EZ Web Audio / createLayeredSound
Function: createLayeredSound()
createLayeredSound(
layers,opts?):Promise<LayeredSound>
Defined in: index.ts:374
Create a LayeredSound that plays multiple Sound/Oscillator instances simultaneously. All layers start at exactly the same audioContext.currentTime for perfect sync.
Parameters
layers
(Sound | Oscillator)[]
Array of Sound or Oscillator instances to layer
opts?
Optional configuration (name, warnLayerCount)
Returns
Promise<LayeredSound>
LayeredSound instance
Example
ts
const bass = await createSound('bass.mp3')
const melody = await createSound('melody.mp3')
const synth = await createOscillator({ frequency: 440 })
const layered = await createLayeredSound([bass, melody, synth])
layered.play() // All layers start at exact same time
layered.setGain(0.5) // Affects all layers
layered.getLayer(2)?.changeGainTo(0.8) // Control individual layer