2019-07-25 03:16:58 +00:00
|
|
|
import { ToneAudioNodeOptions } from "../core/context/ToneAudioNode";
|
|
|
|
import { Multiply } from "./Multiply";
|
|
|
|
import { SignalOperator } from "./SignalOperator";
|
|
|
|
|
|
|
|
/**
|
2019-08-27 15:53:14 +00:00
|
|
|
* Negate the incoming signal. i.e. an input signal of 10 will output -10
|
2019-07-25 03:16:58 +00:00
|
|
|
*
|
2019-08-27 15:53:14 +00:00
|
|
|
* @example
|
2020-04-17 02:24:18 +00:00
|
|
|
* const neg = new Tone.Negate();
|
|
|
|
* const sig = new Tone.Signal(-2).connect(neg);
|
2019-10-25 20:54:33 +00:00
|
|
|
* // output of neg is positive 2.
|
2019-09-16 14:15:23 +00:00
|
|
|
* @category Signal
|
2019-07-25 03:16:58 +00:00
|
|
|
*/
|
|
|
|
export class Negate extends SignalOperator<ToneAudioNodeOptions> {
|
|
|
|
|
2019-09-04 23:18:44 +00:00
|
|
|
readonly name: string = "Negate";
|
2019-07-25 03:16:58 +00:00
|
|
|
|
|
|
|
/**
|
2019-09-14 20:39:18 +00:00
|
|
|
* negation is done by multiplying by -1
|
2019-07-25 03:16:58 +00:00
|
|
|
*/
|
|
|
|
private _multiply: Multiply = new Multiply({
|
|
|
|
context: this.context,
|
|
|
|
value: -1,
|
|
|
|
});
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The input and output are equal to the multiply node
|
|
|
|
*/
|
|
|
|
input = this._multiply;
|
|
|
|
output = this._multiply;
|
|
|
|
|
|
|
|
/**
|
2019-09-14 20:39:18 +00:00
|
|
|
* clean up
|
2019-08-30 16:06:38 +00:00
|
|
|
* @returns {Negate} this
|
2019-07-25 03:16:58 +00:00
|
|
|
*/
|
|
|
|
dispose(): this {
|
|
|
|
super.dispose();
|
|
|
|
this._multiply.dispose();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|