UNPKG

1.24 kBJavaScriptView Raw
1import { SignalOperator } from "./SignalOperator.js";
2import { WaveShaper } from "./WaveShaper.js";
3/**
4 * Return the absolute value of an incoming signal.
5 *
6 * @example
7 * return Tone.Offline(() => {
8 * const abs = new Tone.Abs().toDestination();
9 * const signal = new Tone.Signal(1);
10 * signal.rampTo(-1, 0.5);
11 * signal.connect(abs);
12 * }, 0.5, 1);
13 * @category Signal
14 */
15export class Abs extends SignalOperator {
16 constructor() {
17 super(...arguments);
18 this.name = "Abs";
19 /**
20 * The node which converts the audio ranges
21 */
22 this._abs = new WaveShaper({
23 context: this.context,
24 mapping: (val) => {
25 if (Math.abs(val) < 0.001) {
26 return 0;
27 }
28 else {
29 return Math.abs(val);
30 }
31 },
32 });
33 /**
34 * The AudioRange input [-1, 1]
35 */
36 this.input = this._abs;
37 /**
38 * The output range [0, 1]
39 */
40 this.output = this._abs;
41 }
42 /**
43 * clean up
44 */
45 dispose() {
46 super.dispose();
47 this._abs.dispose();
48 return this;
49 }
50}
51//# sourceMappingURL=Abs.js.map
\No newline at end of file