Skip to content
Tone.js

WaveShaper

class Signal ↳ extends SignalOperator<WaveShaperOptions>

Wraps the native Web Audio API WaveShaperNode.

const osc = new Tone.Oscillator().toDestination().start();
// multiply the output of the signal by 2 using the waveshaper's function
const timesTwo = new Tone.WaveShaper((val) => val * 2, 2048).connect(osc.frequency);
const signal = new Tone.Signal(440).connect(timesTwo);
new WaveShaper(mapping?: WaveShaperMapping, length?: number)

Parameters

  • mapping WaveShaperMapping optional

    The function used to define the values. The mapping function should take two arguments: the first is the value at the current position and the second is the array position. If the argument is an array, that array will be set as the wave shaping function. The input signal is an AudioRange [-1, 1] value and the output signal can take on any numerical values.

  • length number optional

    The length of the WaveShaperNode buffer.

new WaveShaper(options?: Partial<WaveShaperOptions>)

Parameters

input: WaveShaperNode

The input to the waveshaper node.

read-only

name: string

The name of the class

Default: "WaveShaper"

output: WaveShaperNode

The output from the waveshaper node

curve: Float32Array<ArrayBuffer> | null

The array to set as the waveshaper curve. For linear curves array length does not make much difference, but for complex curves longer arrays will provide smoother interpolation.

oversample: OverSampleType

Specifies what type of oversampling (if any) should be used when applying the shaping curve. Can either be “none”, “2x” or “4x”.

↳ inherited from SignalOperator

connect(destination: InputNode, outputNum?: number, inputNum?: number): this

connect the output of a ToneAudioNode to an AudioParam, AudioNode, or ToneAudioNode

Parameters

  • destination InputNode

    The output to connect to

  • outputNum number optional default 0

    The output to connect from

  • inputNum number optional default 0

    The input to connect to

Returns this

dispose(): this

Clean up.

Returns this

setMap(mapping: WaveShaperMappingFn, length?: number): this

Uses a mapping function to set the value of the curve.

const shaper = new Tone.WaveShaper();
// map the input signal from [-1, 1] to [0, 10]
shaper.setMap((val, index) => (val + 1) * 5);

Parameters

  • mapping WaveShaperMappingFn

    The function used to define the values. The mapping function take two arguments: the first is the value at the current position which goes from -1 to 1 over the number of elements in the curve array. The second argument is the array position.

  • length number optional default 1024

Returns this

static

getDefaults(): WaveShaperOptions

Returns all of the default options belonging to the class.

Returns WaveShaperOptions