UNPKG

2.6 kBJavaScriptView Raw
1import { StereoXFeedbackEffect, } from "./StereoXFeedbackEffect.js";
2import { optionsFromArguments } from "../core/util/Defaults.js";
3import { Delay } from "../core/context/Delay.js";
4import { Signal } from "../signal/Signal.js";
5import { readOnly } from "../core/util/Interface.js";
6/**
7 * PingPongDelay is a feedback delay effect where the echo is heard
8 * first in one channel and next in the opposite channel. In a stereo
9 * system these are the right and left channels.
10 * PingPongDelay in more simplified terms is two Tone.FeedbackDelays
11 * with independent delay values. Each delay is routed to one channel
12 * (left or right), and the channel triggered second will always
13 * trigger at the same interval after the first.
14 * @example
15 * const pingPong = new Tone.PingPongDelay("4n", 0.2).toDestination();
16 * const drum = new Tone.MembraneSynth().connect(pingPong);
17 * drum.triggerAttackRelease("C4", "32n");
18 * @category Effect
19 */
20export class PingPongDelay extends StereoXFeedbackEffect {
21 constructor() {
22 const options = optionsFromArguments(PingPongDelay.getDefaults(), arguments, ["delayTime", "feedback"]);
23 super(options);
24 this.name = "PingPongDelay";
25 this._leftDelay = new Delay({
26 context: this.context,
27 maxDelay: options.maxDelay,
28 });
29 this._rightDelay = new Delay({
30 context: this.context,
31 maxDelay: options.maxDelay,
32 });
33 this._rightPreDelay = new Delay({
34 context: this.context,
35 maxDelay: options.maxDelay,
36 });
37 this.delayTime = new Signal({
38 context: this.context,
39 units: "time",
40 value: options.delayTime,
41 });
42 // connect it up
43 this.connectEffectLeft(this._leftDelay);
44 this.connectEffectRight(this._rightPreDelay, this._rightDelay);
45 this.delayTime.fan(this._leftDelay.delayTime, this._rightDelay.delayTime, this._rightPreDelay.delayTime);
46 // rearranged the feedback to be after the rightPreDelay
47 this._feedbackL.disconnect();
48 this._feedbackL.connect(this._rightDelay);
49 readOnly(this, ["delayTime"]);
50 }
51 static getDefaults() {
52 return Object.assign(StereoXFeedbackEffect.getDefaults(), {
53 delayTime: 0.25,
54 maxDelay: 1,
55 });
56 }
57 dispose() {
58 super.dispose();
59 this._leftDelay.dispose();
60 this._rightDelay.dispose();
61 this._rightPreDelay.dispose();
62 this.delayTime.dispose();
63 return this;
64 }
65}
66//# sourceMappingURL=PingPongDelay.js.map
\No newline at end of file