Tone.js/test/tests/Components.js

1063 lines
26 KiB
JavaScript
Raw Normal View History

/* global it, describe, maxTimeout*/
2014-07-30 19:10:45 +00:00
2015-02-02 17:48:04 +00:00
define(["tests/Core", "chai", "Tone/component/CrossFade", "Tone/core/Master", "Tone/signal/Signal",
2015-02-10 21:35:19 +00:00
"Recorder", "Tone/component/Panner", "Tone/component/LFO", "Tone/component/Gate",
2014-08-24 19:46:55 +00:00
"Tone/component/Follower", "Tone/component/Envelope", "Tone/component/Filter", "Tone/component/EQ",
2014-09-21 17:37:34 +00:00
"Tone/component/Merge", "Tone/component/Split", "tests/Common", "Tone/component/AmplitudeEnvelope",
"Tone/component/LowpassCombFilter", "Tone/component/FeedbackCombFilter", "Tone/component/Mono",
2014-11-04 06:27:52 +00:00
"Tone/component/MultibandSplit", "Tone/component/Compressor", "Tone/component/PanVol",
"Tone/component/MultibandCompressor", "Tone/component/ScaledEnvelope", "Tone/component/Limiter"],
2015-02-02 17:48:04 +00:00
function(coreTest, chai, CrossFade, Master, Signal, Recorder, Panner, LFO, Gate, Follower, Envelope,
Filter, EQ, Merge, Split, Test, AmplitudeEnvelope, LowpassCombFilter, FeedbackCombFilter,
Mono, MultibandSplit, Compressor, PanVol, MultibandCompressor, ScaledEnvelope, Limiter){
2014-06-21 17:04:48 +00:00
var expect = chai.expect;
Master.mute();
2015-02-02 17:48:04 +00:00
describe("Tone.CrossFade", function(){
this.timeout(maxTimeout);
2014-06-21 17:04:48 +00:00
2015-02-02 17:48:04 +00:00
var crossFade, drySignal, wetSignal, recorder;
2014-06-21 17:04:48 +00:00
it("can be created and disposed", function(){
2015-02-02 17:48:04 +00:00
var dw = new CrossFade();
2014-06-21 17:04:48 +00:00
dw.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(dw);
2014-06-21 17:04:48 +00:00
});
2014-10-13 20:32:04 +00:00
it("handles input and output connections", function(){
Test.onlineContext();
2015-02-02 17:48:04 +00:00
var crossFade = new CrossFade();
Test.acceptsInput(crossFade, 0);
Test.acceptsInput(crossFade, 1);
Test.acceptsOutput(crossFade);
crossFade.dispose();
2014-10-13 20:32:04 +00:00
});
2014-06-21 17:04:48 +00:00
it("pass 100% dry signal", function(done){
Test.offlineTest(0.1, function(dest){
2015-02-02 17:48:04 +00:00
crossFade = new CrossFade();
drySignal = new Signal(10);
wetSignal = new Signal(20);
2015-02-02 17:48:04 +00:00
drySignal.connect(crossFade, 0, 0);
wetSignal.connect(crossFade, 0, 1);
recorder = new Recorder();
2015-02-10 21:35:19 +00:00
crossFade.fade.value = 0;
2015-02-02 17:48:04 +00:00
crossFade.connect(dest);
}, function(sample){
2015-02-02 17:48:04 +00:00
expect(sample).to.closeTo(10, 0.01);
}, function(){
2015-02-02 17:48:04 +00:00
crossFade.dispose();
2014-06-21 17:04:48 +00:00
drySignal.dispose();
wetSignal.dispose();
done();
2014-06-21 17:04:48 +00:00
});
});
it("pass 100% wet signal", function(done){
Test.offlineTest(0.1, function(dest){
2015-02-02 17:48:04 +00:00
crossFade = new CrossFade();
drySignal = new Signal(10);
wetSignal = new Signal(20);
2015-02-02 17:48:04 +00:00
drySignal.connect(crossFade, 0, 0);
wetSignal.connect(crossFade, 0, 1);
recorder = new Recorder();
2015-02-10 21:35:19 +00:00
crossFade.fade.value = 1;
2015-02-02 17:48:04 +00:00
crossFade.connect(dest);
}, function(sample){
2015-02-02 17:48:04 +00:00
expect(sample).to.closeTo(20, 0.01);
}, function(){
2015-02-02 17:48:04 +00:00
crossFade.dispose();
2014-06-21 17:04:48 +00:00
drySignal.dispose();
wetSignal.dispose();
done();
2014-06-21 17:04:48 +00:00
});
});
it("can mix two signals", function(done){
Test.offlineTest(0.1, function(dest){
2015-02-02 17:48:04 +00:00
crossFade = new CrossFade();
2015-02-12 04:10:28 +00:00
drySignal = new Signal(0.5);
wetSignal = new Signal(0.5);
2015-02-02 17:48:04 +00:00
drySignal.connect(crossFade, 0, 0);
wetSignal.connect(crossFade, 0, 1);
recorder = new Recorder();
2015-02-10 21:35:19 +00:00
crossFade.fade.value = 0.5;
2015-02-02 17:48:04 +00:00
crossFade.connect(dest);
}, function(sample){
2015-02-12 04:10:28 +00:00
expect(sample).to.closeTo(0.707, 0.01);
}, function(){
2015-02-02 17:48:04 +00:00
crossFade.dispose();
2014-06-21 17:04:48 +00:00
drySignal.dispose();
wetSignal.dispose();
done();
2014-06-21 17:04:48 +00:00
});
});
});
describe("Tone.Panner", function(){
this.timeout(maxTimeout);
2014-06-21 17:04:48 +00:00
it("can be created and disposed", function(){
var panner = new Panner();
panner.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(panner);
2014-06-21 17:04:48 +00:00
});
2014-10-13 20:32:04 +00:00
it("handles input and output connections", function(){
Test.onlineContext();
var panner = new Panner();
Test.acceptsInputAndOutput(panner);
panner.dispose();
});
it("passes the incoming signal through", function(done){
var panner;
Test.passesAudio(function(input, output){
panner = new Panner();
input.connect(panner);
panner.connect(output);
}, function(){
panner.dispose();
done();
});
});
2014-06-21 17:04:48 +00:00
it("can pan an incoming signal", function(done){
//pan hard right
var signal, panner;
Test.offlineStereoTest(0.1, function(dest){
signal = new Signal(1);
panner = new Panner();
signal.connect(panner);
2015-02-10 21:35:19 +00:00
panner.pan.value = 1;
panner.connect(dest);
}, function(L, R){
2015-02-02 17:48:04 +00:00
expect(L).to.be.closeTo(0, 0.01);
expect(R).to.be.closeTo(1, 0.01);
}, function(){
panner.dispose();
signal.dispose();
2014-06-21 17:04:48 +00:00
done();
});
});
});
describe("Tone.LFO", function(){
this.timeout(maxTimeout);
2014-06-21 17:04:48 +00:00
it("can be created and disposed", function(){
var l = new LFO();
l.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(l);
2014-06-21 17:04:48 +00:00
});
it("can be started and stopped", function(){
Test.onlineContext();
2014-06-21 17:04:48 +00:00
var lfo = new LFO();
lfo.start();
lfo.stop();
lfo.dispose();
});
2014-10-13 20:32:04 +00:00
it("handles output connections", function(){
Test.onlineContext();
var lfo = new LFO();
Test.acceptsOutput(lfo);
lfo.dispose();
});
2014-06-21 17:04:48 +00:00
it("can be creates an oscillation in a specific range", function(done){
var lfo;
Test.offlineTest(0.1, function(dest){
lfo = new LFO(100, 10, 20);
lfo.connect(dest);
lfo.start();
}, function(sample){
expect(sample).to.be.within(10, 20);
}, function(){
2014-06-21 17:04:48 +00:00
lfo.dispose();
done();
});
});
it("can change the oscillation range", function(done){
var lfo;
Test.offlineTest(0.1, function(dest){
lfo = new LFO(100, 10, 20);
lfo.connect(dest);
lfo.start();
2015-02-10 21:35:19 +00:00
lfo.min = 15;
lfo.max = 18;
}, function(sample){
expect(sample).to.be.within(15, 18);
}, function(){
2014-06-21 17:04:48 +00:00
lfo.dispose();
done();
});
});
2015-02-10 21:35:19 +00:00
it("handles getters/setters as objects", function(){
var lfo = new LFO();
var values = {
"type" : "square",
"min" : -1,
"max" : 2,
"phase" : 180,
"frequency" : "8n",
};
lfo.set(values);
2015-02-12 04:10:28 +00:00
expect(lfo.get()).to.contain.keys(Object.keys(values));
2015-02-10 21:35:19 +00:00
expect(lfo.type).to.equal(values.type);
expect(lfo.min).to.equal(values.min);
expect(lfo.max).to.equal(values.max);
expect(lfo.phase).to.equal(values.phase);
lfo.dispose();
});
2014-06-21 17:04:48 +00:00
});
2014-07-30 19:10:45 +00:00
describe("Tone.Gate", function(){
this.timeout(maxTimeout);
2014-07-30 19:10:45 +00:00
it("can be created and disposed", function(){
var g = new Gate();
g.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(g);
2014-07-30 19:10:45 +00:00
});
2014-10-13 20:32:04 +00:00
it("handles input and output connections", function(){
Test.onlineContext();
var gate = new Gate();
Test.acceptsInputAndOutput(gate);
gate.dispose();
});
2015-02-10 21:35:19 +00:00
it("handles getter/setters", function(){
Test.onlineContext();
var gate = new Gate();
var values = {
"attack" : "4n",
"release" : "8n",
"threshold" : -25,
};
gate.set(values);
expect(gate.get()).to.have.keys(["attack", "release", "threshold"]);
expect(gate.attack).to.equal(values.attack);
expect(gate.decay).to.equal(values.decay);
expect(gate.threshold).to.be.closeTo(values.threshold, 0.1);
gate.dispose();
});
2014-07-30 19:10:45 +00:00
it("won't let signals below a db thresh through", function(done){
var gate, sig;
Test.offlineTest(0.5, function(dest){
2015-01-06 04:33:05 +00:00
gate = new Gate(-10, 0.01);
sig = new Signal(gate.dbToGain(-11));
sig.connect(gate);
gate.connect(dest);
}, function(sample){
expect(sample).to.equal(0);
}, function(){
2014-07-30 19:10:45 +00:00
gate.dispose();
sig.dispose();
done();
});
});
it("lets signals above the db thresh through", function(done){
var gate, sig, level;
Test.offlineTest(0.5, function(dest){
2015-01-06 04:33:05 +00:00
gate = new Gate(-8, 0.01);
level = gate.dbToGain(-6);
sig = new Signal(level);
sig.connect(gate);
gate.connect(dest);
}, function(sample, time){
if (time >= 0.1){
2014-10-13 20:32:04 +00:00
expect(sample).to.be.closeTo(level, 0.001);
}
}, function(){
2014-07-30 19:10:45 +00:00
gate.dispose();
sig.dispose();
done();
});
});
});
describe("Tone.Follower", function(){
this.timeout(maxTimeout);
2014-07-30 19:10:45 +00:00
it("can be created and disposed", function(){
var f = new Follower();
f.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(f);
2014-07-30 19:10:45 +00:00
});
it("handles input and output connections", function(){
Test.onlineContext();
var foll = new Follower(0.1, 0.5);
Test.acceptsInputAndOutput(foll);
foll.dispose();
});
2014-07-30 19:10:45 +00:00
it("smoothes the incoming signal", function(done){
var foll, sig;
Test.offlineTest(0.1, function(dest){
foll = new Follower(0.1, 0.5);
sig = new Signal(0);
sig.connect(foll);
foll.connect(dest);
sig.setValueAtTime(1, "+0.1");
}, function(sample){
expect(sample).to.lessThan(1);
}, function(){
2014-07-30 19:10:45 +00:00
foll.dispose();
sig.dispose();
done();
});
});
2015-02-10 21:35:19 +00:00
it("handles getter/setter as Object", function(){
var foll = new Follower();
var values = {
"attack" : "8n",
"release" : "4n"
};
foll.set(values);
expect(foll.get()).to.have.keys(["attack", "release"]);
expect(foll.get()).to.deep.equal(values);
foll.dispose();
});
2014-07-30 19:10:45 +00:00
});
describe("Tone.Envelope", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var e = new Envelope();
e.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(e);
});
it("handles output connections", function(){
Test.onlineContext();
var e = new Envelope();
Test.acceptsOutput(e);
e.dispose();
});
it ("can take parameters as both an object and as arguments", function(){
var e0 = new Envelope({
"attack" : 0,
"decay" : 0.5,
"sustain" : 1
});
expect(e0.attack).to.equal(0);
expect(e0.decay).to.equal(0.5);
expect(e0.sustain).to.equal(1);
e0.dispose();
var e1 = new Envelope(0.1, 0.2, 0.3);
expect(e1.attack).to.equal(0.1);
expect(e1.decay).to.equal(0.2);
expect(e1.sustain).to.equal(0.3);
e1.dispose();
});
it ("can schedule an ADSR envelope", function(done){
var env;
Test.offlineTest(0.7, function(dest){
env = new Envelope(0.1, 0.2, 0.5, 0.1);
env.connect(dest);
env.triggerAttack(0);
env.triggerRelease(0.4);
}, function(sample, time){
if (time < 0.1){
expect(sample).to.be.within(0, 1);
} else if (time < 0.3){
expect(sample).to.be.within(0.5, 1);
} else if (time < 0.4){
2014-11-30 18:20:57 +00:00
expect(sample).to.be.within(0.499, 0.51);
} else if (time < 0.5){
expect(sample).to.be.within(0, 0.51);
} else {
expect(sample).to.be.below(0.1);
}
}, function(){
env.dispose();
done();
});
});
2015-02-10 21:35:19 +00:00
it ("can get and set values an Objects", function(){
var env = new Envelope();
var values = {
"attack" : 0,
"decay" : 0.5,
"sustain" : 1,
"release" : "4n"
};
env.set(values);
expect(env.get()).to.deep.equal(values);
env.dispose();
});
2015-02-24 00:46:28 +00:00
it ("can schedule an attackRelease", function(done){
var env;
Test.offlineTest(0.7, function(dest){
env = new Envelope(0.1, 0.2, 0.5, 0.1);
env.connect(dest);
env.triggerAttackRelease(0.4, 0);
}, function(sample, time){
if (time < 0.1){
expect(sample).to.be.within(0, 1);
} else if (time < 0.3){
expect(sample).to.be.within(0.5, 1);
} else if (time < 0.4){
expect(sample).to.be.within(0.499, 0.51);
} else if (time < 0.5){
expect(sample).to.be.within(0, 0.51);
} else {
expect(sample).to.be.below(0.1);
}
}, function(){
env.dispose();
done();
});
});
});
describe("Tone.Filter", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var f = new Filter();
f.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(f);
});
it("handles input and output connections", function(){
Test.onlineContext();
var f = new Filter();
Test.acceptsInputAndOutput(f);
f.dispose();
});
2015-02-10 21:35:19 +00:00
it("can set/get values as an Object", function(){
var f = new Filter();
var values = {
"type" : "highpass",
"frequency" : 440,
"rolloff" : -24,
"Q" : 2,
"gain" : -6,
};
f.set(values);
expect(f.get()).to.have.keys(["type", "frequency", "rolloff", "Q", "gain"]);
expect(f.type).to.equal(values.type);
expect(f.frequency.value).to.equal(values.frequency);
expect(f.rolloff).to.equal(values.rolloff);
expect(f.Q.value).to.equal(values.Q);
expect(f.gain.value).to.be.closeTo(values.gain, 0.04);
f.dispose();
});
2014-10-13 20:32:04 +00:00
it("passes the incoming signal through", function(done){
var filter;
Test.passesAudio(function(input, output){
filter = new Filter();
input.connect(filter);
filter.connect(output);
}, function(){
filter.dispose();
done();
});
});
it ("can take parameters as both an object and as arguments", function(){
Test.onlineContext();
var f0 = new Filter({
"frequency" : 1000,
"type" : "highpass"
});
2015-02-10 21:35:19 +00:00
expect(f0.frequency.value).to.equal(1000);
expect(f0.type).to.equal("highpass");
f0.dispose();
var f1 = new Filter(200, "bandpass");
2015-02-10 21:35:19 +00:00
expect(f1.frequency.value).to.equal(200);
expect(f1.type).to.equal("bandpass");
f1.dispose();
});
});
2014-08-24 16:49:20 +00:00
describe("Tone.EQ", function(){
this.timeout(maxTimeout);
2014-08-24 16:49:20 +00:00
it("can be created and disposed", function(){
var eq = new EQ();
eq.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(eq);
2014-08-24 16:49:20 +00:00
});
it("handles input and output connections", function(){
Test.onlineContext();
var eq = new EQ();
Test.acceptsInputAndOutput(eq);
eq.dispose();
});
2014-10-13 20:32:04 +00:00
it("passes the incoming signal through", function(done){
var eq;
Test.passesAudio(function(input, output){
eq = new EQ();
input.connect(eq);
eq.connect(output);
}, function(){
eq.dispose();
done();
});
});
2015-02-10 21:35:19 +00:00
it("can set/get values as an Object", function(){
Test.onlineContext();
var eq = new EQ();
var values = {
"high" : -12,
"mid" : -24,
"low" : -1
};
eq.set(values);
2015-02-24 00:46:28 +00:00
expect(eq.high.value).to.be.closeTo(values.high, 0.1);
expect(eq.mid.value).to.be.closeTo(values.mid, 0.1);
expect(eq.low.value).to.be.closeTo(values.low, 0.1);
2015-02-10 21:35:19 +00:00
eq.dispose();
});
2014-08-24 16:49:20 +00:00
});
2014-08-24 19:46:55 +00:00
//MERGE
describe("Tone.Merge", function(){
this.timeout(maxTimeout);
2014-08-24 19:46:55 +00:00
it("can be created and disposed", function(){
var mer = new Merge();
mer.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(mer);
2014-08-24 19:46:55 +00:00
});
it("handles input and output connections", function(){
Test.onlineContext();
var mer = new Merge();
Test.acceptsInput(mer.left);
Test.acceptsInput(mer.right);
Test.acceptsOutput(mer);
mer.dispose();
});
2014-08-24 19:46:55 +00:00
it("merge two signal into one stereo signal", function(done){
//make an oscillator to drive the signal
var sigL, sigR, merger;
Test.offlineStereoTest(0.1, function(dest){
sigL = new Signal(1);
sigR = new Signal(2);
merger = new Merge();
sigL.connect(merger.left);
sigR.connect(merger.right);
merger.connect(dest);
}, function(L, R){
expect(L).to.equal(1);
expect(R).to.equal(2);
}, function(){
sigL.dispose();
sigR.dispose();
merger.dispose();
2014-08-24 19:46:55 +00:00
done();
});
});
});
describe("Tone.Split", function(){
this.timeout(maxTimeout);
2014-08-24 19:46:55 +00:00
it("can be created and disposed", function(){
var split = new Split();
split.dispose();
2014-09-20 22:47:40 +00:00
Test.wasDisposed(split);
2014-08-24 19:46:55 +00:00
});
it("handles input and output connections", function(){
Test.onlineContext();
var split = new Split();
Test.acceptsInput(split);
Test.acceptsOutput(split.left);
Test.acceptsOutput(split.right);
split.dispose();
});
it("merges two signal into one stereo signal and then split them back into two signals on left side", function(done){
var sigL, sigR, merger, split;
Test.offlineTest(0.1, function(dest){
sigL = new Signal(1);
sigR = new Signal(2);
merger = new Merge();
split = new Split();
sigL.connect(merger.left);
sigR.connect(merger.right);
merger.connect(split);
split.connect(dest, 0, 0);
}, function(sample){
expect(sample).to.equal(1);
}, function(){
sigL.dispose();
sigR.dispose();
merger.dispose();
split.dispose();
done();
2014-08-24 19:46:55 +00:00
});
});
it("merges two signal into one stereo signal and then split them back into two signals on right side", function(done){
var sigL, sigR, merger, split;
Test.offlineTest(0.1, function(dest){
sigL = new Signal(1);
sigR = new Signal(2);
merger = new Merge();
split = new Split();
sigL.connect(merger.left);
sigR.connect(merger.right);
merger.connect(split);
split.connect(dest, 1, 0);
}, function(sample){
expect(sample).to.equal(2);
}, function(){
sigL.dispose();
sigR.dispose();
merger.dispose();
split.dispose();
2014-08-24 19:46:55 +00:00
done();
});
});
});
2014-09-20 22:47:40 +00:00
describe("Tone.AmplitudeEnvelope", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var ampEnv = new AmplitudeEnvelope();
ampEnv.dispose();
Test.wasDisposed(ampEnv);
});
it("handles input and output connections", function(){
Test.onlineContext();
var ampEnv = new AmplitudeEnvelope();
Test.acceptsInputAndOutput(ampEnv);
ampEnv.dispose();
});
2014-09-20 22:47:40 +00:00
it("inherits all methods from Envelope", function(){
var ampEnv = new AmplitudeEnvelope();
expect(ampEnv).to.be.instanceOf(Envelope);
ampEnv.dispose();
});
});
2014-09-20 23:24:25 +00:00
describe("Tone.LowpassCombFilter", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var lfcf = new LowpassCombFilter();
lfcf.dispose();
Test.wasDisposed(lfcf);
});
it("handles input and output connections", function(){
Test.onlineContext();
var lfcf = new LowpassCombFilter();
Test.acceptsInputAndOutput(lfcf);
lfcf.dispose();
});
2014-10-13 20:32:04 +00:00
it("passes the incoming signal through", function(done){
var lfcf;
Test.passesAudio(function(input, output){
lfcf = new LowpassCombFilter();
input.connect(lfcf);
lfcf.connect(output);
}, function(){
lfcf.dispose();
done();
});
});
2015-02-10 21:35:19 +00:00
it("handles getters/setters", function(){
Test.onlineContext();
var lfcf = new LowpassCombFilter();
var values = {
"resonance" : 0.4,
"dampening" : 4000,
"delayTime" : "4n"
};
lfcf.set(values);
expect(lfcf.get()).to.have.keys(["resonance", "dampening", "delayTime"]);
lfcf.dispose();
});
2014-09-20 23:24:25 +00:00
});
2014-09-21 17:37:34 +00:00
describe("Tone.FeedbackCombFilter", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var fbcf = new FeedbackCombFilter();
fbcf.dispose();
Test.wasDisposed(fbcf);
});
it("handles input and output connections", function(){
Test.onlineContext();
var fbcf = new FeedbackCombFilter();
Test.acceptsInputAndOutput(fbcf);
fbcf.dispose();
});
2014-10-13 20:32:04 +00:00
2015-02-10 21:35:19 +00:00
it("can set delayTime", function(){
Test.onlineContext();
var fbcf = new FeedbackCombFilter();
fbcf.delayTime = "4n";
expect(fbcf.delayTime).to.equal("4n");
fbcf.dispose();
});
2014-10-13 20:32:04 +00:00
it("passes the incoming signal through", function(done){
var fbcf;
Test.passesAudio(function(input, output){
fbcf = new FeedbackCombFilter();
input.connect(fbcf);
fbcf.connect(output);
}, function(){
fbcf.dispose();
done();
});
});
2014-09-21 17:37:34 +00:00
});
describe("Tone.Mono", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var mono = new Mono();
mono.dispose();
Test.wasDisposed(mono);
});
it("handles input and output connections", function(){
Test.onlineContext();
var mono = new Mono();
Test.acceptsInputAndOutput(mono);
mono.dispose();
});
2014-10-13 20:32:04 +00:00
it("passes the incoming signal through", function(done){
var mono;
Test.passesAudio(function(input, output){
mono = new FeedbackCombFilter();
input.connect(mono);
mono.connect(output);
}, function(){
mono.dispose();
done();
});
});
});
describe("Tone.MultibandSplit", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var mband = new MultibandSplit();
mband.dispose();
Test.wasDisposed(mband);
});
it("handles input and output connections", function(){
Test.onlineContext();
var mband = new MultibandSplit();
Test.acceptsInput(mband);
Test.acceptsOutput(mband.low);
Test.acceptsOutput(mband, 1);
Test.acceptsOutput(mband, 2);
mband.dispose();
});
2014-09-21 17:37:34 +00:00
});
describe("Tone.Compressor", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var comp = new Compressor();
comp.dispose();
Test.wasDisposed(comp);
});
it("handles input and output connections", function(){
Test.onlineContext();
var comp = new Compressor();
Test.acceptsInputAndOutput(comp);
comp.dispose();
});
it("passes the incoming signal through", function(done){
var comp;
Test.passesAudio(function(input, output){
comp = new Compressor();
input.connect(comp);
comp.connect(output);
}, function(){
comp.dispose();
done();
});
});
2015-02-10 21:35:19 +00:00
it("can be get and set through object", function(){
var comp = new Compressor();
var values = {
"ratio" : 22,
"threshold" : -30,
"release" : 0.5,
"attack" : 0.03,
"knee" : 20
};
comp.set(values);
expect(comp.get()).to.have.keys(["ratio", "threshold", "release", "attack", "ratio"]);
comp.dispose();
});
it("can get/set all interfaces", function(){
var comp = new Compressor();
var values = {
"ratio" : 22,
"threshold" : -30,
"release" : 0.5,
"attack" : 0.03,
"knee" : 20
};
comp.ratio.value = values.ratio;
comp.threshold.value = values.threshold;
comp.release.value = values.release;
comp.attack.value = values.attack;
comp.knee.value = values.knee;
expect(comp.ratio.value).to.equal(values.ratio);
expect(comp.threshold.value).to.equal(values.threshold);
expect(comp.release.value).to.equal(values.release);
expect(comp.attack.value).to.be.closeTo(values.attack, 0.01);
expect(comp.knee.value).to.equal(values.knee);
comp.dispose();
});
});
2014-11-04 06:27:52 +00:00
describe("Tone.PanVol", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var panvol = new PanVol();
panvol.dispose();
Test.wasDisposed(panvol);
});
it("handles input and output connections", function(){
Test.onlineContext();
var panvol = new PanVol();
Test.acceptsInputAndOutput(panvol);
panvol.dispose();
});
it("passes the incoming signal through", function(done){
var panvol;
Test.passesAudio(function(input, output){
panvol = new PanVol();
input.connect(panvol);
panvol.connect(output);
}, function(){
panvol.dispose();
done();
});
});
2015-02-10 21:35:19 +00:00
it("can set the pan and volume", function(){
var panvol = new PanVol();
panvol.volume.value = -12;
panvol.pan.value = 0;
expect(panvol.volume.value).to.be.closeTo(-12, 0.1);
expect(panvol.pan.value).to.be.equal(0);
});
2014-11-04 06:27:52 +00:00
});
describe("Tone.MultibandCompressor", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var comp = new MultibandCompressor();
comp.dispose();
Test.wasDisposed(comp);
});
it("handles input and output connections", function(){
Test.onlineContext();
var comp = new MultibandCompressor();
Test.acceptsInputAndOutput(comp);
comp.dispose();
});
it("passes the incoming signal through", function(done){
var comp;
Test.passesAudio(function(input, output){
comp = new MultibandCompressor();
input.connect(comp);
comp.connect(output);
}, function(){
comp.dispose();
done();
});
});
2015-02-10 21:35:19 +00:00
it("handles getters/setters", function(){
Test.onlineContext();
var comp = new MultibandCompressor();
var values = {
"low" : {
"attack" : 0.3
},
"mid" : {
"threshold" : -12
}
};
comp.set(values);
expect(comp.get()).to.have.deep.property("low.attack");
expect(comp.get()).to.have.deep.property("mid.threshold");
expect(comp.low.attack.value).to.be.closeTo(0.3, 0.05);
expect(comp.mid.threshold.value).to.be.closeTo(-12, 0.05);
comp.dispose();
});
});
2014-11-04 06:27:52 +00:00
describe("Tone.ScaledEnvelope", function(){
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var e = new ScaledEnvelope();
e.dispose();
Test.wasDisposed(e);
});
it("handles output connections", function(){
Test.onlineContext();
var e = new ScaledEnvelope();
Test.acceptsOutput(e);
e.dispose();
});
it ("can take parameters as an object", function(){
var e0 = new ScaledEnvelope({
"attack" : 0,
"decay" : 0.5,
"sustain" : 1,
"min" : 10,
"max": 5
});
expect(e0.attack).to.equal(0);
expect(e0.decay).to.equal(0.5);
expect(e0.sustain).to.equal(1);
e0.dispose();
});
it ("can schedule an ADSR envelope", function(done){
var env;
Test.offlineTest(0.7, function(dest){
env = new ScaledEnvelope({
"attack" : 0.1,
"decay" : 0.2,
"sustain" : 0.5,
"release" : 0.1,
"min" : 0,
"max": 100
});
env.connect(dest);
env.triggerAttack(0);
env.triggerRelease(0.4);
}, function(sample, time){
if (time < 0.1){
expect(sample).to.be.within(0, 100);
} else if (time < 0.3){
expect(sample).to.be.within(0.5, 100);
} else if (time < 0.4){
expect(sample).to.be.within(0.5, 51);
} else if (time < 0.5){
expect(sample).to.be.within(0, 51);
} else {
expect(sample).to.be.below(1);
}
}, function(){
env.dispose();
done();
});
});
it ("can scale the range", function(done){
var env;
Test.offlineTest(0.7, function(dest){
env = new ScaledEnvelope(0.1, 0.2, 0.5, 0.1);
env.connect(dest);
2015-02-10 21:35:19 +00:00
env.min = 5;
env.max = 10;
2014-11-04 06:27:52 +00:00
env.triggerAttack(0.1);
}, function(sample, time){
if (time < 0.1){
expect(sample).to.be.closeTo(5, 0.1);
} else if (time < 0.2){
expect(sample).to.be.within(5, 10);
}
}, function(){
env.dispose();
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();
});
2014-11-04 06:27:52 +00:00
2015-02-10 21:35:19 +00:00
it("can get and set values", function(){
Test.onlineContext();
var lim = new Limiter();
lim.threshold.value = -12;
expect(lim.threshold.value).to.be.closeTo(-12, 0.05);
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();
});
});
2014-11-04 06:27:52 +00:00
});
2014-06-21 17:04:48 +00:00
});