Tone.js/Tone/signal/Multiply.js

65 lines
1.6 KiB
JavaScript
Raw Normal View History

define(["Tone/core/Tone", "Tone/core/Param", "Tone/core/Gain", "Tone/signal/SignalBase"], function(Tone){
"use strict";
2014-06-17 00:05:54 +00:00
/**
* @class Multiply two incoming signals. Or, if a number is given in the constructor,
* multiplies the incoming signal by that value.
2014-06-17 00:05:54 +00:00
*
* @constructor
* @extends {Tone.Signal}
2015-06-19 04:52:04 +00:00
* @param {number=} value Constant value to multiple. If no value is provided,
* it will return the product of the first and second inputs
2015-02-27 18:40:35 +00:00
* @example
2015-06-19 04:52:04 +00:00
* var mult = new Tone.Multiply();
* var sigA = new Tone.Signal(3);
* var sigB = new Tone.Signal(4);
* sigA.connect(mult, 0, 0);
* sigB.connect(mult, 0, 1);
* //output of mult is 12.
2015-06-20 19:50:57 +00:00
* @example
* var mult = new Tone.Multiply(10);
* var sig = new Tone.Signal(2).connect(mult);
* //the output of mult is 20.
2014-06-17 00:05:54 +00:00
*/
Tone.Multiply = function(value){
2014-10-23 01:20:43 +00:00
Tone.Signal.call(this);
2016-09-20 03:02:42 +00:00
this.createInsOuts(2, 0);
2014-10-23 01:20:43 +00:00
2014-06-17 15:42:38 +00:00
/**
* the input node is the same as the output node
* it is also the GainNode which handles the scaling of incoming signal
*
2014-06-17 15:42:38 +00:00
* @type {GainNode}
2014-10-23 01:20:43 +00:00
* @private
*/
2016-09-20 01:44:41 +00:00
this._mult = this.input[0] = this.output = new Tone.Gain();
2014-10-23 01:20:43 +00:00
/**
* the scaling parameter
* @type {AudioParam}
* @private
2014-06-17 15:42:38 +00:00
*/
2015-10-21 14:34:37 +00:00
this._param = this.input[1] = this.output.gain;
this.value = Tone.defaultArg(value, 0);
this.proxy = false;
2014-06-15 21:38:59 +00:00
};
Tone.extend(Tone.Multiply, Tone.Signal);
2014-06-20 04:38:14 +00:00
/**
* clean up
* @returns {Tone.Multiply} this
2014-06-20 04:38:14 +00:00
*/
Tone.Multiply.prototype.dispose = function(){
Tone.Signal.prototype.dispose.call(this);
2016-09-20 03:02:42 +00:00
this._mult.dispose();
2014-10-23 01:20:43 +00:00
this._mult = null;
2015-10-21 14:34:37 +00:00
this._param = null;
2015-02-02 03:56:33 +00:00
return this;
};
2014-06-20 04:38:14 +00:00
return Tone.Multiply;
2014-06-15 21:38:59 +00:00
});