UNPKG

1.85 kBJavaScriptView Raw
1import { ToneAudioNode, } from "../../core/context/ToneAudioNode.js";
2import { optionsFromArguments } from "../../core/util/Defaults.js";
3import { Compressor } from "./Compressor.js";
4import { readOnly } from "../../core/util/Interface.js";
5/**
6 * Limiter will limit the loudness of an incoming signal.
7 * Under the hood it's composed of a {@link Compressor} with a fast attack
8 * and release and max compression ratio.
9 *
10 * @example
11 * const limiter = new Tone.Limiter(-20).toDestination();
12 * const oscillator = new Tone.Oscillator().connect(limiter);
13 * oscillator.start();
14 * @category Component
15 */
16export class Limiter extends ToneAudioNode {
17 constructor() {
18 const options = optionsFromArguments(Limiter.getDefaults(), arguments, [
19 "threshold",
20 ]);
21 super(options);
22 this.name = "Limiter";
23 this._compressor =
24 this.input =
25 this.output =
26 new Compressor({
27 context: this.context,
28 ratio: 20,
29 attack: 0.003,
30 release: 0.01,
31 threshold: options.threshold,
32 });
33 this.threshold = this._compressor.threshold;
34 readOnly(this, "threshold");
35 }
36 static getDefaults() {
37 return Object.assign(ToneAudioNode.getDefaults(), {
38 threshold: -12,
39 });
40 }
41 /**
42 * A read-only decibel value for metering purposes, representing the current amount of gain
43 * reduction that the compressor is applying to the signal.
44 */
45 get reduction() {
46 return this._compressor.reduction;
47 }
48 dispose() {
49 super.dispose();
50 this._compressor.dispose();
51 this.threshold.dispose();
52 return this;
53 }
54}
55//# sourceMappingURL=Limiter.js.map
\No newline at end of file