Tone.js/Tone/effect/PingPongDelay.js

99 lines
2.9 KiB
JavaScript
Raw Normal View History

import Tone from "../core/Tone";
import "../effect/StereoXFeedbackEffect";
import "../signal/Signal";
import "../core/Delay";
/**
* @class Tone.PingPongDelay is a feedback delay effect where the echo is heard
* first in one channel and next in the opposite channel. In a stereo
* system these are the right and left channels.
* PingPongDelay in more simplified terms is two Tone.FeedbackDelays
* with independent delay values. Each delay is routed to one channel
* (left or right), and the channel triggered second will always
* trigger at the same interval after the first.
*
* @constructor
* @extends {Tone.StereoXFeedbackEffect}
* @param {Time|Object} [delayTime] The delayTime between consecutive echos.
* @param {NormalRange=} feedback The amount of the effected signal which
* is fed back through the delay.
* @example
* var pingPong = new Tone.PingPongDelay("4n", 0.2).toMaster();
* var drum = new Tone.MembraneSynth().connect(pingPong);
* drum.triggerAttackRelease("C4", "32n");
*/
Tone.PingPongDelay = function(){
var options = Tone.defaults(arguments, ["delayTime", "feedback"], Tone.PingPongDelay);
Tone.StereoXFeedbackEffect.call(this, options);
/**
* the delay node on the left side
* @type {Tone.Delay}
* @private
*/
this._leftDelay = new Tone.Delay(0, options.maxDelayTime);
/**
* the delay node on the right side
* @type {Tone.Delay}
* @private
*/
this._rightDelay = new Tone.Delay(0, options.maxDelayTime);
/**
* the predelay on the right side
* @type {Tone.Delay}
* @private
*/
this._rightPreDelay = new Tone.Delay(0, options.maxDelayTime);
/**
* the delay time signal
* @type {Time}
* @signal
*/
this.delayTime = new Tone.Signal(options.delayTime, Tone.Type.Time);
2015-03-02 00:49:01 +00:00
//connect it up
this.effectSendL.chain(this._leftDelay, this.effectReturnL);
this.effectSendR.chain(this._rightPreDelay, this._rightDelay, this.effectReturnR);
this.delayTime.fan(this._leftDelay.delayTime, this._rightDelay.delayTime, this._rightPreDelay.delayTime);
//rearranged the feedback to be after the rightPreDelay
this._feedbackLR.disconnect();
this._feedbackLR.connect(this._rightDelay);
this._readOnly(["delayTime"]);
};
2014-08-23 17:51:02 +00:00
Tone.extend(Tone.PingPongDelay, Tone.StereoXFeedbackEffect);
/**
* @static
* @type {Object}
*/
Tone.PingPongDelay.defaults = {
"delayTime" : 0.25,
"maxDelayTime" : 1
};
/**
* Clean up.
* @returns {Tone.PingPongDelay} this
*/
Tone.PingPongDelay.prototype.dispose = function(){
Tone.StereoXFeedbackEffect.prototype.dispose.call(this);
this._leftDelay.dispose();
this._leftDelay = null;
this._rightDelay.dispose();
this._rightDelay = null;
this._rightPreDelay.dispose();
this._rightPreDelay = null;
this._writable(["delayTime"]);
this.delayTime.dispose();
this.delayTime = null;
return this;
};
export default Tone.PingPongDelay;
2014-08-20 21:10:12 +00:00