UNPKG

2.82 kBJavaScriptView Raw
1import { ToneAudioNode, } from "../../core/context/ToneAudioNode.js";
2import { Compressor } from "./Compressor.js";
3import { optionsFromArguments } from "../../core/util/Defaults.js";
4import { readOnly } from "../../core/util/Interface.js";
5import { MultibandSplit } from "../channel/MultibandSplit.js";
6import { Gain } from "../../core/context/Gain.js";
7/**
8 * A compressor with separate controls over low/mid/high dynamics.
9 * @see {@link Compressor} and {@link MultibandSplit}
10 *
11 * @example
12 * const multiband = new Tone.MultibandCompressor({
13 * lowFrequency: 200,
14 * highFrequency: 1300,
15 * low: {
16 * threshold: -12
17 * }
18 * });
19 * @category Component
20 */
21export 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 // connect the compressor
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//# sourceMappingURL=MultibandCompressor.js.map
\No newline at end of file