1 | import { connect, connectSeries, ToneAudioNode, } from "../core/context/ToneAudioNode.js";
|
2 | import { CrossFade } from "../component/channel/CrossFade.js";
|
3 | import { Split } from "../component/channel/Split.js";
|
4 | import { Gain } from "../core/context/Gain.js";
|
5 | import { Merge } from "../component/channel/Merge.js";
|
6 | import { readOnly } from "../core/util/Interface.js";
|
7 |
|
8 |
|
9 |
|
10 | export class StereoEffect extends ToneAudioNode {
|
11 | constructor(options) {
|
12 | super(options);
|
13 | this.name = "StereoEffect";
|
14 | this.input = new Gain({ context: this.context });
|
15 |
|
16 | this.input.channelCount = 2;
|
17 | this.input.channelCountMode = "explicit";
|
18 | this._dryWet = this.output = new CrossFade({
|
19 | context: this.context,
|
20 | fade: options.wet,
|
21 | });
|
22 | this.wet = this._dryWet.fade;
|
23 | this._split = new Split({ context: this.context, channels: 2 });
|
24 | this._merge = new Merge({ context: this.context, channels: 2 });
|
25 |
|
26 | this.input.connect(this._split);
|
27 |
|
28 | this.input.connect(this._dryWet.a);
|
29 | this._merge.connect(this._dryWet.b);
|
30 | readOnly(this, ["wet"]);
|
31 | }
|
32 | |
33 |
|
34 |
|
35 | connectEffectLeft(...nodes) {
|
36 | this._split.connect(nodes[0], 0, 0);
|
37 | connectSeries(...nodes);
|
38 | connect(nodes[nodes.length - 1], this._merge, 0, 0);
|
39 | }
|
40 | |
41 |
|
42 |
|
43 | connectEffectRight(...nodes) {
|
44 | this._split.connect(nodes[0], 1, 0);
|
45 | connectSeries(...nodes);
|
46 | connect(nodes[nodes.length - 1], this._merge, 0, 1);
|
47 | }
|
48 | static getDefaults() {
|
49 | return Object.assign(ToneAudioNode.getDefaults(), {
|
50 | wet: 1,
|
51 | });
|
52 | }
|
53 | dispose() {
|
54 | super.dispose();
|
55 | this._dryWet.dispose();
|
56 | this._split.dispose();
|
57 | this._merge.dispose();
|
58 | return this;
|
59 | }
|
60 | }
|
61 |
|
\ | No newline at end of file |