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);
Constructor
Section titled “Constructor”new WaveShaper(mapping?: WaveShaperMapping, length?: number)Parameters
-
mapping
WaveShaperMappingoptionalThe 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
numberoptionalThe length of the WaveShaperNode buffer.
new WaveShaper(options?: Partial<WaveShaperOptions>)Parameters
- options
Partial<WaveShaperOptions>optional
Properties
Section titled “Properties”curve: Float32Array<ArrayBuffer> | nullThe 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
Section titled “oversample”oversample: OverSampleTypeSpecifies what type of oversampling (if any) should be used when applying the shaping curve. Can either be “none”, “2x” or “4x”.
Methods
Section titled “Methods”connect()
Section titled “connect()”↳ inherited from SignalOperator
connect(destination: InputNode, outputNum?: number, inputNum?: number): thisconnect the output of a ToneAudioNode to an AudioParam, AudioNode, or ToneAudioNode
Parameters
-
destination
InputNodeThe output to connect to
-
outputNum
numberoptional default0The output to connect from
-
inputNum
numberoptional default0The input to connect to
Returns this
disconnect()
Section titled “disconnect()”↳ inherited from SignalOperator
disconnect(destination: InputNode, outputNum?: number, inputNum?: number): thisdisconnect the output
Parameters
- destination
InputNode - outputNum
numberoptional default0 - inputNum
numberoptional default0
Returns this
setMap()
Section titled “setMap()”setMap(mapping: WaveShaperMappingFn, length?: number): thisUses 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
WaveShaperMappingFnThe 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
numberoptional default1024
Returns this
getDefaults()
Section titled “getDefaults()”static
getDefaults(): WaveShaperOptionsReturns all of the default options belonging to the class.
Returns WaveShaperOptions
Inherited members
Section titled “Inherited members”- From
ToneWithContext: context, blockTime, sampleTime, get(), immediate(), now(), set(), toFrequency(), toSeconds(), toTicks() - From
Tone: debug, version, disposed, toString() - From
ToneAudioNode: channelCount, channelCountMode, channelInterpretation, numberOfInputs, numberOfOutputs, chain(), fan(), toDestination(), toMaster()