/
Zero.ts
45 lines (38 loc) · 1.13 KB
/
Zero.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Gain } from "../core/context/Gain";
import { connect, disconnect, ToneAudioNodeOptions } from "../core/context/ToneAudioNode";
import { optionsFromArguments } from "../core/util/Defaults";
import { SignalOperator } from "./SignalOperator";
/**
* Tone.Zero outputs 0's at audio-rate. The reason this has to be
* it's own class is that many browsers optimize out Tone.Signal
* with a value of 0 and will not process nodes further down the graph.
* @category Signal
*/
export class Zero extends SignalOperator<ToneAudioNodeOptions> {
readonly name: string = "Zero";
/**
* The gain node which connects the constant source to the output
*/
private _gain = new Gain({ context: this.context });
/**
* Only outputs 0
*/
output = this._gain;
/**
* no input node
*/
input = undefined;
constructor(options?: Partial<ToneAudioNodeOptions>);
constructor() {
super(Object.assign(optionsFromArguments(Zero.getDefaults(), arguments)));
connect(this.context.getConstant(0), this._gain);
}
/**
* clean up
*/
dispose(): this {
super.dispose();
disconnect(this.context.getConstant(0), this._gain);
return this;
}
}