AudioEffects. AudioEffect

Base class for audio effects, an input and output with a wet/dry mix between them

  • Sounds connect to input, output goes to the master gain until connect() moves it
  • Subclasses put their nodes between input and the wet gain with connectEffect

Constructor

new AudioEffect(mixopt)

Create an audio effect

Parameters:
NameTypeAttributesDefaultDescription
mixnumber<optional>
1

Wet/dry balance, 0 is fully dry and 1 is fully wet

Example
const cave = new AudioReverb(3, 2);
footstep.output = cave; // every play of this sound is in the cave

Members

dryGain

Properties
TypeDescription
GainNode

Level of the unprocessed signal

input

Properties
TypeDescription
GainNode

Connect sounds to this node

mix

Properties
TypeDescription
number

Wet/dry balance, 0 is fully dry and 1 is fully wet

output

Properties
TypeDescription
GainNode

This node carries the mixed result, send it somewhere with connect(), never by assigning here

  • Unlike sound.output, which is where a sound's audio goes and can be set to an effect

wetGain

Properties
TypeDescription
GainNode

Level of the processed signal

Methods

connect(target) → {AudioEffect|AudioNode}

Send this effect's output into another effect or audio node instead of the speakers

Parameters:
NameTypeDescription
targetAudioEffect | AudioNode

The next effect in the chain, or any audio node

Returns:
  • The target, so chains read left to right
Type: 
AudioEffect | AudioNode

(protected) connectEffect(first, lastopt)

Wire nodes between the input and the wet gain, for subclasses

Parameters:
NameTypeAttributesDefaultDescription
firstAudioNode

Node the input connects to

lastAudioNode<optional>
first

Node that connects to the wet gain

disconnect()

Stop sending this effect's output anywhere

(protected) rampParam(param, value, fadeTimeopt)

Ramp one of this effect's params, keeping the effect running until the ramp is done

  • The browser drops an effect from rendering while nothing plays through it, which would freeze a ramp partway, so a silent source feeds the input for the ramp's length
Parameters:
NameTypeAttributesDefaultDescription
paramAudioParam

The param to ramp

valuenumber

Where to ramp to

fadeTimenumber<optional>
0

Seconds to ramp over, 0 sets the value at once

setMix(mix, fadeTimeopt)

Set the wet/dry balance

Parameters:
NameTypeAttributesDefaultDescription
mixnumber

0 is fully dry and 1 is fully wet

fadeTimenumber<optional>
0

Seconds to ramp over so the change doesn't click