OLD | NEW |
---|---|
(Empty) | |
1 <html> | |
2 <head> | |
3 <title>Audio Loop Benchmark</title> | |
4 <style>* { font-family: monospace; }</style> | |
5 </head> | |
6 <body> | |
7 <h1>Audio Loop Benchmark</h1> | |
8 <p> | |
9 Benchmark measuring how fast we can continuously repeat a short sound | |
10 clip. In the ideal scenario we'd have zero latency processing script, | |
11 seeking back to the beginning of the clip, and resuming audio playback. | |
12 </p> | |
13 <p> | |
14 Using the loop attribute will avoid involving script to seek back to the | |
15 beginning of the clip, but testing reveals it isn't adding to latency. | |
16 </p> | |
17 | |
18 <input id="loop" type="checkbox" />Use loop attribute | |
19 <button onclick="startTest(document.getElementById('loop').checked);">Start< /button> | |
20 | |
21 <p> | |
22 Times Played: <span id="times"></span></span><br> | |
23 Clip Duration: <span id="clip"></span></span><br> | |
24 Ideal Duration: <span id="ideal"></span><br> | |
25 Actual Duration: <span id="actual"></span><br> | |
26 </p> | |
27 | |
28 <script> | |
29 var TIMES = 50, loopCount = 0, idealDuration = -1, actualDuration = -1; | |
30 | |
31 function getAndClearElement(id) { | |
32 var elem = document.getElementById(id); | |
33 elem.innerText = ''; | |
34 return elem; | |
35 } | |
36 | |
37 function startTest(use_loop) { | |
38 var timesElem = getAndClearElement('times'); | |
39 var clipElem = getAndClearElement('clip'); | |
40 var idealElem = getAndClearElement('ideal'); | |
41 var actualElem = getAndClearElement('actual'); | |
42 var buttonElem = document.querySelector('button'); | |
43 | |
44 loopCount = 0; | |
45 var startTime; | |
46 | |
47 buttonElem.disabled = true; | |
48 | |
49 function onLoaded() { | |
50 idealDuration = Math.round(audio.duration * TIMES * 1000, 0); | |
51 idealElem.innerText = idealDuration + ' ms'; | |
52 clipElem.innerText = Math.round(audio.duration * 1000, 0) + ' ms'; | |
53 | |
54 if (use_loop) { | |
55 audio.addEventListener('seeked', onLoop); | |
56 audio.loop = true; | |
57 } else { | |
58 audio.addEventListener('ended', onEnded); | |
59 audio.addEventListener('seeked', onSeeked); | |
60 } | |
61 startTime = new Date(); | |
62 audio.play(); | |
63 } | |
64 | |
65 var audio = document.createElement('audio'); | |
66 audio.addEventListener('canplaythrough', onLoaded); | |
67 audio.src = "../pink_noise_140ms.wav"; | |
68 | |
69 function onEnded() { | |
70 ++loopCount; | |
71 timesElem.innerText = loopCount + '/' + TIMES; | |
72 if (loopCount == TIMES) { | |
73 actualDuration = new Date() - startTime; | |
74 actualElem.innerText = actualDuration + ' ms'; | |
75 buttonElem.disabled = false; | |
76 | |
77 // Let the PyAuto test know we're done testing. | |
78 if (window.domAutomationController) | |
79 window.domAutomationController.send(true); | |
80 return; | |
81 } | |
82 | |
83 audio.currentTime = 0; | |
84 } | |
85 | |
86 function onSeeked() { | |
87 audio.play(); | |
88 } | |
89 | |
90 function onLoop() { | |
91 ++loopCount; | |
92 timesElem.innerText = loopCount + '/' + TIMES; | |
93 if (loopCount == TIMES) { | |
94 audio.pause(); | |
95 actualDuration = new Date() - startTime; | |
96 actualElem.innerText = actualDuration + ' ms'; | |
97 buttonElem.disabled = false; | |
98 | |
99 // Let the PyAuto test know we're done testing. | |
100 if (window.domAutomationController) | |
101 window.domAutomationController.send(true); | |
102 return; | |
103 } | |
shadi
2012/05/17 22:03:37
It seems this code is tha same as onEnded except l
DaleCurtis
2012/05/18 00:23:36
Done.
| |
104 } | |
105 } | |
106 </script> | |
107 </body> | |
108 </html> | |
OLD | NEW |