1 | import { ToneAudioNode, } from "../../core/context/ToneAudioNode.js";
|
2 | import { Compressor } from "./Compressor.js";
|
3 | import { optionsFromArguments } from "../../core/util/Defaults.js";
|
4 | import { readOnly } from "../../core/util/Interface.js";
|
5 | import { MultibandSplit } from "../channel/MultibandSplit.js";
|
6 | import { Gain } from "../../core/context/Gain.js";
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export class MultibandCompressor extends ToneAudioNode {
|
22 | constructor() {
|
23 | const options = optionsFromArguments(MultibandCompressor.getDefaults(), arguments);
|
24 | super(options);
|
25 | this.name = "MultibandCompressor";
|
26 | this._splitter = this.input = new MultibandSplit({
|
27 | context: this.context,
|
28 | lowFrequency: options.lowFrequency,
|
29 | highFrequency: options.highFrequency,
|
30 | });
|
31 | this.lowFrequency = this._splitter.lowFrequency;
|
32 | this.highFrequency = this._splitter.highFrequency;
|
33 | this.output = new Gain({ context: this.context });
|
34 | this.low = new Compressor(Object.assign(options.low, { context: this.context }));
|
35 | this.mid = new Compressor(Object.assign(options.mid, { context: this.context }));
|
36 | this.high = new Compressor(Object.assign(options.high, { context: this.context }));
|
37 |
|
38 | this._splitter.low.chain(this.low, this.output);
|
39 | this._splitter.mid.chain(this.mid, this.output);
|
40 | this._splitter.high.chain(this.high, this.output);
|
41 | readOnly(this, ["high", "mid", "low", "highFrequency", "lowFrequency"]);
|
42 | }
|
43 | static getDefaults() {
|
44 | return Object.assign(ToneAudioNode.getDefaults(), {
|
45 | lowFrequency: 250,
|
46 | highFrequency: 2000,
|
47 | low: {
|
48 | ratio: 6,
|
49 | threshold: -30,
|
50 | release: 0.25,
|
51 | attack: 0.03,
|
52 | knee: 10,
|
53 | },
|
54 | mid: {
|
55 | ratio: 3,
|
56 | threshold: -24,
|
57 | release: 0.03,
|
58 | attack: 0.02,
|
59 | knee: 16,
|
60 | },
|
61 | high: {
|
62 | ratio: 3,
|
63 | threshold: -24,
|
64 | release: 0.03,
|
65 | attack: 0.02,
|
66 | knee: 16,
|
67 | },
|
68 | });
|
69 | }
|
70 | dispose() {
|
71 | super.dispose();
|
72 | this._splitter.dispose();
|
73 | this.low.dispose();
|
74 | this.mid.dispose();
|
75 | this.high.dispose();
|
76 | this.output.dispose();
|
77 | return this;
|
78 | }
|
79 | }
|
80 |
|
\ | No newline at end of file |