2014-09-01 17:09:33 +00:00
|
|
|
define(["Tone/core/Tone", "Tone/effect/StereoXFeedbackEffect", "Tone/signal/Signal", "Tone/signal/Multiply"],
|
|
|
|
function(Tone){
|
|
|
|
|
2014-09-04 04:41:40 +00:00
|
|
|
"use strict";
|
|
|
|
|
2014-06-19 03:45:23 +00:00
|
|
|
/**
|
2014-09-01 17:09:33 +00:00
|
|
|
* @class PingPongDelay is a dual delay effect where the echo is heard
|
|
|
|
* first in one channel and next in the opposite channel
|
2014-06-21 21:34:31 +00:00
|
|
|
*
|
|
|
|
* @constructor
|
2014-09-01 17:09:33 +00:00
|
|
|
* @extends {Tone.StereoXFeedbackEffect}
|
2014-12-02 06:42:08 +00:00
|
|
|
* @param {Tone.Time|Object} [delayTime=0.25] is the interval between consecutive echos
|
2015-02-27 21:53:10 +00:00
|
|
|
* @param {number=} feedback The amount of the effected signal which
|
|
|
|
* is fed back through the delay.
|
|
|
|
* @example
|
|
|
|
* var pingPong = new Tone.PingPongDelay("4n", 0.2);
|
2014-06-19 03:45:23 +00:00
|
|
|
*/
|
2014-08-25 14:23:37 +00:00
|
|
|
Tone.PingPongDelay = function(){
|
2014-08-23 17:51:02 +00:00
|
|
|
|
2015-02-27 21:53:10 +00:00
|
|
|
var options = this.optionsObject(arguments, ["delayTime", "feedback"], Tone.PingPongDelay.defaults);
|
2014-09-01 17:09:33 +00:00
|
|
|
Tone.StereoXFeedbackEffect.call(this, options);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* the delay node on the left side
|
|
|
|
* @type {DelayNode}
|
|
|
|
* @private
|
|
|
|
*/
|
2014-10-01 23:45:30 +00:00
|
|
|
this._leftDelay = this.context.createDelay(options.maxDelayTime);
|
2014-04-06 04:12:18 +00:00
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
2014-09-01 17:09:33 +00:00
|
|
|
* the delay node on the right side
|
|
|
|
* @type {DelayNode}
|
2014-08-23 18:25:20 +00:00
|
|
|
* @private
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2014-10-01 23:45:30 +00:00
|
|
|
this._rightDelay = this.context.createDelay(options.maxDelayTime);
|
|
|
|
|
2014-06-21 21:34:31 +00:00
|
|
|
/**
|
2014-09-01 17:09:33 +00:00
|
|
|
* the delay time signal
|
|
|
|
* @type {Tone.Signal}
|
2014-06-21 21:34:31 +00:00
|
|
|
*/
|
2015-02-10 16:40:27 +00:00
|
|
|
this.delayTime = new Tone.Signal(options.delayTime, Tone.Signal.Units.Time);
|
2014-08-23 17:51:02 +00:00
|
|
|
|
2014-04-06 04:12:18 +00:00
|
|
|
//connect it up
|
2015-02-13 21:10:45 +00:00
|
|
|
this.effectSendL.chain(this._leftDelay, this.effectReturnL);
|
2014-12-01 02:32:09 +00:00
|
|
|
this.effectSendR.chain(this._rightDelay, this.effectReturnR);
|
2015-02-13 21:10:45 +00:00
|
|
|
this.delayTime.fan(this._leftDelay.delayTime, this._rightDelay.delayTime);
|
2014-10-01 23:45:30 +00:00
|
|
|
//rearranged the feedback to be after the leftPreDelay
|
|
|
|
this._feedbackRL.disconnect();
|
|
|
|
this._feedbackRL.connect(this._leftDelay);
|
2014-06-19 03:45:23 +00:00
|
|
|
};
|
2014-04-06 04:12:18 +00:00
|
|
|
|
2014-09-01 17:09:33 +00:00
|
|
|
Tone.extend(Tone.PingPongDelay, Tone.StereoXFeedbackEffect);
|
2014-04-06 04:12:18 +00:00
|
|
|
|
2014-08-25 14:23:37 +00:00
|
|
|
/**
|
|
|
|
* @static
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
Tone.PingPongDelay.defaults = {
|
|
|
|
"delayTime" : 0.25,
|
2014-10-01 23:45:30 +00:00
|
|
|
"maxDelayTime" : 1
|
2014-08-25 14:23:37 +00:00
|
|
|
};
|
|
|
|
|
2014-08-20 21:10:12 +00:00
|
|
|
/**
|
|
|
|
* clean up
|
2015-02-02 18:22:16 +00:00
|
|
|
* @returns {Tone.PingPongDelay} `this`
|
2014-08-20 21:10:12 +00:00
|
|
|
*/
|
|
|
|
Tone.PingPongDelay.prototype.dispose = function(){
|
2014-09-01 17:09:33 +00:00
|
|
|
Tone.StereoXFeedbackEffect.prototype.dispose.call(this);
|
|
|
|
this._leftDelay.disconnect();
|
|
|
|
this._leftDelay = null;
|
2015-02-13 21:10:45 +00:00
|
|
|
this._rightDelay.disconnect();
|
2014-09-01 17:09:33 +00:00
|
|
|
this._rightDelay = null;
|
2015-02-13 21:10:45 +00:00
|
|
|
this.delayTime.dispose();
|
2014-09-01 17:09:33 +00:00
|
|
|
this.delayTime = null;
|
2015-02-02 18:22:16 +00:00
|
|
|
return this;
|
2014-08-20 21:10:12 +00:00
|
|
|
};
|
|
|
|
|
2014-04-06 04:12:18 +00:00
|
|
|
return Tone.PingPongDelay;
|
|
|
|
});
|