EZ Web Audio / createLayeredSound
Function: createLayeredSound()
Call Signature
createLayeredSound(
layers,opts?):Promise<LayeredSound>
Defined in: packages/core/src/index.ts:1040
Create a LayeredSound that plays multiple Sound/Oscillator instances simultaneously. All layers start at exactly the same audioContext.currentTime for perfect sync.
Parameters
layers
(Oscillator | Sound<BaseSoundEventMap>)[]
Array of Sound or Oscillator instances to layer
opts?
Optional configuration (name, warnLayerCount)
Returns
Promise<LayeredSound>
LayeredSound instance
Example
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.changeGainTo(0.5) // Affects all layers
layered.getLayer(2)?.changeGainTo(0.8) // Control individual layerCall Signature
createLayeredSound(
audioContext,layers,opts?):Promise<LayeredSound>
Defined in: packages/core/src/index.ts:1041
Create a LayeredSound that plays multiple Sound/Oscillator instances simultaneously. All layers start at exactly the same audioContext.currentTime for perfect sync.
Parameters
audioContext
BaseAudioContext
layers
(Oscillator | Sound<BaseSoundEventMap>)[]
Array of Sound or Oscillator instances to layer
opts?
Optional configuration (name, warnLayerCount)
Returns
Promise<LayeredSound>
LayeredSound instance
Example
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.changeGainTo(0.5) // Affects all layers
layered.getLayer(2)?.changeGainTo(0.8) // Control individual layer