Tone.js/Tone/signal/Zero.ts

46 lines
1.1 KiB
TypeScript
Raw Normal View History

2019-07-11 21:11:07 +00:00
import { Gain } from "../core/context/Gain";
import { connect, disconnect, ToneAudioNodeOptions } from "../core/context/ToneAudioNode";
import { optionsFromArguments } from "../core/util/Defaults";
import { SignalOperator } from "./SignalOperator";
/**
2019-09-14 20:39:18 +00:00
* 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.
2019-09-16 14:15:23 +00:00
* @category Signal
2019-07-11 21:11:07 +00:00
*/
export class Zero extends SignalOperator<ToneAudioNodeOptions> {
2019-08-03 01:09:35 +00:00
2019-09-04 23:18:44 +00:00
readonly name: string = "Zero";
2019-07-11 21:11:07 +00:00
/**
* The gain node which connects the constant source to the output
*/
2019-09-14 22:12:44 +00:00
private _gain = new Gain({ context: this.context });
2019-07-11 21:11:07 +00:00
/**
* Only outputs 0
*/
output = this._gain;
/**
* no input node
*/
input = undefined;
2019-09-04 23:18:44 +00:00
constructor(options?: Partial<ToneAudioNodeOptions>);
2019-07-11 21:11:07 +00:00
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;
}
}