UNPKG

2.07 kBJavaScriptView Raw
1import { Param } from "../context/Param.js";
2import { optionsFromArguments } from "../util/Defaults.js";
3import { readOnly } from "../util/Interface.js";
4import { ToneAudioNode } from "./ToneAudioNode.js";
5/**
6 * Wrapper around Web Audio's native [DelayNode](http://webaudio.github.io/web-audio-api/#the-delaynode-interface).
7 * @category Core
8 * @example
9 * return Tone.Offline(() => {
10 * const delay = new Tone.Delay(0.1).toDestination();
11 * // connect the signal to both the delay and the destination
12 * const pulse = new Tone.PulseOscillator().connect(delay).toDestination();
13 * // start and stop the pulse
14 * pulse.start(0).stop(0.01);
15 * }, 0.5, 1);
16 */
17export class Delay extends ToneAudioNode {
18 constructor() {
19 const options = optionsFromArguments(Delay.getDefaults(), arguments, [
20 "delayTime",
21 "maxDelay",
22 ]);
23 super(options);
24 this.name = "Delay";
25 const maxDelayInSeconds = this.toSeconds(options.maxDelay);
26 this._maxDelay = Math.max(maxDelayInSeconds, this.toSeconds(options.delayTime));
27 this._delayNode =
28 this.input =
29 this.output =
30 this.context.createDelay(maxDelayInSeconds);
31 this.delayTime = new Param({
32 context: this.context,
33 param: this._delayNode.delayTime,
34 units: "time",
35 value: options.delayTime,
36 minValue: 0,
37 maxValue: this.maxDelay,
38 });
39 readOnly(this, "delayTime");
40 }
41 static getDefaults() {
42 return Object.assign(ToneAudioNode.getDefaults(), {
43 delayTime: 0,
44 maxDelay: 1,
45 });
46 }
47 /**
48 * The maximum delay time. This cannot be changed after
49 * the value is passed into the constructor.
50 */
51 get maxDelay() {
52 return this._maxDelay;
53 }
54 /**
55 * Clean up.
56 */
57 dispose() {
58 super.dispose();
59 this._delayNode.disconnect();
60 this.delayTime.dispose();
61 return this;
62 }
63}
64//# sourceMappingURL=Delay.js.map
\No newline at end of file