Skip to content

Commit

Permalink
chore: use offlineaudiocontext for dataset testing
Browse files Browse the repository at this point in the history
  • Loading branch information
dlepaux committed Jan 28, 2024
1 parent 966498a commit d487267
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions testing/index.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
import {analyzeFullBuffer} from '../src/analyzer';

async function runTests() {
const audioContext = new AudioContext();
const response = await fetch('http://localhost:9876/base/tests/datasets/manifest.json');
const audioContext = new OfflineAudioContext(2, 44100 * 40, 44100);
const response = await fetch('/tests/datasets/manifest.json');
const json: Record<string, number> = await response.json(); // eslint-disable-line @typescript-eslint/no-unsafe-assignment
for (const fileName of Object.keys(json)) {
const bpm = json[fileName];
const response = await fetch(`http://localhost:9876/base/tests/datasets/${fileName}`);
const response = await fetch(`/tests/datasets/${fileName}`);
const buffer = await response.arrayBuffer();
const audioBuffer = await audioContext.decodeAudioData(buffer);
const tempo = await analyzeFullBuffer(audioBuffer);
// Console.assert(tempo[0].tempo === bpm, 'The computed tempo is not matching');
console.assert(tempo[0].tempo === bpm, 'The computed tempo is not matching');
}

await audioContext.close();
}

runTests(); // eslint-disable-line @typescript-eslint/no-floating-promises

0 comments on commit d487267

Please sign in to comment.