2
0
Fork 0
mirror of https://github.com/Tonejs/Tone.js synced 2025-02-15 20:18:24 +00:00
Tone.js/Tone/signal/Multiply.js

64 lines
1.6 KiB
JavaScript
Raw Normal View History

2014-08-24 15:47:59 -04:00
define(["Tone/core/Tone", "Tone/signal/Signal"], function(Tone){
"use strict";
2014-06-16 20:05:54 -04:00
/**
2015-06-19 00:52:04 -04:00
* @class Multiply two incoming signals. Or, if a number is given in the constructor,
* multiplies the incoming signal by that value.
2014-06-16 20:05:54 -04:00
*
* @constructor
2015-02-23 00:30:53 -05:00
* @extends {Tone.Signal}
2015-06-19 00:52:04 -04: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 13:40:35 -05:00
* @example
2015-06-19 00:52:04 -04: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 15:50:57 -04:00
* @example
* var mult = new Tone.Multiply(10);
* var sig = new Tone.Signal(2).connect(mult);
* //the output of mult is 20.
2014-06-16 20:05:54 -04:00
*/
Tone.Multiply = function(value){
2014-10-22 21:20:43 -04:00
Tone.call(this, 2, 0);
2014-10-22 21:20:43 -04:00
2014-06-17 11:42:38 -04:00
/**
* the input node is the same as the output node
* it is also the GainNode which handles the scaling of incoming signal
*
* @type {GainNode}
2014-10-22 21:20:43 -04:00
* @private
*/
this._mult = this.input[0] = this.output = this.context.createGain();
/**
* the scaling parameter
* @type {AudioParam}
* @private
2014-06-17 11:42:38 -04:00
*/
2015-10-21 10:34:37 -04:00
this._param = this.input[1] = this.output.gain;
2014-06-30 17:11:46 -04:00
2015-10-21 10:34:37 -04:00
this._param.value = this.defaultArg(value, 0);
2014-06-15 17:38:59 -04:00
};
2015-02-23 00:30:53 -05:00
Tone.extend(Tone.Multiply, Tone.Signal);
2014-06-20 00:38:14 -04:00
/**
* clean up
* @returns {Tone.Multiply} this
2014-06-20 00:38:14 -04:00
*/
Tone.Multiply.prototype.dispose = function(){
Tone.prototype.dispose.call(this);
2015-04-05 14:42:14 -04:00
this._mult.disconnect();
2014-10-22 21:20:43 -04:00
this._mult = null;
2015-10-21 10:34:37 -04:00
this._param = null;
2015-02-01 22:56:33 -05:00
return this;
2014-06-20 00:38:14 -04:00
};
return Tone.Multiply;
2014-06-15 17:38:59 -04:00
});