Tone.js/Tone/component/LFO.js

75 lines
1.7 KiB
JavaScript
Raw Normal View History

2014-04-05 00:24:19 +00:00
///////////////////////////////////////////////////////////////////////////////
//
// LFO
//
///////////////////////////////////////////////////////////////////////////////
2014-04-06 20:51:30 +00:00
define(["Tone/core/Tone", "Tone/source/Oscillator", "Tone/signal/Scale"], function(Tone){
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
Tone.LFO = function(rate, outputMin, outputMax){
//extends Unit
Tone.call(this);
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//defaults
rate = this.defaultArg(rate, 1);
min = this.defaultArg(outputMin, -1);
max = this.defaultArg(outputMax, 1);
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//the components
this.oscillator = new Tone.Oscillator(rate, "sine");
this.scaler = new Tone.Scale(min, max);
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//connect it up
this.chain(this.oscillator, this.scaler, this.output);
}
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
Tone.extend(Tone.LFO, Tone);
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//start the lfo
Tone.LFO.prototype.start = function(time){
this.oscillator.start(time);
}
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//stop
Tone.LFO.prototype.stop = function(time){
this.oscillator.stop(time);
}
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//set the params
2014-04-07 00:12:40 +00:00
Tone.LFO.prototype.setFrequency = function(rate){
2014-04-06 00:47:59 +00:00
this.oscillator.setFrequency(rate);
}
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//set the params
Tone.LFO.prototype.setMin = function(min){
this.scaler.setMin(min);
}
2014-04-05 00:24:19 +00:00
2014-04-06 00:47:59 +00:00
//set the params
Tone.LFO.prototype.setMax = function(max){
this.scaler.setMax(max);
}
//set the waveform of the LFO
//@param {string | number} type ('sine', 'square', 'sawtooth', 'triangle', 'custom');
Tone.LFO.prototype.setType = function(type){
this.oscillator.setType(type);
}
//@private
//pointer to the parent's connect method
Tone.LFO.prototype._connect = Tone.prototype.connect;
//triggers the release of the envelope
Tone.LFO.prototype.connect = function(param){
if (param instanceof AudioParam){
//set the initial value
2014-04-16 04:23:58 +00:00
param.value = 0;
}
this._connect(param);
}
2014-04-06 00:47:59 +00:00
return Tone.LFO;
});