updated tests with global recorder settings

This commit is contained in:
Yotam Mann 2014-08-27 15:46:32 -04:00
parent 4b51032c7a
commit 0103735589
2 changed files with 60 additions and 85 deletions

View file

@ -1,4 +1,4 @@
/* global it, describe, after */
/* global it, describe, recorderDelay, recorderDuration, maxTimeout, after*/
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",
@ -11,7 +11,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
Master.mute();
describe("Tone.DryWet", function(){
this.timeout(1000);
this.timeout(maxTimeout);
var dryWet, drySignal, wetSignal, recorder;
@ -22,7 +22,6 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
it("pass 100% dry signal", function(done){
dryWet = new DryWet();
dryWet.toMaster();
drySignal = new Signal(10);
wetSignal = new Signal(20);
drySignal.connect(dryWet.dry);
@ -30,23 +29,22 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
recorder = new Recorder();
dryWet.connect(recorder);
dryWet.setDry(1);
recorder.record(0.05, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
expect(buffer[i]).to.equal(10);
}
done();
dryWet.dispose();
drySignal.dispose();
wetSignal.dispose();
recorder.dispose();
done();
});
});
it("pass 100% wet signal", function(done){
dryWet = new DryWet();
dryWet.toMaster();
drySignal = new Signal(10);
wetSignal = new Signal(20);
drySignal.connect(dryWet.dry);
@ -54,7 +52,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
recorder = new Recorder();
dryWet.connect(recorder);
dryWet.setWet(1);
recorder.record(0.05, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
expect(buffer[i]).to.equal(20);
@ -69,17 +67,14 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
it("can mix two signals", function(done){
dryWet = new DryWet();
dryWet.toMaster();
drySignal = new Signal(10);
drySignal.noGC();
wetSignal = new Signal(20);
drySignal.connect(dryWet.dry);
wetSignal.connect(dryWet.wet);
wetSignal.noGC();
recorder = new Recorder();
dryWet.connect(recorder);
dryWet.setWet(1);
recorder.record(0.05, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
expect(buffer[i]).to.equal(20);
@ -91,41 +86,12 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
recorder.dispose();
});
});
it("can ramp from dry to wet", function(done){
dryWet = new DryWet();
drySignal = new Signal(10);
wetSignal = new Signal(20);
drySignal.connect(dryWet.dry);
wetSignal.connect(dryWet.wet);
recorder = new Recorder();
recorder.toMaster();
dryWet.connect(recorder);
dryWet.setWet(0);
dryWet.setWet(1, 0.05);
recorder.record(0.1, 0.0, function(buffers){
var buffer = buffers[0];
expect(buffer[0]).to.be.closeTo(10, 0.01);
for (var i = 0; i < buffer.length; i++){
if (buffer[i] === 20){
expect(recorder.samplesToSeconds(i)).to.be.closeTo(0.05, 0.01);
break;
}
}
done();
dryWet.dispose();
drySignal.dispose();
wetSignal.dispose();
recorder.dispose();
});
});
});
describe("Tone.Recorder", function(){
this.timeout(1000);
this.timeout(maxTimeout);
var recorder = new Recorder();
recorder.toMaster();
after(function(){
recorder.dispose();
@ -139,7 +105,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
it("can record an incoming signal", function(done){
var sig = new Signal(1);
sig.connect(recorder);
recorder.record(0.001, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
expect(buffer[i]).to.equal(1);
@ -151,10 +117,9 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
});
describe("Tone.Panner", function(){
this.timeout(1000);
this.timeout(maxTimeout);
var panner = new Panner();
panner.toMaster();
after(function(){
panner.dispose();
@ -172,7 +137,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
panner.connect(recorder);
//pan hard right
panner.setPan(1);
recorder.record(0.01, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var bufferL = buffers[0];
var bufferR = buffers[1];
for (var i = 0; i < bufferL.length; i++){
@ -187,7 +152,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
});
describe("Tone.LFO", function(){
this.timeout(1000);
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var l = new LFO();
@ -206,7 +171,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
lfo.start();
var recorder = new Recorder();
lfo.connect(recorder);
recorder.record(0.01, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
expect(buffer[i]).to.be.within(10, 20);
@ -223,7 +188,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
lfo.setMin(15);
var recorder = new Recorder();
lfo.connect(recorder);
recorder.record(0.01, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
expect(buffer[i]).to.be.within(15, 20);
@ -237,7 +202,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
describe("Tone.Gate", function(){
this.timeout(1000);
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var g = new Gate();
@ -250,7 +215,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
var recorder = new Recorder();
sig.connect(gate);
gate.connect(recorder);
recorder.record(0.01, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
expect(buffer[i]).to.equal(0);
@ -268,7 +233,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
var recorder = new Recorder();
sig.connect(gate);
gate.connect(recorder);
recorder.record(0.01, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
expect(buffer[i]).to.greaterThan(0);
@ -282,7 +247,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
});
describe("Tone.Follower", function(){
this.timeout(1000);
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var f = new Follower();
@ -290,13 +255,13 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
});
it("smoothes the incoming signal", function(done){
var foll = new Follower(0.1);
var foll = new Follower(recorderDuration, 0.5);
var sig = new Signal(0);
var recorder = new Recorder();
sig.connect(foll);
sig.setValue(1);
foll.connect(recorder);
recorder.record(0.01, 0.1, function(buffers){
sig.setValueAtTime(1, "+", recorderDelay);
recorder.record(recorderDuration, recorderDelay, function(buffers){
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
expect(buffer[i]).to.lessThan(1);
@ -311,7 +276,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
});
describe("Tone.Envelope", function(){
this.timeout(1000);
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var e = new Envelope();
@ -338,7 +303,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
});
describe("Tone.Filter", function(){
this.timeout(1000);
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var f = new Filter();
@ -362,7 +327,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
});
describe("Tone.EQ", function(){
this.timeout(1000);
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var eq = new EQ();
@ -373,7 +338,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
//MERGE
describe("Tone.Merge", function(){
this.timeout(1000);
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var mer = new Merge();
@ -389,7 +354,7 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
sigR.connect(merger.right);
var recorder = new Recorder(2);
merger.connect(recorder);
recorder.record(0.1, 0.1, function(buffers){
recorder.record(recorderDuration, recorderDelay, function(buffers){
var lBuffer = buffers[0];
var rBuffer = buffers[1];
//get the left buffer and check that all values are === 1
@ -404,36 +369,44 @@ function(coreTest, chai, DryWet, Master, Signal, Recorder, Panner, LFO, Gate, Fo
//SCALE
describe("Tone.Split", function(){
this.timeout(1000);
this.timeout(maxTimeout);
it("can be created and disposed", function(){
var split = new Split();
split.dispose();
});
it("merges two signal into one stereo signal and then split them back into two signals", function(done){
it("merges two signal into one stereo signal and then split them back into two signals on left side", function(done){
//make an oscillator to drive the signal
var sigL = new Signal(1);
var sigR = new Signal(2);
var sig = new Signal(1);
var merger = new Merge();
var split = new Split();
sigL.connect(merger.left);
sigR.connect(merger.right);
sig.connect(merger.left);
merger.connect(split);
var recorderL = new Recorder();
var recorderR = new Recorder();
split.left.connect(recorderL);
split.right.connect(recorderR);
recorderL.record(0.1, 0.1, function(buffers){
var recorder = new Recorder();
split.left.connect(recorder);
recorder.record(recorderDuration, recorderDelay, function(buffers){
var lBuffer = buffers[0];
for (var i = 0; i < lBuffer.length; i++){
expect(lBuffer[i]).to.equal(1);
}
done();
});
recorderR.record(0.1, 0.1, function(buffers){
var rBuffer = buffers[0];
for (var j = 0; j < rBuffer.length; j++){
expect(rBuffer[j]).to.equal(2);
});
it("merges two signal into one stereo signal and then split them back into two signals on right side", function(done){
//make an oscillator to drive the signal
var sig = new Signal(2);
var merger = new Merge();
var split = new Split();
sig.connect(merger.right);
merger.connect(split);
var recorder = new Recorder();
split.right.connect(recorder);
recorder.record(recorderDuration, recorderDelay, function(buffers){
var lBuffer = buffers[0];
for (var i = 0; i < lBuffer.length; i++){
expect(lBuffer[i]).to.equal(2);
}
done();
});

View file

@ -1,4 +1,4 @@
/* global it, describe, after */
/* global it, describe, after, maxTimeout, recorderDelay, recorderDuration */
define(["chai", "Tone/source/Player", "Tone/core/Master", "Tone/source/Oscillator", "Tone/component/Recorder", "Tone/source/Noise", "tests/Core"],
function(chai, Player, Master, Oscillator, Recorder, Noise){
@ -8,7 +8,7 @@ function(chai, Player, Master, Oscillator, Recorder, Noise){
Master.mute();
describe("Tone.Player", function(){
this.timeout(1000);
this.timeout(maxTimeout);
var player = new Player("./testAudio/kick.mp3");
player.toMaster();
@ -63,7 +63,7 @@ function(chai, Player, Master, Oscillator, Recorder, Noise){
});
describe("Tone.Oscillator", function(){
this.timeout(1000);
this.timeout(maxTimeout);
var oscillator = new Oscillator();
oscillator.toMaster();
@ -110,13 +110,14 @@ function(chai, Player, Master, Oscillator, Recorder, Noise){
it("be scheduled to start in the future", function(done){
var recorder = new Recorder();
oscillator.connect(recorder);
oscillator.start("+.05");
recorder.record(0.1, 0.05, function(buffers){
var startOffset = 0.05;
oscillator.start("+"+(recorderDelay + startOffset));
recorder.record(recorderDuration + startOffset, recorderDelay, function(buffers){
oscillator.stop();
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
if (buffer[i] !== 0){
expect(oscillator.samplesToSeconds(i)).to.be.closeTo(0.05, 0.01);
expect(oscillator.samplesToSeconds(i)).to.be.closeTo(startOffset, 0.1);
break;
}
}
@ -138,7 +139,7 @@ function(chai, Player, Master, Oscillator, Recorder, Noise){
});
describe("Tone.Noise", function(){
this.timeout(1000);
this.timeout(maxTimeout);
var noise = new Noise();
noise.toMaster();
@ -185,13 +186,14 @@ function(chai, Player, Master, Oscillator, Recorder, Noise){
it("be scheduled to start in the future", function(done){
var recorder = new Recorder();
noise.connect(recorder);
noise.start("+.05");
recorder.record(0.1, 0.05, function(buffers){
var startOffset = 0.1;
noise.start("+"+(recorderDelay + startOffset));
recorder.record(recorderDuration + startOffset, recorderDelay, function(buffers){
noise.stop();
var buffer = buffers[0];
for (var i = 0; i < buffer.length; i++){
if (buffer[i] !== 0){
expect(noise.samplesToSeconds(i)).to.be.closeTo(0.05, 0.01);
expect(noise.samplesToSeconds(i)).to.be.closeTo(startOffset, 0.1);
break;
}
}