Skip to content

Commit de6b6e5

Browse files
committed
Adding David Humphrey's unit tests and test harness
1 parent 0acac23 commit de6b6e5

13 files changed

+876
-2
lines changed

dsp.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ DFT.prototype.forward = function(buffer) {
192192
imag = 0.0;
193193

194194
for ( var n = 0; n < buffer.length; n++ ) {
195-
real += this.cosTable[k*n] * signal[n];
196-
imag += this.sinTable[k*n] * signal[n];
195+
real += this.cosTable[k*n] * buffer[n];
196+
imag += this.sinTable[k*n] * buffer[n];
197197
}
198198

199199
this.complexValues[k] = {real: real, imag: imag};

test/adsr-test.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
load('audio-harness.js');
2+
load('dsp.js');
3+
4+
var iterations = 1000;
5+
6+
var envelope = new ADSR(0.01, 0.1, 0.5, 0.1, 0.2, 44100);
7+
8+
var calcADSR = function() {
9+
var fb = getFramebuffer(),
10+
signal = DSP.getChannel(DSP.MIX, fb);
11+
12+
envelope.process(signal);
13+
};
14+
15+
runTest(calcADSR, iterations);

test/audio-harness.js

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
load('samples.js');
2+
3+
var startTime,
4+
totalTime;
5+
6+
function calcTime() {
7+
totalTime = (new Date()).getTime() - startTime;
8+
}
9+
10+
function printResults(iterations) {
11+
print('Total Time: ' + totalTime + 'ms for ' + iterations + ' iterations, ' +
12+
(totalTime / iterations) + 'ms per iteration.');
13+
}
14+
15+
function runTest(test, iterations) {
16+
startTime = new Date().getTime();
17+
for (var i = 0; i < iterations; i++) {
18+
test();
19+
}
20+
calcTime();
21+
printResults(iterations)
22+
}

test/beatdetect-test.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
load('audio-harness.js');
2+
load('dsp.js');
3+
load('beatdetektor.js');
4+
5+
var iterations = 1000;
6+
7+
var fft = fft = new FFT(frameBufferLength / channels, rate);
8+
var bd = new BeatDetektor();
9+
var kick_det = new BeatDetektor.modules.vis.BassKick();
10+
var vu = new BeatDetektor.modules.vis.VU();
11+
12+
var m_BeatTimer = 0;
13+
var m_BeatCounter = 0;
14+
var ftimer = 0;
15+
16+
var calcBeat = function() {
17+
var fb = getFramebuffer(),
18+
signal = DSP.getChannel(DSP.MIX, fb);
19+
20+
fft.forward(signal);
21+
22+
var timestamp = (new Date()).getTime();
23+
bd.process(timestamp, fft.spectrum);
24+
25+
// Bass Kick detection
26+
kick_det.process(bd);
27+
vu.process(bd);
28+
};
29+
30+
runTest(calcBeat, iterations);

0 commit comments

Comments
 (0)