UNPKG

2.48 kBPlain TextView Raw
1import { Effect, EffectOptions } from "./Effect.js";
2import { MidSideSplit } from "../component/channel/MidSideSplit.js";
3import { MidSideMerge } from "../component/channel/MidSideMerge.js";
4import { OutputNode, ToneAudioNode } from "../core/context/ToneAudioNode.js";
5
6export type MidSideEffectOptions = EffectOptions;
7
8/**
9 * Mid/Side processing separates the the 'mid' signal
10 * (which comes out of both the left and the right channel)
11 * and the 'side' (which only comes out of the the side channels)
12 * and effects them separately before being recombined.
13 * Applies a Mid/Side seperation and recombination.
14 * Algorithm found in [kvraudio forums](http://www.kvraudio.com/forum/viewtopic.php?t=212587).
15 * This is a base-class for Mid/Side Effects.
16 * @category Effect
17 */
18export abstract class MidSideEffect<
19 Options extends MidSideEffectOptions,
20> extends Effect<Options> {
21 readonly name: string = "MidSideEffect";
22
23 /**
24 * The mid/side split
25 */
26 private _midSideSplit: MidSideSplit;
27
28 /**
29 * The mid/side merge
30 */
31 private _midSideMerge: MidSideMerge;
32
33 /**
34 * The mid send. Connect to mid processing
35 */
36 protected _midSend: ToneAudioNode;
37
38 /**
39 * The side send. Connect to side processing
40 */
41 protected _sideSend: ToneAudioNode;
42
43 /**
44 * The mid return connection
45 */
46 protected _midReturn: ToneAudioNode;
47
48 /**
49 * The side return connection
50 */
51 protected _sideReturn: ToneAudioNode;
52
53 constructor(options: MidSideEffectOptions) {
54 super(options);
55
56 this._midSideMerge = new MidSideMerge({ context: this.context });
57 this._midSideSplit = new MidSideSplit({ context: this.context });
58 this._midSend = this._midSideSplit.mid;
59 this._sideSend = this._midSideSplit.side;
60 this._midReturn = this._midSideMerge.mid;
61 this._sideReturn = this._midSideMerge.side;
62
63 // the connections
64 this.effectSend.connect(this._midSideSplit);
65 this._midSideMerge.connect(this.effectReturn);
66 }
67
68 /**
69 * Connect the mid chain of the effect
70 */
71 protected connectEffectMid(...nodes: OutputNode[]): void {
72 this._midSend.chain(...nodes, this._midReturn);
73 }
74
75 /**
76 * Connect the side chain of the effect
77 */
78 protected connectEffectSide(...nodes: OutputNode[]): void {
79 this._sideSend.chain(...nodes, this._sideReturn);
80 }
81
82 dispose(): this {
83 super.dispose();
84 this._midSideSplit.dispose();
85 this._midSideMerge.dispose();
86 this._midSend.dispose();
87 this._sideSend.dispose();
88 this._midReturn.dispose();
89 this._sideReturn.dispose();
90 return this;
91 }
92}