/
MidSideCompressor.ts
87 lines (74 loc) · 2.56 KB
/
MidSideCompressor.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import { InputNode, OutputNode, ToneAudioNode, ToneAudioNodeOptions } from "../../core/context/ToneAudioNode";
import { Compressor, CompressorOptions } from "./Compressor";
import { optionsFromArguments } from "../../core/util/Defaults";
import { MidSideSplit } from "../channel/MidSideSplit";
import { MidSideMerge } from "../channel/MidSideMerge";
import { readOnly, RecursivePartial } from "../../core/util/Interface";
export interface MidSideCompressorOptions extends ToneAudioNodeOptions {
mid: Omit<CompressorOptions, keyof ToneAudioNodeOptions>;
side: Omit<CompressorOptions, keyof ToneAudioNodeOptions>;
}
/**
* MidSideCompressor applies two different compressors to the [[mid]]
* and [[side]] signal components of the input. See [[MidSideSplit]] and [[MidSideMerge]].
* @category Component
*/
export class MidSideCompressor extends ToneAudioNode<MidSideCompressorOptions> {
readonly name: string = "MidSideCompressor";
readonly input: InputNode;
readonly output: OutputNode;
/**
* Split the incoming signal into Mid/Side
*/
private _midSideSplit: MidSideSplit;
/**
* Merge the compressed signal back into a single stream
*/
private _midSideMerge: MidSideMerge;
/**
* The compression applied to the mid signal
*/
readonly mid: Compressor;
/**
* The compression applied to the side signal
*/
readonly side: Compressor;
constructor(options?: RecursivePartial<MidSideCompressorOptions>);
constructor() {
super(Object.assign(optionsFromArguments(MidSideCompressor.getDefaults(), arguments)));
const options = optionsFromArguments(MidSideCompressor.getDefaults(), arguments);
this._midSideSplit = this.input = new MidSideSplit({ context: this.context });
this._midSideMerge = this.output = new MidSideMerge({ context: this.context });
this.mid = new Compressor(Object.assign(options.mid, { context: this.context }));
this.side = new Compressor(Object.assign(options.side, { context: this.context }));
this._midSideSplit.mid.chain(this.mid, this._midSideMerge.mid);
this._midSideSplit.side.chain(this.side, this._midSideMerge.side);
readOnly(this, ["mid", "side"]);
}
static getDefaults(): MidSideCompressorOptions {
return Object.assign(ToneAudioNode.getDefaults(), {
mid: {
ratio: 3,
threshold: -24,
release: 0.03,
attack: 0.02,
knee: 16
},
side: {
ratio: 6,
threshold: -30,
release: 0.25,
attack: 0.03,
knee: 10
}
});
}
dispose(): this {
super.dispose();
this.mid.dispose();
this.side.dispose();
this._midSideSplit.dispose();
this._midSideMerge.dispose();
return this;
}
}