Skip to content
Tone.js

Gain

class Core ↳ extends ToneAudioNode<GainOptions<TypeName>>

A thin wrapper around the Native Web Audio GainNode. The GainNode is a basic building block of the Web Audio API and is useful for routing audio and adjusting gains.

return Tone.Offline(() => {
	const gainNode = new Tone.Gain(0).toDestination();
	const osc = new Tone.Oscillator(30).connect(gainNode).start();
	gainNode.gain.rampTo(1, 0.1);
	gainNode.gain.rampTo(0, 0.4, 0.2);
}, 0.7, 1);
new Gain(gain?: UnitMap[TypeName], units?: TypeName)

Parameters

  • gain UnitMap[TypeName] optional

    The initial gain of the GainNode

  • units TypeName optional

    The units of the gain parameter.

new Gain(options?: Partial<GainOptions<TypeName>>)

Parameters

read-only

gain: Param<TypeName>

The gain parameter of the gain node.

const gainNode = new Tone.Gain(0).toDestination();
const osc = new Tone.Oscillator().connect(gainNode).start();
gainNode.gain.rampTo(1, 0.1);
gainNode.gain.rampTo(0, 2, "+0.5");

read-only

input: GainNode

The input node or nodes. If the object is a source, it does not have any input and this.input is undefined.

read-only

name: string

The name of the class

Default: "Gain"

read-only

output: GainNode

The output nodes. If the object is a sink, it does not have any output and this.output is undefined.

dispose(): this

Clean up.

Returns this

static

getDefaults(): GainOptions<any>

Returns all of the default options belonging to the class.

Returns GainOptions<any>