4 <title>Audio Loop Benchmark
</title>
5 <style>* { font-family: monospace; }
</style>
8 <h1>Audio Loop Benchmark
</h1>
10 Benchmark measuring how fast we can continuously repeat a short sound
11 clip. In the ideal scenario we'd have zero latency processing script,
12 seeking back to the beginning of the clip, and resuming audio playback.
15 <button onclick=
"startTest();">Start
</button>
18 Times Played:
<span id=
"times"></span></span><br>
19 Clip Duration:
<span id=
"clip"></span></span><br>
20 Ideal Duration:
<span id=
"ideal"></span><br>
21 Actual Duration:
<span id=
"actual"></span><br>
22 Average Latency:
<span id=
"average"></span><br>
26 var TIMES
= 50, averageLatency
= 0;
28 function getAndClearElement(id
) {
29 var elem
= document
.getElementById(id
);
34 function startTest() {
35 var timesElem
= getAndClearElement('times');
36 var clipElem
= getAndClearElement('clip');
37 var idealElem
= getAndClearElement('ideal');
38 var actualElem
= getAndClearElement('actual');
39 var averageElem
= getAndClearElement('average');
40 var buttonElem
= document
.querySelector('button');
42 var loopCount
= 0, idealDuration
= 0, actualDuration
= 0;
45 buttonElem
.disabled
= true;
48 idealDuration
= Math
.round(audio
.duration
* TIMES
* 1000, 0);
49 idealElem
.innerText
= idealDuration
+ ' ms';
50 clipElem
.innerText
= Math
.round(audio
.duration
* 1000, 0) + ' ms';
51 audio
.addEventListener('seeked', onLoop
);
52 startTime
= window
.performance
.now();
56 var audio
= document
.createElement('audio');
57 audio
.addEventListener('canplaythrough', onLoaded
);
59 audio
.src
= '../pink_noise_140ms.wav';
63 timesElem
.innerText
= loopCount
+ '/' + TIMES
;
64 if (loopCount
== TIMES
) {
65 actualDuration
= window
.performance
.now() - startTime
;
66 actualElem
.innerText
= actualDuration
+ ' ms';
67 buttonElem
.disabled
= false;
69 averageLatency
= (actualDuration
- idealDuration
) / loopCount
;
70 averageElem
.innerText
= averageLatency
+ ' ms';
72 // Let the PyAuto test know we're done testing.
73 if (window
.domAutomationController
)
74 window
.domAutomationController
.send(true);