1 | import { Param } from "../context/Param.js";
|
2 | import { optionsFromArguments } from "../util/Defaults.js";
|
3 | import { readOnly } from "../util/Interface.js";
|
4 | import { ToneAudioNode } from "./ToneAudioNode.js";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | export 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 |
|
49 |
|
50 |
|
51 | get maxDelay() {
|
52 | return this._maxDelay;
|
53 | }
|
54 | |
55 |
|
56 |
|
57 | dispose() {
|
58 | super.dispose();
|
59 | this._delayNode.disconnect();
|
60 | this.delayTime.dispose();
|
61 | return this;
|
62 | }
|
63 | }
|
64 |
|
\ | No newline at end of file |