1 | import { Param } from "../../core/context/Param.js";
|
2 | import { ToneAudioNode, } from "../../core/context/ToneAudioNode.js";
|
3 | import { optionsFromArguments } from "../../core/util/Defaults.js";
|
4 | import { readOnly } from "../../core/util/Interface.js";
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | export class Compressor extends ToneAudioNode {
|
16 | constructor() {
|
17 | const options = optionsFromArguments(Compressor.getDefaults(), arguments, ["threshold", "ratio"]);
|
18 | super(options);
|
19 | this.name = "Compressor";
|
20 | |
21 |
|
22 |
|
23 | this._compressor = this.context.createDynamicsCompressor();
|
24 | this.input = this._compressor;
|
25 | this.output = this._compressor;
|
26 | this.threshold = new Param({
|
27 | minValue: this._compressor.threshold.minValue,
|
28 | maxValue: this._compressor.threshold.maxValue,
|
29 | context: this.context,
|
30 | convert: false,
|
31 | param: this._compressor.threshold,
|
32 | units: "decibels",
|
33 | value: options.threshold,
|
34 | });
|
35 | this.attack = new Param({
|
36 | minValue: this._compressor.attack.minValue,
|
37 | maxValue: this._compressor.attack.maxValue,
|
38 | context: this.context,
|
39 | param: this._compressor.attack,
|
40 | units: "time",
|
41 | value: options.attack,
|
42 | });
|
43 | this.release = new Param({
|
44 | minValue: this._compressor.release.minValue,
|
45 | maxValue: this._compressor.release.maxValue,
|
46 | context: this.context,
|
47 | param: this._compressor.release,
|
48 | units: "time",
|
49 | value: options.release,
|
50 | });
|
51 | this.knee = new Param({
|
52 | minValue: this._compressor.knee.minValue,
|
53 | maxValue: this._compressor.knee.maxValue,
|
54 | context: this.context,
|
55 | convert: false,
|
56 | param: this._compressor.knee,
|
57 | units: "decibels",
|
58 | value: options.knee,
|
59 | });
|
60 | this.ratio = new Param({
|
61 | minValue: this._compressor.ratio.minValue,
|
62 | maxValue: this._compressor.ratio.maxValue,
|
63 | context: this.context,
|
64 | convert: false,
|
65 | param: this._compressor.ratio,
|
66 | units: "positive",
|
67 | value: options.ratio,
|
68 | });
|
69 |
|
70 | readOnly(this, ["knee", "release", "attack", "ratio", "threshold"]);
|
71 | }
|
72 | static getDefaults() {
|
73 | return Object.assign(ToneAudioNode.getDefaults(), {
|
74 | attack: 0.003,
|
75 | knee: 30,
|
76 | ratio: 12,
|
77 | release: 0.25,
|
78 | threshold: -24,
|
79 | });
|
80 | }
|
81 | |
82 |
|
83 |
|
84 |
|
85 | get reduction() {
|
86 | return this._compressor.reduction;
|
87 | }
|
88 | dispose() {
|
89 | super.dispose();
|
90 | this._compressor.disconnect();
|
91 | this.attack.dispose();
|
92 | this.release.dispose();
|
93 | this.threshold.dispose();
|
94 | this.ratio.dispose();
|
95 | this.knee.dispose();
|
96 | return this;
|
97 | }
|
98 | }
|
99 |
|
\ | No newline at end of file |