Tone.js/Tone/signal/Abs.js

76 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-07-03 03:36:59 +00:00
define(["Tone/core/Tone", "Tone/signal/Threshold", "Tone/signal/Negate", "Tone/signal/EqualZero"], function(Tone){
/**
2014-07-04 17:36:13 +00:00
* @class return the absolute value of an incoming signal
*
* @constructor
* @extends {Tone}
*/
2014-07-04 17:36:13 +00:00
Tone.Abs = function(){
2014-07-03 03:36:59 +00:00
Tone.call(this);
/**
2014-07-03 03:36:59 +00:00
* @type {Tone.Threshold}
* @private
*/
2014-07-03 03:36:59 +00:00
this._thresh = new Tone.Threshold(0);
/**
2014-07-03 03:36:59 +00:00
* @type {Tone.Negate}
* @private
*/
2014-07-03 03:36:59 +00:00
this._negate = new Tone.Negate();
2014-07-03 03:36:59 +00:00
/**
* @type {Tone.EqualZero}
* @private
*/
this._not = new Tone.EqualZero();
2014-07-03 03:36:59 +00:00
/**
* @type {GainNode}
* @private
*/
this._positive = this.context.createGain();
2014-07-03 03:36:59 +00:00
/**
* @type {GainNode}
* @private
*/
this._negative = this.context.createGain();
this.input.connect(this._thresh);
//two routes, one positive, one negative
this.chain(this.input, this._positive, this.output);
this.chain(this.input, this._negate, this._negative, this.output);
//the switching logic
this._thresh.connect(this._positive.gain);
this._positive.gain.value = 0;
this.chain(this._thresh, this._not, this._negative.gain);
this._negative.gain.value = 0;
};
2014-07-03 03:36:59 +00:00
Tone.extend(Tone.Abs);
/**
* dispose method
*/
Tone.Abs.prototype.dispose = function(){
2014-07-03 03:36:59 +00:00
this._thresh.dispose();
this._negate.dispose();
this._not.dispose();
this._positive.disconnect();
this._negative.disconnect();
2014-07-04 02:57:04 +00:00
this.input.disconnect();
this.output.disconnect();
2014-07-03 03:36:59 +00:00
this._thresh = null;
this._negate = null;
this._not = null;
this._positive = null;
this._negative = null;
2014-07-04 02:57:04 +00:00
this.input = null;
this.output = null;
};
return Tone.Abs;
});