mirror of
https://github.com/Tonejs/Tone.js
synced 2024-11-16 08:38:00 +00:00
Tone.Limiter is a compressor with limiter settings
This commit is contained in:
parent
09f4b5fdf8
commit
574c75f7c6
2 changed files with 78 additions and 3 deletions
47
Tone/component/Limiter.js
Normal file
47
Tone/component/Limiter.js
Normal file
|
@ -0,0 +1,47 @@
|
|||
define(["Tone/core/Tone", "Tone/component/Compressor"], function(Tone){
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* @class A limiter on the incoming signal. Composed of a Tone.Compressor
|
||||
* with a fast attack and decay value.
|
||||
*
|
||||
* @extends {Tone}
|
||||
* @constructor
|
||||
* @param {number} threshold the threshold in decibels
|
||||
*/
|
||||
Tone.Limiter = function(threshold){
|
||||
|
||||
/**
|
||||
* the compressor
|
||||
* @private
|
||||
* @type {Tone.Compressor}
|
||||
*/
|
||||
this._compressor = this.input = this.output = new Tone.Compressor({
|
||||
"attack" : 0.001,
|
||||
"decay" : 0.001,
|
||||
"threshold" : threshold
|
||||
});
|
||||
};
|
||||
|
||||
Tone.extend(Tone.Limiter);
|
||||
|
||||
/**
|
||||
* set the threshold value
|
||||
* @param {number} value the threshold in decibels
|
||||
*/
|
||||
Tone.Limiter.prototype.setThreshold = function(value) {
|
||||
this._compressor.setThreshold(value);
|
||||
};
|
||||
|
||||
/**
|
||||
* clean up
|
||||
*/
|
||||
Tone.Limiter.prototype.dispose = function(){
|
||||
Tone.prototype.dispose.call(this);
|
||||
this._compressor.dispose();
|
||||
this._compressor = null;
|
||||
};
|
||||
|
||||
return Tone.Limiter;
|
||||
});
|
|
@ -1,4 +1,4 @@
|
|||
/* global it, describe, maxTimeout, after*/
|
||||
/* global it, describe, maxTimeout*/
|
||||
|
||||
define(["tests/Core", "chai", "Tone/component/DryWet", "Tone/core/Master", "Tone/signal/Signal",
|
||||
"Tone/component/Recorder", "Tone/component/Panner", "Tone/component/LFO", "Tone/component/Gate",
|
||||
|
@ -6,10 +6,10 @@ define(["tests/Core", "chai", "Tone/component/DryWet", "Tone/core/Master", "Tone
|
|||
"Tone/component/Merge", "Tone/component/Split", "tests/Common", "Tone/component/AmplitudeEnvelope",
|
||||
"Tone/component/LowpassCombFilter", "Tone/component/FeedbackCombFilter", "Tone/component/Mono",
|
||||
"Tone/component/MultibandSplit", "Tone/component/Compressor", "Tone/component/PanVol",
|
||||
"Tone/component/MultibandCompressor", "Tone/component/ScaledEnvelope"],
|
||||
"Tone/component/MultibandCompressor", "Tone/component/ScaledEnvelope", "Tone/component/Limiter"],
|
||||
function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Follower, Envelope,
|
||||
Filter, EQ, Merge, Split, Test, AmplitudeEnvelope, LowpassCombFilter, FeedbackCombFilter,
|
||||
Mono, MultibandSplit, Compressor, PanVol, MultibandCompressor, ScaledEnvelope){
|
||||
Mono, MultibandSplit, Compressor, PanVol, MultibandCompressor, ScaledEnvelope, Limiter){
|
||||
var expect = chai.expect;
|
||||
|
||||
Master.mute();
|
||||
|
@ -851,6 +851,34 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
|
|||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("Tone.Limiter", function(){
|
||||
this.timeout(maxTimeout);
|
||||
|
||||
it("can be created and disposed", function(){
|
||||
var lim = new Limiter();
|
||||
lim.dispose();
|
||||
Test.wasDisposed(lim);
|
||||
});
|
||||
|
||||
it("handles input and output connections", function(){
|
||||
Test.onlineContext();
|
||||
var lim = new Limiter();
|
||||
Test.acceptsInputAndOutput(lim);
|
||||
lim.dispose();
|
||||
});
|
||||
|
||||
it("passes the incoming signal through", function(done){
|
||||
var lim;
|
||||
Test.passesAudio(function(input, output){
|
||||
lim = new Limiter();
|
||||
input.connect(lim);
|
||||
lim.connect(output);
|
||||
}, function(){
|
||||
lim.dispose();
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue