Sources
Every layer starts with a source - the raw signal that everything else shapes. @web-kits/audio supports six source types.
Oscillator
The most common source. Pick a waveform, set a frequency, and optionally sweep or FM-modulate it.
{
source: {
type: "sine",
frequency: 440,
detune: 0,
fm: { ratio: 3.5, depth: 200 },
},
}| Property | Type | Description |
|---|---|---|
type | "sine" | "triangle" | "square" | "sawtooth" | Waveform shape |
frequency | number | { start, end } | Hz, or a sweep between values |
detune | number | Cents offset |
fm | { ratio, depth } | FM synthesis modulator |
Noise
Broadband noise. Useful for percussion, textures, and risers.
{ source: { type: "noise", color: "pink" } }Colors: "white" (default), "pink", "brown".
Wavetable
Define your own harmonic content with an array of partial amplitudes.
{
source: {
type: "wavetable",
harmonics: [1, 0.5, 0.25, 0.125],
frequency: 440,
},
}Sample
Play back an audio file. The buffer is fetched and decoded automatically.
{
source: {
type: "sample",
url: "/sounds/kick.wav",
playbackRate: 1,
loop: false,
},
}| Property | Type | Description |
|---|---|---|
url | string | Path to audio file |
buffer | AudioBuffer | Pre-decoded buffer |
playbackRate | number | Speed multiplier |
loop | boolean | Loop playback |
loopStart | number | Loop start point (s) |
loopEnd | number | Loop end point (s) |
Stream
Route a live MediaStream - like a microphone - through the signal path.
{ source: { type: "stream", stream: mediaStream } }Constant
A DC offset. Mainly useful as a modulation source for advanced signal routing.
{ source: { type: "constant", offset: 1 } }