-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: use offlineaudiocontext for dataset testing
- Loading branch information
Showing
1 changed file
with
4 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |