UNPKG

1.84 kBJavaScriptView Raw
1import { connectSeries } from "../core/context/ToneAudioNode.js";
2import { Gain } from "../core/context/Gain.js";
3import { optionsFromArguments } from "../core/util/Defaults.js";
4import { Negate } from "../signal/Negate.js";
5import { Signal } from "../signal/Signal.js";
6/**
7 * Subtract the signal connected to the input is subtracted from the signal connected
8 * The subtrahend.
9 *
10 * @example
11 * // subtract a scalar from a signal
12 * const sub = new Tone.Subtract(1);
13 * const sig = new Tone.Signal(4).connect(sub);
14 * // the output of sub is 3.
15 * @example
16 * // subtract two signals
17 * const sub = new Tone.Subtract();
18 * const sigA = new Tone.Signal(10);
19 * const sigB = new Tone.Signal(2.5);
20 * sigA.connect(sub);
21 * sigB.connect(sub.subtrahend);
22 * // output of sub is 7.5
23 * @category Signal
24 */
25export class Subtract extends Signal {
26 constructor() {
27 super(optionsFromArguments(Subtract.getDefaults(), arguments, ["value"]));
28 this.override = false;
29 this.name = "Subtract";
30 /**
31 * the summing node
32 */
33 this._sum = new Gain({ context: this.context });
34 this.input = this._sum;
35 this.output = this._sum;
36 /**
37 * Negate the input of the second input before connecting it to the summing node.
38 */
39 this._neg = new Negate({ context: this.context });
40 /**
41 * The value which is subtracted from the main signal
42 */
43 this.subtrahend = this._param;
44 connectSeries(this._constantSource, this._neg, this._sum);
45 }
46 static getDefaults() {
47 return Object.assign(Signal.getDefaults(), {
48 value: 0,
49 });
50 }
51 dispose() {
52 super.dispose();
53 this._neg.dispose();
54 this._sum.dispose();
55 return this;
56 }
57}
58//# sourceMappingURL=Subtract.js.map
\No newline at end of file