UNPKG

3.28 kBTypeScriptView Raw
1import { ToneAudioNodeOptions } from "../core/context/ToneAudioNode.js";
2import { SignalOperator } from "./SignalOperator.js";
3export type WaveShaperMappingFn = (value: number, index?: number) => number;
4type WaveShaperMapping = WaveShaperMappingFn | number[] | Float32Array;
5interface WaveShaperOptions extends ToneAudioNodeOptions {
6 mapping?: WaveShaperMapping;
7 length: number;
8 curve?: number[] | Float32Array;
9}
10/**
11 * Wraps the native Web Audio API
12 * [WaveShaperNode](http://webaudio.github.io/web-audio-api/#the-waveshapernode-interface).
13 *
14 * @example
15 * const osc = new Tone.Oscillator().toDestination().start();
16 * // multiply the output of the signal by 2 using the waveshaper's function
17 * const timesTwo = new Tone.WaveShaper((val) => val * 2, 2048).connect(osc.frequency);
18 * const signal = new Tone.Signal(440).connect(timesTwo);
19 * @category Signal
20 */
21export declare class WaveShaper extends SignalOperator<WaveShaperOptions> {
22 readonly name: string;
23 /**
24 * the waveshaper node
25 */
26 private _shaper;
27 /**
28 * The input to the waveshaper node.
29 */
30 input: WaveShaperNode;
31 /**
32 * The output from the waveshaper node
33 */
34 output: WaveShaperNode;
35 /**
36 * @param mapping The function used to define the values.
37 * The mapping function should take two arguments:
38 * the first is the value at the current position
39 * and the second is the array position.
40 * If the argument is an array, that array will be
41 * set as the wave shaping function. The input
42 * signal is an AudioRange [-1, 1] value and the output
43 * signal can take on any numerical values.
44 *
45 * @param length The length of the WaveShaperNode buffer.
46 */
47 constructor(mapping?: WaveShaperMapping, length?: number);
48 constructor(options?: Partial<WaveShaperOptions>);
49 static getDefaults(): WaveShaperOptions;
50 /**
51 * Uses a mapping function to set the value of the curve.
52 * @param mapping The function used to define the values.
53 * The mapping function take two arguments:
54 * the first is the value at the current position
55 * which goes from -1 to 1 over the number of elements
56 * in the curve array. The second argument is the array position.
57 * @example
58 * const shaper = new Tone.WaveShaper();
59 * // map the input signal from [-1, 1] to [0, 10]
60 * shaper.setMap((val, index) => (val + 1) * 5);
61 */
62 setMap(mapping: WaveShaperMappingFn, length?: number): this;
63 /**
64 * The array to set as the waveshaper curve. For linear curves
65 * array length does not make much difference, but for complex curves
66 * longer arrays will provide smoother interpolation.
67 */
68 get curve(): Float32Array | null;
69 set curve(mapping: Float32Array | null);
70 /**
71 * Specifies what type of oversampling (if any) should be used when
72 * applying the shaping curve. Can either be "none", "2x" or "4x".
73 */
74 get oversample(): OverSampleType;
75 set oversample(oversampling: OverSampleType);
76 /**
77 * Clean up.
78 */
79 dispose(): this;
80}
81export {};