Tone.js/Tone/effects/AutoPanner.js

77 lines
1.8 KiB
JavaScript
Raw Normal View History

2014-04-06 20:51:30 +00:00
define(["Tone/core/Tone", "Tone/source/Oscillator", "Tone/component/Panner", "Tone/effects/Effect"], function(Tone){
2014-04-05 00:24:19 +00:00
/**
* AutoPanner creates a left-right panner effect (not a 3D panner).
*
* @constructor
* @param { number= } rate (optional) rate in HZ of the left-right pan
* @param { number= } amount (optional) of the pan in dB (0 - 1)
*/
2014-04-06 00:47:59 +00:00
Tone.AutoPanner = function(rate, amount){
Tone.Effect.call(this);
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//defaults
amount = this.defaultArg(amount, 1);
rate = this.defaultArg(rate, 1);
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//components
this.osc = new Tone.Oscillator(rate);
this.amount = this.context.createGain();
this.panner = new Tone.Panner();
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//connections
this.connectEffect(this.panner);
this.chain(this.osc, this.amount, this.panner.control);
};
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//extend Effect
Tone.extend(Tone.AutoPanner, Tone.Effect);
/**
* Start the panner
*
* @param {Tone.Time} Time the panner begins.
*/
2014-04-06 00:47:59 +00:00
Tone.AutoPanner.prototype.start = function(time){
this.osc.start(time);
};
2014-04-05 00:24:19 +00:00
/**
* Stop the panner
*
* @param {Tone.Time} time the panner stops.
*/
2014-04-06 00:47:59 +00:00
Tone.AutoPanner.prototype.stop = function(time){
this.osc.stop(time);
};
2014-04-05 00:24:19 +00:00
/**
* Set the type of oscillator attached to the AutoPanner.
2014-06-16 23:58:23 +00:00
*
* @param {string} type of oscillator the panner is attached to (sine|sawtooth|triangle|square)
*/
2014-04-06 00:47:59 +00:00
Tone.AutoPanner.prototype.setType = function(type){
this.osc.setType(type);
};
2014-04-05 00:24:19 +00:00
/**
* Set frequency of the oscillator attached to the AutoPanner.
2014-06-16 23:58:23 +00:00
*
* @param {number|string} rate in HZ of the oscillator's frequency.
*/
2014-04-07 02:38:06 +00:00
Tone.AutoPanner.prototype.setFrequency = function(rate){
this.osc.setFrequency(rate);
};
2014-04-05 00:24:19 +00:00
/**
* Set the amount of the AutoPanner.
2014-06-16 23:58:23 +00:00
*
* @param {number} amount in dB (0 - 1)
*/
2014-04-06 00:47:59 +00:00
Tone.AutoPanner.prototype.setAmount = function(amount){
this.amount.gain.value = amount;
};
2014-04-06 00:47:59 +00:00
return Tone.AutoPanner;
});