Permalink
Browse files

Lots more tests for single-sample AudioletNodes.

  • Loading branch information...
oampo committed Feb 12, 2012
1 parent 2fa6882 commit 039cc5df960bdbc8744cfea4d5f39da8fb74561a
@@ -0,0 +1,52 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testBadValueDetector() {
+ var detected = false
+ var audiolet = new Audiolet();
+ var source = new AudioletNode(audiolet, 0, 1);
+ var bvd = new BadValueDetector(audiolet, function() {
+ detected = true;
+ });
+
+ source.connect(bvd);
+
+ // Null
+ source.outputs[0].samples = [null];
+ bvd.tick();
+ Assert.assertTrue(detected, "Null detected");
+
+ // NaN
+ detected = false;
+ source.outputs[0].samples = [NaN];
+ bvd.tick();
+ Assert.assertTrue(detected, "NaN detected");
+
+ // Undefined
+ detected = false;
+ source.outputs[0].samples = [undefined];
+ bvd.tick();
+ Assert.assertTrue(detected, "Undefined detected");
+
+ // Infinity
+ detected = false;
+ source.outputs[0].samples = [Infinity];
+ bvd.tick();
+ Assert.assertTrue(detected, "Undefined detected");
+
+ // -Infinity
+ detected = false;
+ source.outputs[0].samples = [-Infinity];
+ bvd.tick();
+ Assert.assertTrue(detected, "Undefined detected");
+
+ // Pass values
+ detected = false;
+ source.outputs[0].samples = [0.7];
+ bvd.tick();
+ Assert.assertFalse(detected, "Values undetected");
+}
+
+test("Bad Value Detector", testBadValueDetector);
View
@@ -0,0 +1,26 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testBitCrusher() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var bitCrusher = new BitCrusher(audiolet, 8);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(bitCrusher);
+ bitCrusher.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ bitCrusher.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer);
+}
+
+test("Bit Crusher", testBitCrusher);
View
@@ -0,0 +1,25 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testCombFilter() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var combFilter = new CombFilter(audiolet, 0.1, 0.1, 0.5);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(combFilter);
+ combFilter.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ combFilter.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertAudibleValues(buffer);
+}
+
+test("Comb Filter", testCombFilter);
View
@@ -0,0 +1,45 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testDCFilter() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var add = new Add(audiolet, 1); // Adds a DC offset
+ var dcFilter = new DCFilter(audiolet);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(add);
+ add.connect(dcFilter);
+ dcFilter.connect(recorder);
+
+ // Give the filter time to start filtering the offset
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ add.tick();
+ dcFilter.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, -1, 2);
+
+ // Most of the DC offset should now be filtered
+ recorder.reset();
+ for (var i=0; i<audiolet.device.sampleRate; i++) {
+ sine.tick();
+ add.tick();
+ dcFilter.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, -1, 1);
+}
+
+test("DC Filter", testDCFilter);
@@ -0,0 +1,25 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testDampedCombFilter() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var combFilter = new DampedCombFilter(audiolet, 0.1, 0.1, 0.5, 0.05);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(combFilter);
+ combFilter.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ combFilter.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertAudibleValues(buffer);
+}
+
+test("Damped Comb Filter", testDampedCombFilter);
View
@@ -0,0 +1,41 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testDelay() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var delay = new Delay(audiolet, 1, 1);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(delay);
+ delay.connect(recorder);
+
+ // Should output silence for the first second
+ for (var i=0; i<audiolet.device.sampleRate; i++) {
+ sine.tick();
+ delay.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, 0, 0);
+
+ // After the first second it should output the sine wave
+ recorder.reset();
+ for (var i=0; i<audiolet.device.sampleRate; i++) {
+ sine.tick();
+ delay.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer);
+ Assert.assertValuesReach(buffer, -0.9, 0.9);
+ Assert.assertContinuous(buffer);
+}
+
+test("Delay", testDelay);
@@ -0,0 +1,31 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testDiscontinuityDetector() {
+ var detected = false
+ var audiolet = new Audiolet();
+ var source = new AudioletNode(audiolet, 0, 1);
+ var dd = new DiscontinuityDetector(audiolet, 0.1, function() {
+ detected = true;
+ });
+
+ source.connect(dd);
+
+ // Continuous
+ source.outputs[0].samples = [0];
+ dd.tick();
+ source.outputs[0].samples = [0.1];
+ dd.tick();
+ source.outputs[0].samples = [0.15];
+ dd.tick();
+ Assert.assertFalse(detected, "Continuous undetected");
+
+ // Discontinuous
+ source.outputs[0].samples = [0.35];
+ dd.tick();
+ Assert.assertTrue(detected, "Discontinuous detected");
+}
+
+test("Discontinuity Detector", testDiscontinuityDetector);
View
@@ -0,0 +1,41 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testFeedbackDelay() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var delay = new FeedbackDelay(audiolet, 1, 1);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(delay);
+ delay.connect(recorder);
+
+ // Should output silence for the first second
+ for (var i=0; i<audiolet.device.sampleRate; i++) {
+ sine.tick();
+ delay.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, 0, 0);
+
+ // After the first second it should output the sine wave
+ recorder.reset();
+ for (var i=0; i<audiolet.device.sampleRate; i++) {
+ sine.tick();
+ delay.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer);
+ Assert.assertValuesReach(buffer, -0.9, 0.9);
+ Assert.assertContinuous(buffer);
+}
+
+test("Feedback Delay", testFeedbackDelay);
View
@@ -0,0 +1,28 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testGain() {
+ var audiolet = new Audiolet();
+ var sine = new Sine(audiolet);
+ var gain = new Gain(audiolet, 2);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ sine.connect(gain);
+ gain.connect(recorder);
+
+ for (var i=0; i<81920; i++) {
+ sine.tick();
+ gain.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer, 0.2);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, -2, 2);
+ Assert.assertValuesReach(buffer, -1.9, 1.9);
+}
+
+test("Gain", testGain);
View
@@ -0,0 +1,35 @@
+load('../../../../audiotest.js/trunk/audiotest.js');
+load('../../src/audiofile/audiofile.js');
+load('../../src/audiolet/Audiolet.js');
+load('../Environment.js');
+
+function testLag() {
+ var audiolet = new Audiolet();
+ var lag = new Lag(audiolet, 5);
+ var recorder = new InputRecorder(audiolet, 1);
+
+ lag.connect(recorder);
+
+ // Check that we move continuously from 5 to 0
+ lag.value.setValue(0);
+ for (var i=0; i<audiolet.device.sampleRate; i++) {
+ lag.tick();
+ recorder.tick();
+ }
+
+ var buffer = recorder.buffers[0][0];
+ Assert.assertContinuous(buffer);
+ Assert.assertAudibleValues(buffer);
+ Assert.assertValuesInRange(buffer, 0, 5);
+
+ // Check that the lag has almost reached 0
+ recorder.reset();
+ for (var i=0; i<audiolet.device.sampleRate; i++) {
+ lag.tick();
+ recorder.tick();
+ }
+ var buffer = recorder.buffers[0][0];
+ Assert.assertValuesInRange(buffer, 0, 0.01);
+};
+
+test("Lag", testLag);

0 comments on commit 039cc5d

Please sign in to comment.