Tone.js/Tone/effect/Vibrato.js

104 lines
2.2 KiB
JavaScript
Raw Normal View History

import Tone from "../core/Tone";
import "../effect/Effect";
import "../core/Delay";
import "../component/LFO";
2015-08-26 14:28:53 +00:00
/**
* @class A Vibrato effect composed of a Tone.Delay and a Tone.LFO. The LFO
* modulates the delayTime of the delay, causing the pitch to rise
* and fall.
* @extends {Tone.Effect}
* @param {Frequency} frequency The frequency of the vibrato.
* @param {NormalRange} depth The amount the pitch is modulated.
*/
Tone.Vibrato = function(){
var options = Tone.defaults(arguments, ["frequency", "depth"], Tone.Vibrato);
Tone.Effect.call(this, options);
2015-10-21 16:11:19 +00:00
2015-08-26 14:28:53 +00:00
/**
* The delay node used for the vibrato effect
* @type {Tone.Delay}
* @private
2015-08-26 14:28:53 +00:00
*/
this._delayNode = new Tone.Delay(0, options.maxDelay);
2015-08-26 14:28:53 +00:00
/**
* The LFO used to control the vibrato
* @type {Tone.LFO}
* @private
2015-08-26 14:28:53 +00:00
*/
this._lfo = new Tone.LFO({
"type" : options.type,
"min" : 0,
"max" : options.maxDelay,
"frequency" : options.frequency,
"phase" : -90 //offse the phase so the resting position is in the center
}).start().connect(this._delayNode.delayTime);
2015-08-26 14:28:53 +00:00
/**
* The frequency of the vibrato
* @type {Frequency}
* @signal
2015-08-26 14:28:53 +00:00
*/
this.frequency = this._lfo.frequency;
2015-08-26 14:28:53 +00:00
/**
* The depth of the vibrato.
* @type {NormalRange}
* @signal
2015-08-26 14:28:53 +00:00
*/
this.depth = this._lfo.amplitude;
this.depth.value = options.depth;
this._readOnly(["frequency", "depth"]);
this.effectSend.chain(this._delayNode, this.effectReturn);
};
Tone.extend(Tone.Vibrato, Tone.Effect);
/**
* The defaults
* @type {Object}
* @const
*/
Tone.Vibrato.defaults = {
"maxDelay" : 0.005,
"frequency" : 5,
"depth" : 0.1,
"type" : "sine"
};
2015-08-26 14:28:53 +00:00
/**
* Type of oscillator attached to the Vibrato.
* @memberOf Tone.Vibrato#
* @type {string}
* @name type
*/
Object.defineProperty(Tone.Vibrato.prototype, "type", {
get : function(){
return this._lfo.type;
},
set : function(type){
this._lfo.type = type;
}
2017-10-26 20:02:01 +00:00
});
/**
* Clean up.
* @returns {Tone.Vibrato} this
*/
Tone.Vibrato.prototype.dispose = function(){
Tone.Effect.prototype.dispose.call(this);
this._delayNode.dispose();
this._delayNode = null;
this._lfo.dispose();
this._lfo = null;
this._writable(["frequency", "depth"]);
this.frequency = null;
this.depth = null;
};
export default Tone.Vibrato;