UNPKG

2.08 kBJavaScriptView Raw
1import { connect, connectSeries, ToneAudioNode, } from "../core/context/ToneAudioNode.js";
2import { CrossFade } from "../component/channel/CrossFade.js";
3import { Split } from "../component/channel/Split.js";
4import { Gain } from "../core/context/Gain.js";
5import { Merge } from "../component/channel/Merge.js";
6import { readOnly } from "../core/util/Interface.js";
7/**
8 * Base class for Stereo effects.
9 */
10export class StereoEffect extends ToneAudioNode {
11 constructor(options) {
12 super(options);
13 this.name = "StereoEffect";
14 this.input = new Gain({ context: this.context });
15 // force mono sources to be stereo
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 // connections
26 this.input.connect(this._split);
27 // dry wet connections
28 this.input.connect(this._dryWet.a);
29 this._merge.connect(this._dryWet.b);
30 readOnly(this, ["wet"]);
31 }
32 /**
33 * Connect the left part of the effect
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 * Connect the right part of the effect
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//# sourceMappingURL=StereoEffect.js.map
\No newline at end of file