-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-audio.js
More file actions
71 lines (55 loc) · 2.06 KB
/
Copy pathtest-audio.js
File metadata and controls
71 lines (55 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import puppeteer from 'puppeteer';
(async () => {
const browser = await puppeteer.launch({ headless: "new" });
const page = await browser.newPage();
page.on('console', msg => {
console.log(`[Browser Console] ${msg.text()}`);
});
try {
await page.goto('http://localhost:5173/dsp-test.html', { waitUntil: 'networkidle0' });
// We have dsp-test.html. Let's see if it works.
await page.evaluate(async () => {
// Create audio context
const ctx = new AudioContext();
await ctx.audioWorklet.addModule('/worklets/track-processor.bundle.js');
const node = new AudioWorkletNode(ctx, 'track-processor', {
numberOfInputs: 0,
numberOfOutputs: 1,
outputChannelCount: [2]
});
node.port.postMessage({ type: 'INIT_WASM' });
await new Promise(r => setTimeout(r, 500));
// Load a static buffer
const left = new Float32Array(44100);
const right = new Float32Array(44100);
for(let i=0; i<44100; i++) { left[i] = 1.0; right[i] = 1.0; } // DC offset
node.port.postMessage({
type: 'LOAD_TRACK_FULL',
leftChannel: left,
rightChannel: right,
bufferLength: 44100,
trackSampleRate: 44100
});
node.port.postMessage({ type: 'PLAY' });
// analyze output
const analyzer = ctx.createAnalyser();
node.connect(analyzer);
analyzer.connect(ctx.destination);
await ctx.resume();
await new Promise(r => setTimeout(r, 500));
const data = new Float32Array(analyzer.fftSize);
analyzer.getFloatTimeDomainData(data);
let hasAudio = false;
for(let i=0; i<data.length; i++) {
if(Math.abs(data[i]) > 0.01) { hasAudio = true; break; }
}
console.log("TEST RESULT HAS AUDIO: " + hasAudio);
console.log("FIRST SAMPLES: " + data[0] + ", " + data[1] + ", " + data[2]);
});
await new Promise(r => setTimeout(r, 2000));
} catch (e) {
console.error(e);
} finally {
await browser.close();
}
})();