| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/js-test.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> |
| 5 <script src="../resources/compatibility.js"></script> | 6 <script src="../resources/compatibility.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audio-testing.js"></script> |
| 8 <title>Test AnalyserNode getFloatTimeDomainData</title> | 9 <title>Test AnalyserNode getFloatTimeDomainData</title> |
| 9 </head> | 10 </head> |
| 10 | 11 |
| 11 <body> | 12 <body> |
| 12 <script> | 13 <script> |
| 13 description("Test AnalyserNode getFloatTimeDomainData"); | |
| 14 window.jsTestIsAsync = true; | |
| 15 | |
| 16 // Use a power of two to eliminate any round-off in the computation of the
times for | 14 // Use a power of two to eliminate any round-off in the computation of the
times for |
| 17 // context.suspend(). | 15 // context.suspend(). |
| 18 var sampleRate = 32768; | 16 var sampleRate = 32768; |
| 19 | 17 |
| 20 // The largest FFT size for the analyser node is 32768. We want to render
longer than this so | 18 // The largest FFT size for the analyser node is 32768. We want to render
longer than this so |
| 21 // that we have at least one complete buffer of data of 32768 samples. | 19 // that we have at least one complete buffer of data of 32768 samples. |
| 22 var renderFrames = 2 * 32768; | 20 var renderFrames = 2 * 32768; |
| 23 var renderDuration = renderFrames / sampleRate; | 21 var renderDuration = renderFrames / sampleRate; |
| 24 | 22 |
| 25 var audit = Audit.createTaskRunner(); | 23 var audit = Audit.createTaskRunner(); |
| 26 | 24 |
| 27 // Test that getFloatTimeDomainData handles short and long vectors correct
ly. | 25 // Test that getFloatTimeDomainData handles short and long vectors correct
ly. |
| 28 audit.defineTask("short and long vector", function (done) { | 26 audit.defineTask("short and long vector", function (done) { |
| 29 var fftSize = 32; | 27 var fftSize = 32; |
| 30 var graphInfo = createGraph(fftSize); | 28 var graphInfo = createGraph(fftSize); |
| 31 var context = graphInfo.context; | 29 var context = graphInfo.context; |
| 32 var analyser = graphInfo.analyser; | 30 var analyser = graphInfo.analyser; |
| 33 var signalBuffer = graphInfo.signalBuffer; | 31 var signalBuffer = graphInfo.signalBuffer; |
| 34 var signal = signalBuffer.getChannelData(0); | 32 var signal = signalBuffer.getChannelData(0); |
| 35 | 33 |
| 36 var success = true; | 34 var success = true; |
| 37 var sampleFrame = 128; | 35 var sampleFrame = 128; |
| 38 | 36 |
| 39 context.suspend(sampleFrame / sampleRate).then(function () { | 37 context.suspend(sampleFrame / sampleRate).then(function () { |
| 40 var shortData = new Float32Array(8); | 38 var shortData = new Float32Array(8); |
| 41 // Initialize the array to Infinity to represent uninitialize data. | 39 // Initialize the array to Infinity to represent uninitialize data. |
| 42 shortData.fill(Infinity); | 40 shortData.fill(Infinity); |
| 43 testPassed(shortData.length + "-element short array initialized to Inf
inity."); | |
| 44 | 41 |
| 45 analyser.getFloatTimeDomainData(shortData); | 42 analyser.getFloatTimeDomainData(shortData); |
| 46 testPassed("getFloatTimeDomainData(<" + shortData.length + "-element v
ector>)."); | |
| 47 | 43 |
| 48 // The short array should be filled with the expected data, with no er
rors thrown. | 44 // The short array should be filled with the expected data, with no er
rors thrown. |
| 49 | 45 |
| 50 var expected = signal.subarray(sampleFrame - fftSize, sampleFrame); | 46 var expected = signal.subarray(sampleFrame - fftSize, sampleFrame); |
| 51 success = Should(shortData.length + "-element time domain data", short
Data) | 47 success = Should(shortData.length + "-element time domain data", short
Data) |
| 52 .beEqualToArray(expected.subarray(0, shortData.length)) && success; | 48 .beEqualToArray(expected.subarray(0, shortData.length)) && success; |
| 53 | 49 |
| 54 var longData = new Float32Array(2 * fftSize); | 50 var longData = new Float32Array(2 * fftSize); |
| 55 // Initialize the array to Infinity to represent uninitialize data. | 51 // Initialize the array to Infinity to represent uninitialize data. |
| 56 longData.fill(Infinity); | 52 longData.fill(Infinity); |
| 57 testPassed(longData.length + "-element long array initialized to Infin
ity."); | |
| 58 | 53 |
| 59 analyser.getFloatTimeDomainData(longData); | 54 analyser.getFloatTimeDomainData(longData); |
| 60 testPassed("getFloatTimeDomainData(<" + longData.length + "-element ve
ctor>)."); | |
| 61 | 55 |
| 62 // The long array should filled with the expected data but the extra e
lements should be | 56 // The long array should filled with the expected data but the extra e
lements should be |
| 63 // untouched. | 57 // untouched. |
| 64 success = Should("longData.subarray(0, " + fftSize + ")", | 58 success = Should("longData.subarray(0, " + fftSize + ")", |
| 65 longData.subarray(0, fftSize), { | 59 longData.subarray(0, fftSize), { |
| 66 numberOfArrayLog: 32 | 60 numberOfArrayLog: 32 |
| 67 }) | 61 }) |
| 68 .beEqualToArray(expected) && success; | 62 .beEqualToArray(expected) && success; |
| 69 | 63 |
| 70 success = Should("Unfilled elements longData.subarray(" + fftSize + ")
", | 64 success = Should("Unfilled elements longData.subarray(" + fftSize + ")
", |
| 71 longData.subarray(fftSize)) | 65 longData.subarray(fftSize)) |
| 72 .beConstantValueOf(Infinity) && success; | 66 .beConstantValueOf(Infinity) && success; |
| 73 }).then(context.resume.bind(context)); | 67 }).then(context.resume.bind(context)); |
| 74 | 68 |
| 75 context.startRendering().then(function (buffer) { | 69 context.startRendering().then(function (buffer) { |
| 76 if (success) | 70 Should("Long and short time domain arrays handled", success) |
| 77 testPassed("Long and short time domain arrays handled correctly.\n")
; | 71 .summarize("correctly.", "incorrectly."); |
| 78 else | |
| 79 testFailed("Long and short time domain arrays handled incorrectly.\n
"); | |
| 80 }).then(done); | 72 }).then(done); |
| 81 }); | 73 }); |
| 82 | 74 |
| 83 var success = true; | 75 var success = true; |
| 84 | 76 |
| 85 // Generate tests for all valid FFT sizes for an AnalyserNode. | 77 // Generate tests for all valid FFT sizes for an AnalyserNode. |
| 86 for (var k = 5; k < 16; ++k) { | 78 for (var k = 5; k < 16; ++k) { |
| 87 var fftSize = Math.pow(2, k); | 79 var fftSize = Math.pow(2, k); |
| 88 (function (n) { | 80 (function (n) { |
| 89 // We grab a sample at (roughly) half the rendering duration. | 81 // We grab a sample at (roughly) half the rendering duration. |
| 90 audit.defineTask("fftSize " + n, function (done) { | 82 audit.defineTask("fftSize " + n, function (done) { |
| 91 runTest(n, renderDuration / 2).then(done); | 83 runTest(n, renderDuration / 2).then(done); |
| 92 }); | 84 }); |
| 93 })(fftSize); | 85 })(fftSize); |
| 94 } | 86 } |
| 95 | 87 |
| 96 audit.defineTask("summarize size tests", function (done) { | 88 audit.defineTask("summarize size tests", function (done) { |
| 97 if (success) | 89 Should("Time domain data", success) |
| 98 testPassed("Time domain data contained the correct data for each size.
\n"); | 90 .summarize("contained the correct data for each size.", |
| 99 else | 91 "did not contain the correct data for each size."); |
| 100 testFailed("Time domain data did not contain the correct data for each
size.\n"); | |
| 101 | 92 |
| 102 done(); | 93 done(); |
| 103 }); | 94 }); |
| 104 | 95 |
| 105 // Special case for a large size, but the sampling point is early. The in
itial part of the | 96 // Special case for a large size, but the sampling point is early. The in
itial part of the |
| 106 // buffer should be filled with zeroes. | 97 // buffer should be filled with zeroes. |
| 107 | 98 |
| 108 audit.defineTask("initial zeroes", function (done) { | 99 audit.defineTask("initial zeroes", function (done) { |
| 109 // Somewhat arbitrary size for the analyser. It should be greater than
one rendering | 100 // Somewhat arbitrary size for the analyser. It should be greater than
one rendering |
| 110 // quantum. | 101 // quantum. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 132 } | 123 } |
| 133 | 124 |
| 134 var signal = signalBuffer.getChannelData(0); | 125 var signal = signalBuffer.getChannelData(0); |
| 135 success = Should(prefix + "(" + (fftSize - sampleFrame) + ", " + fft
Size + ")", | 126 success = Should(prefix + "(" + (fftSize - sampleFrame) + ", " + fft
Size + ")", |
| 136 data.subarray(fftSize - sampleFrame, fftSize)) | 127 data.subarray(fftSize - sampleFrame, fftSize)) |
| 137 .beEqualToArray(signal.subarray(0, sampleFrame)) && success; | 128 .beEqualToArray(signal.subarray(0, sampleFrame)) && success; |
| 138 }).then(context.resume.bind(context)); | 129 }).then(context.resume.bind(context)); |
| 139 } | 130 } |
| 140 | 131 |
| 141 context.startRendering().then(function (b) { | 132 context.startRendering().then(function (b) { |
| 142 if (success) { | 133 Should("Time domain data", success) |
| 143 testPassed( | 134 .summarize( |
| 144 "Time domain data contained initial zeroes and correct data as exp
ected.\n"); | 135 "contained initial zeroes and correct data as expected", |
| 145 } else { | 136 "did not contain initial zeroes and correct data as expected."); |
| 146 testFailed( | |
| 147 "Time domain data did not contain initial zeroes and correct data
as expected.\n" | |
| 148 ); | |
| 149 } | |
| 150 | |
| 151 }).then(done); | 137 }).then(done); |
| 152 }); | 138 }); |
| 153 | 139 |
| 154 audit.defineTask("finish", function (done) { | 140 audit.defineTask("finish", function (done) { |
| 155 finishJSTest(); | |
| 156 done(); | 141 done(); |
| 157 }); | 142 }); |
| 158 | 143 |
| 159 audit.runTasks(); | 144 audit.runTasks(); |
| 160 | 145 |
| 161 // Run test of an AnalyserNode with fftSize of |fftSize|, and with the dat
a from the node | 146 // Run test of an AnalyserNode with fftSize of |fftSize|, and with the dat
a from the node |
| 162 // being requested at time |sampletime|. The result from the analyser nod
e is compared | 147 // being requested at time |sampletime|. The result from the analyser nod
e is compared |
| 163 // against the expected data. The result of startRendering() is returned. | 148 // against the expected data. The result of startRendering() is returned. |
| 164 function runTest(fftSize, sampleTime) { | 149 function runTest(fftSize, sampleTime) { |
| 165 var graphInfo = createGraph(fftSize); | 150 var graphInfo = createGraph(fftSize); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 | 197 |
| 213 return { | 198 return { |
| 214 context: context, | 199 context: context, |
| 215 analyser: analyser, | 200 analyser: analyser, |
| 216 signalBuffer: signalBuffer | 201 signalBuffer: signalBuffer |
| 217 }; | 202 }; |
| 218 } | 203 } |
| 219 </script> | 204 </script> |
| 220 </body> | 205 </body> |
| 221 </html> | 206 </html> |
| OLD | NEW |