mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
Subtract class
subtract a signal and a number or a signal and a signal
This commit is contained in:
parent
d2d57a3f37
commit
7f7e093a4b
1 changed files with 65 additions and 0 deletions
65
Tone/signal/Subtract.js
Normal file
65
Tone/signal/Subtract.js
Normal file
|
@ -0,0 +1,65 @@
|
|||
define(["Tone/core/Tone", "Tone/signal/Add", "Tone/signal/Negate", "Tone/signal/Signal"], function(Tone){
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @class Subtract a signal and a number or two signals.
|
||||
*
|
||||
*
|
||||
* @extends {Tone}
|
||||
* @constructor
|
||||
* @param {number=} value value to subtract from the incoming signal. If the value
|
||||
* is omitted, it will subtract the second signal from the first
|
||||
*/
|
||||
Tone.Subtract = function(value){
|
||||
|
||||
/**
|
||||
* the inputs
|
||||
* input 0 : minuend
|
||||
* input 1 : subtrahend
|
||||
* @type {Array}
|
||||
*/
|
||||
this.input = new Array(2);
|
||||
|
||||
/**
|
||||
* the adder node
|
||||
* @type {Tone.Add}
|
||||
* @private
|
||||
*/
|
||||
this._adder = this.input[0] = this.output = new Tone.Add(-value);
|
||||
|
||||
/**
|
||||
* the negate node
|
||||
* @type {Tone.Negate}
|
||||
* @private
|
||||
*/
|
||||
this._neg = this.input[1] = new Tone.Negate();
|
||||
|
||||
//connect it up
|
||||
this._neg.connect(this._adder, 0, 1);
|
||||
};
|
||||
|
||||
Tone.extend(Tone.Subtract);
|
||||
|
||||
/**
|
||||
* set the constant
|
||||
*
|
||||
* @param {number} value
|
||||
*/
|
||||
Tone.Subtract.prototype.setValue = function(value){
|
||||
this._adder.setValue(-value);
|
||||
};
|
||||
|
||||
/**
|
||||
* clean up
|
||||
*/
|
||||
Tone.Subtract.prototype.dispose = function(){
|
||||
Tone.prototype.dispose.call(this);
|
||||
this._neg.dispose();
|
||||
this._neg = null;
|
||||
this._adder.dispose();
|
||||
this._adder = null;
|
||||
};
|
||||
|
||||
return Tone.Subtract;
|
||||
});
|
Loading…
Reference in a new issue