Tone.js/Tone/core/Delay.js

85 lines
1.9 KiB
JavaScript
Raw Normal View History

2018-01-02 15:37:27 +00:00
define(["Tone/core/Tone", "Tone/core/Param", "Tone/core/AudioNode"], function(Tone) {
2015-08-15 23:30:33 +00:00
2015-10-21 16:11:19 +00:00
"use strict";
2015-08-15 23:30:33 +00:00
/**
* @class Wrapper around Web Audio's native [DelayNode](http://webaudio.github.io/web-audio-api/#the-delaynode-interface).
2015-08-15 23:30:33 +00:00
* @extends {Tone}
2015-11-02 14:31:12 +00:00
* @param {Time=} delayTime The delay applied to the incoming signal.
* @param {Time=} maxDelay The maximum delay time.
2015-08-15 23:30:33 +00:00
*/
Tone.Delay = function(){
2017-04-26 02:23:22 +00:00
var options = Tone.defaults(arguments, ["delayTime", "maxDelay"], Tone.Delay);
Tone.AudioNode.call(this);
2015-08-15 23:30:33 +00:00
2018-02-15 16:41:01 +00:00
/**
* The maximum delay time initialized with the node
* @type {Number}
* @private
*/
this._maxDelay = Math.max(this.toSeconds(options.maxDelay), this.toSeconds(options.delayTime));
2015-08-15 23:30:33 +00:00
/**
* The native delay node
* @type {DelayNode}
* @private
*/
2018-02-15 16:41:01 +00:00
this._delayNode = this.input = this.output = this.context.createDelay(this._maxDelay);
2015-08-15 23:30:33 +00:00
/**
* The amount of time the incoming signal is
* delayed.
* @type {Time}
2015-08-15 23:30:33 +00:00
* @signal
*/
2015-11-02 14:31:12 +00:00
this.delayTime = new Tone.Param({
"param" : this._delayNode.delayTime,
"units" : Tone.Type.Time,
"value" : options.delayTime
});
2015-08-15 23:30:33 +00:00
this._readOnly("delayTime");
};
Tone.extend(Tone.Delay, Tone.AudioNode);
2015-08-15 23:30:33 +00:00
/**
* The defaults
* @const
* @type {Object}
*/
Tone.Delay.defaults = {
"maxDelay" : 1,
2015-11-02 14:31:12 +00:00
"delayTime" : 0
2015-08-15 23:30:33 +00:00
};
2018-02-15 16:41:01 +00:00
/**
* The maximum delay time. This cannot be changed. The value is passed into the constructor.
* @memberof Tone.Delay#
* @type {Time}
* @name maxDelay
* @readOnly
*/
Object.defineProperty(Tone.Delay.prototype, "maxDelay", {
get : function(){
return this._maxDelay;
}
});
2015-08-15 23:30:33 +00:00
/**
* Clean up.
* @return {Tone.Delay} this
*/
Tone.Delay.prototype.dispose = function(){
Tone.AudioNode.prototype.dispose.call(this);
2015-08-15 23:30:33 +00:00
this._delayNode.disconnect();
this._delayNode = null;
this._writable("delayTime");
this.delayTime = null;
return this;
};
2015-08-15 23:30:33 +00:00
return Tone.Delay;
});