adding LFOs
This commit is contained in:
72
src/API.ts
72
src/API.ts
@ -807,6 +807,78 @@ export class UserAPI {
|
|||||||
return cycle;
|
return cycle;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// =============================================================
|
||||||
|
// Low Frequency Oscillators
|
||||||
|
// =============================================================
|
||||||
|
|
||||||
|
sine(freq: number = 1, offset: number=0): number {
|
||||||
|
/**
|
||||||
|
* Returns a sine wave between -1 and 1.
|
||||||
|
*
|
||||||
|
* @param freq - The frequency of the sine wave
|
||||||
|
* @param offset - The offset of the sine wave
|
||||||
|
* @returns A sine wave between -1 and 1
|
||||||
|
*/
|
||||||
|
return Math.sin(this.app.clock.ctx.currentTime * Math.PI * 2 * freq) + offset
|
||||||
|
}
|
||||||
|
|
||||||
|
saw(freq: number = 1, offset: number=0): number {
|
||||||
|
/**
|
||||||
|
* Returns a saw wave between -1 and 1.
|
||||||
|
*
|
||||||
|
* @param freq - The frequency of the saw wave
|
||||||
|
* @param offset - The offset of the saw wave
|
||||||
|
* @returns A saw wave between -1 and 1
|
||||||
|
* @see triangle
|
||||||
|
* @see square
|
||||||
|
* @see sine
|
||||||
|
* @see noise
|
||||||
|
*/
|
||||||
|
return (this.app.clock.ctx.currentTime * freq) % 1 * 2 - 1 + offset
|
||||||
|
}
|
||||||
|
|
||||||
|
triangle(freq: number = 1, offset: number=0): number {
|
||||||
|
/**
|
||||||
|
* Returns a triangle wave between -1 and 1.
|
||||||
|
*
|
||||||
|
* @returns A triangle wave between -1 and 1
|
||||||
|
* @see saw
|
||||||
|
* @see square
|
||||||
|
* @see sine
|
||||||
|
* @see noise
|
||||||
|
*/
|
||||||
|
return Math.abs(this.saw(freq, offset)) * 2 - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
square(freq: number = 1, offset: number=0): number {
|
||||||
|
/**
|
||||||
|
* Returns a square wave between -1 and 1.
|
||||||
|
*
|
||||||
|
* @returns A square wave between -1 and 1
|
||||||
|
* @see saw
|
||||||
|
* @see triangle
|
||||||
|
* @see sine
|
||||||
|
* @see noise
|
||||||
|
*/
|
||||||
|
return this.saw(freq, offset) > 0 ? 1 : -1
|
||||||
|
}
|
||||||
|
|
||||||
|
noise(): number {
|
||||||
|
/**
|
||||||
|
* Returns a random value between -1 and 1.
|
||||||
|
*
|
||||||
|
* @returns A random value between -1 and 1
|
||||||
|
* @see saw
|
||||||
|
* @see triangle
|
||||||
|
* @see square
|
||||||
|
* @see sine
|
||||||
|
* @see noise
|
||||||
|
*/
|
||||||
|
return Math.random() * 2 - 1
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// =============================================================
|
// =============================================================
|
||||||
// Trivial functions
|
// Trivial functions
|
||||||
// =============================================================
|
// =============================================================
|
||||||
|
|||||||
@ -12,6 +12,7 @@ export interface TimePosition {
|
|||||||
export class Clock {
|
export class Clock {
|
||||||
|
|
||||||
evaluations: number
|
evaluations: number
|
||||||
|
ctx: AudioContext
|
||||||
transportNode: TransportNode
|
transportNode: TransportNode
|
||||||
bpm: number
|
bpm: number
|
||||||
time_signature: number[]
|
time_signature: number[]
|
||||||
@ -20,6 +21,7 @@ export class Clock {
|
|||||||
tick: number
|
tick: number
|
||||||
|
|
||||||
constructor(public app: Editor, ctx: AudioContext) {
|
constructor(public app: Editor, ctx: AudioContext) {
|
||||||
|
this.ctx = ctx;
|
||||||
this.tick = 0;
|
this.tick = 0;
|
||||||
this.time_position = { bar: 0, beat: 0, pulse: 0 }
|
this.time_position = { bar: 0, beat: 0, pulse: 0 }
|
||||||
this.bpm = 120;
|
this.bpm = 120;
|
||||||
|
|||||||
Reference in New Issue
Block a user