diff --git a/test/tests/Signal.js b/test/tests/Signal.js index 0dbc0167..6be8788d 100644 --- a/test/tests/Signal.js +++ b/test/tests/Signal.js @@ -1,39 +1,55 @@ define(["chai", "Tone/component/Recorder", "Tone/signal/Signal", "Tone/signal/Add", "Tone/signal/Multiply", - "Tone/signal/Scale", "Tone/source/Oscillator", "Tone/signal/Merge", "Tone/signal/Split"], -function(chai, Recorder, Signal, Add, Multiply, Scale, Oscillator, Merge, Split){ + "Tone/signal/Scale", "Tone/source/Oscillator", "Tone/signal/Merge", "Tone/signal/Split", "tests/WebAudio"], +function(chai, Recorder, Signal, Add, Multiply, Scale, Oscillator, Merge, Split, Master){ var expect = chai.expect; //SIGNAL describe("Tone.Signal", function(){ - this.timeout(300); - it("outputs correct value", function(done){ - var signal = new Signal(2); - var recorder = new Recorder(); - signal.connect(recorder); - recorder.record(0.05); - setTimeout(function(){ - var buffer = recorder.getFloat32Array()[0]; - for (var i = 0; i < buffer.length; i++){ - expect(buffer[i]).to.equal(2); + this.timeout(1000); + + + it("can start with a value initially", function(){ + var signal = new Signal(100); + expect(signal.getValue()).to.equal(100); + }); + + it("can set a value", function(){ + var signal = new Signal(0); + signal.setValue(10); + expect(signal.getValue()).to.equal(10); + }); + + it("can set a value in the future", function(done){ + var signal = new Signal(0); + // signal.toMaster(); + signal.setValueAtTime(10, "+0.1"); + signal.noGC(); + expect(signal.getValue()).to.equal(0); + var interval = setInterval(function(){ + if (signal.getValue() === 10){ + done(); + clearInterval(interval); + signal.dispose(); } - done(); - }, 100); + }, 10); }); - it("can change value with sample accurate timing", function(done){ + it("can change value with sample accurate timing", function(done){ var signal = new Signal(0); - var recorder = new Recorder(1); + var waitTime = 0.05; + var recorder = new Recorder(); signal.connect(recorder); - var waitTime = 0.03; - recorder.record(0.05); + signal.noGC(); signal.setValueAtTime(1, "+"+waitTime);//ramp after 50ms + recorder.record(0.1); setTimeout(function(){ var buffer = recorder.getFloat32Array()[0]; for (var i = 0; i < buffer.length; i++){ if (buffer[i] === 1){ - expect(signal.samplesToSeconds(i)).is.closeTo(waitTime, 0.01); + expect(signal.samplesToSeconds(i)).is.closeTo(waitTime, 0.001); done(); + signal.dispose(); break; } } @@ -43,6 +59,8 @@ function(chai, Recorder, Signal, Add, Multiply, Scale, Oscillator, Merge, Split) it("can sync to another signal", function(done){ var signal0 = new Signal(1); var signal1 = new Signal(2); + signal0.noGC(); + signal1.noGC(); //sync signal1 to signal0 signal1.sync(signal0); //change signal0 and signal1 should also change @@ -56,13 +74,37 @@ function(chai, Recorder, Signal, Add, Multiply, Scale, Oscillator, Merge, Split) expect(buffer[i]).to.equal(4); } done(); + signal0.dispose(); + signal1.dispose(); }, 100); - }); + }); + + it("can ramp from the current value", function(done){ + var signal = new Signal(-10); + signal.noGC(); + var recorder = new Recorder(1); + signal.connect(recorder); + var waitTime = 0.03; + recorder.record(0.05); + expect(signal.getValue()).to.equal(-10); + signal.linearRampToValueNow(1, waitTime); + setTimeout(function(){ + var buffer = recorder.getFloat32Array()[0]; + for (var i = 0; i < buffer.length; i++){ + if (buffer[i] === 1){ + expect(signal.samplesToSeconds(i)).is.closeTo(waitTime, 0.01); + done(); + signal.dispose(); + break; + } + } + }, 100); + }); }); //ADD describe("Tone.Add", function(){ - this.timeout(300); + this.timeout(500); it("correctly sums a signal and a number", function(done){ var signal = new Signal(0); var adder = new Add(3); @@ -99,7 +141,7 @@ function(chai, Recorder, Signal, Add, Multiply, Scale, Oscillator, Merge, Split) //MULTIPLY describe("Tone.Multiply", function(){ - this.timeout(300); + this.timeout(500); it("correctly multiplys a signal and a scalar", function(done){ var signal = new Signal(2); var mult = new Multiply(10); @@ -120,7 +162,7 @@ function(chai, Recorder, Signal, Add, Multiply, Scale, Oscillator, Merge, Split) //SCALE describe("Tone.Scale", function(){ - this.timeout(300); + this.timeout(500); it("scales an input range to an output range", function(done){ //make an oscillator to drive the signal var osc = new Oscillator(1000); @@ -143,7 +185,7 @@ function(chai, Recorder, Signal, Add, Multiply, Scale, Oscillator, Merge, Split) //MERGE describe("Tone.Merge", function(){ - this.timeout(300); + this.timeout(500); it("merge two signal into one stereo signal", function(done){ //make an oscillator to drive the signal var sigL = new Signal(1); @@ -170,7 +212,7 @@ function(chai, Recorder, Signal, Add, Multiply, Scale, Oscillator, Merge, Split) //SCALE describe("Tone.Split", function(){ - this.timeout(300); + this.timeout(500); it("merges two signal into one stereo signal and then split them back into two signals", function(done){ //make an oscillator to drive the signal var sigL = new Signal(1);