In synth-kit most of the functions accepts an optional AudioContext as last parameter. If no one is provided, synth-kit creates a singleton AudioContext using 'audio-context' module.
- Source:
Methods
(static) after(delay, context) → {Float}
Get time after n seconds (from now)
Parameters:
Name | Type | Description |
---|---|---|
delay |
Float | the delay |
context |
AudioContext | (Optional) an optional audio context |
- Source:
Returns:
time in seconds
- Type
- Float
Example
now() // => 0.785
after(1) // => 1.785
(static) context(context) → {AudioContext}
Get the audio context.
Parameters:
Name | Type | Description |
---|---|---|
context |
AudioContext | (Optional) if given, it return itself. If nothing passed, it returns the AudioContext singleton instance |
- Source:
Returns:
the audio context
- Type
- AudioContext
Example
// normally you won't do this:
var gain = context().createGain()
(static) dest(context) → {AudioContext}
Get the audio context's destination
Parameters:
Name | Type | Description |
---|---|---|
context |
AudioContext | (Optional) an alternate audio context |
- Source:
Returns:
the audio context destination
- Type
- AudioContext
Example
conn(sine(300), dest()).start()
(static) now(context) → {Number}
Get audio context's current time
Parameters:
Name | Type | Description |
---|---|---|
context |
AudioContext | (Optional) an optional audio context |
- Source:
Returns:
the time in seconds relative to the AudioContext creation
- Type
- Number
Example
now() // => 3.3213
(static) samplingRate(context) → {Integer}
Get audio context sampling rate
Parameters:
Name | Type | Description |
---|---|---|
context |
AudioContext | (Optional) the audio context |
- Source:
Returns:
the context's sampling rate
- Type
- Integer
Example
samplingRate() // => 44100
(static) timeToSamples(seconds, context) → {Integer}
Convert from seconds to samples (using AudioContext sampling rate)
Parameters:
Name | Type | Description |
---|---|---|
seconds |
Float | the number of seconds |
context |
AudioContext | (Optional) the audio context |
- Source:
Returns:
the number of samples
- Type
- Integer
Example
white(seconds(1.2)) // => generate 1.2 seconds of white noise
(static) when(time, delay, context)
Get a valid time
Parameters:
Name | Type | Description |
---|---|---|
time |
Float | the time (equal or greater than now(), otherwise, ignored) |
delay |
Float | the delay |
context |
AudioContext | (Optional) an optional audio context |
- Source:
Example
now() // => 0.7
time(0.2) // => 0.7
time(1) // => 1
time(0.2, 1) // => 1.7 (time is ignored because is < than now())