2024-05-03 18:31:14 +00:00
|
|
|
import {
|
|
|
|
ToneAudioNode,
|
|
|
|
ToneAudioNodeOptions,
|
|
|
|
} from "../../core/context/ToneAudioNode.js";
|
|
|
|
import { Split } from "./Split.js";
|
|
|
|
import { Add } from "../../signal/Add.js";
|
|
|
|
import { Multiply } from "../../signal/Multiply.js";
|
|
|
|
import { Subtract } from "../../signal/Subtract.js";
|
|
|
|
import { optionsFromArguments } from "../../core/util/Defaults.js";
|
2019-10-29 00:42:43 +00:00
|
|
|
|
|
|
|
export type MidSideSplitOptions = ToneAudioNodeOptions;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mid/Side processing separates the the 'mid' signal (which comes out of both the left and the right channel)
|
|
|
|
* and the 'side' (which only comes out of the the side channels).
|
|
|
|
* ```
|
|
|
|
* Mid = (Left+Right)/sqrt(2); // obtain mid-signal from left and right
|
2019-10-29 00:59:01 +00:00
|
|
|
* Side = (Left-Right)/sqrt(2); // obtain side-signal from left and right
|
2019-10-29 00:42:43 +00:00
|
|
|
* ```
|
2020-09-02 20:53:38 +00:00
|
|
|
* @category Component
|
2019-10-29 00:42:43 +00:00
|
|
|
*/
|
|
|
|
export class MidSideSplit extends ToneAudioNode<MidSideSplitOptions> {
|
|
|
|
readonly name: string = "MidSideSplit";
|
|
|
|
|
|
|
|
readonly input: Split;
|
|
|
|
|
|
|
|
/**
|
2024-04-29 14:48:37 +00:00
|
|
|
* There is no output node, use either {@link mid} or {@link side} outputs.
|
2019-10-29 00:42:43 +00:00
|
|
|
*/
|
|
|
|
readonly output: undefined;
|
|
|
|
/**
|
|
|
|
* Split the incoming signal into left and right channels
|
|
|
|
*/
|
|
|
|
private _split: Split;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sums the left and right channels
|
|
|
|
*/
|
|
|
|
private _midAdd: Add;
|
|
|
|
|
|
|
|
/**
|
2024-05-03 18:31:14 +00:00
|
|
|
* Subtract left and right channels.
|
2019-10-29 00:42:43 +00:00
|
|
|
*/
|
|
|
|
private _sideSubtract: Subtract;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The "mid" output. `(Left+Right)/sqrt(2)`
|
|
|
|
*/
|
2019-11-04 02:35:26 +00:00
|
|
|
readonly mid: ToneAudioNode;
|
2019-10-29 00:42:43 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The "side" output. `(Left-Right)/sqrt(2)`
|
|
|
|
*/
|
2019-11-04 02:35:26 +00:00
|
|
|
readonly side: ToneAudioNode;
|
2024-05-03 18:31:14 +00:00
|
|
|
|
2019-10-29 00:42:43 +00:00
|
|
|
constructor(options?: Partial<MidSideSplitOptions>);
|
|
|
|
constructor() {
|
|
|
|
super(optionsFromArguments(MidSideSplit.getDefaults(), arguments));
|
|
|
|
|
|
|
|
this._split = this.input = new Split({
|
|
|
|
channels: 2,
|
2024-05-03 18:31:14 +00:00
|
|
|
context: this.context,
|
2019-10-29 00:42:43 +00:00
|
|
|
});
|
|
|
|
this._midAdd = new Add({ context: this.context });
|
|
|
|
this.mid = new Multiply({
|
|
|
|
context: this.context,
|
|
|
|
value: Math.SQRT1_2,
|
|
|
|
});
|
|
|
|
this._sideSubtract = new Subtract({ context: this.context });
|
|
|
|
this.side = new Multiply({
|
|
|
|
context: this.context,
|
|
|
|
value: Math.SQRT1_2,
|
|
|
|
});
|
|
|
|
|
|
|
|
this._split.connect(this._midAdd, 0);
|
|
|
|
this._split.connect(this._midAdd.addend, 1);
|
|
|
|
this._split.connect(this._sideSubtract, 0);
|
|
|
|
this._split.connect(this._sideSubtract.subtrahend, 1);
|
|
|
|
this._midAdd.connect(this.mid);
|
|
|
|
this._sideSubtract.connect(this.side);
|
|
|
|
}
|
|
|
|
|
|
|
|
dispose(): this {
|
|
|
|
super.dispose();
|
|
|
|
this.mid.dispose();
|
|
|
|
this.side.dispose();
|
|
|
|
this._midAdd.dispose();
|
|
|
|
this._sideSubtract.dispose();
|
|
|
|
this._split.dispose();
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
}
|