| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../resources/testharness.js"></script> | 4 <script src="../../resources/testharness.js"></script> |
| 5 <script src="../../resources/testharnessreport.js"></script> | 5 <script src="../../resources/testharnessreport.js"></script> |
| 6 <script src="../resources/audit-util.js"></script> | 6 <script src="../resources/audit-util.js"></script> |
| 7 <script src="../resources/audio-testing.js"></script> | 7 <script src="../resources/audit.js"></script> |
| 8 <script src="../resources/realtimeanalyser-testing.js"></script> | 8 <script src="../resources/realtimeanalyser-testing.js"></script> |
| 9 <script src="../resources/fft.js"></script> | 9 <script src="../resources/fft.js"></script> |
| 10 <title>Test Analyser getFloatFrequencyData and getByteFrequencyData, No Smoo
thing</title> | 10 <title>Test Analyser getFloatFrequencyData and getByteFrequencyData, No Smoo
thing</title> |
| 11 </head> | 11 </head> |
| 12 | 12 |
| 13 <body> | 13 <body> |
| 14 <script> | 14 <script> |
| 15 // Use a power of two to eliminate any round-off in the computation of the
times for | 15 // Use a power of two to eliminate any round-off in the computation of the
times for |
| 16 // context.suspend(). | 16 // context.suspend(). |
| 17 var sampleRate = 32768; | 17 var sampleRate = 32768; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 floatRelError: 1.1756e-7 | 64 floatRelError: 1.1756e-7 |
| 65 }]; | 65 }]; |
| 66 | 66 |
| 67 // True if all of the basic tests passed. | 67 // True if all of the basic tests passed. |
| 68 var basicTestsPassed = true; | 68 var basicTestsPassed = true; |
| 69 | 69 |
| 70 // Generate tests for each entry in testConfig. | 70 // Generate tests for each entry in testConfig. |
| 71 for (var k = 0; k < testConfig.length; ++k) { | 71 for (var k = 0; k < testConfig.length; ++k) { |
| 72 var name = testConfig[k].order + "-order FFT"; | 72 var name = testConfig[k].order + "-order FFT"; |
| 73 (function (config) { | 73 (function (config) { |
| 74 audit.defineTask(name, function (done) { | 74 audit.define(name, (task, should) => { |
| 75 basicFFTTest(config).then(done); | 75 basicFFTTest(should, config).then(() => task.done()); |
| 76 }); | 76 }); |
| 77 })(testConfig[k]); | 77 })(testConfig[k]); |
| 78 } | 78 } |
| 79 | 79 |
| 80 // Just print a summary of the result of the above tests. | |
| 81 audit.defineTask("summarize basic tests", function (done) { | |
| 82 Should("Basic frequency data computed", basicTestsPassed) | |
| 83 .summarize("correctly", "incorrectly"); | |
| 84 done(); | |
| 85 }); | |
| 86 | |
| 87 // Test that smoothing isn't done and we have the expected data, calling g
etFloatFrequencyData | 80 // Test that smoothing isn't done and we have the expected data, calling g
etFloatFrequencyData |
| 88 // twice at different times. | 81 // twice at different times. |
| 89 audit.defineTask("no smoothing", function (done) { | 82 audit.define("no smoothing", (task, should) => { |
| 90 // Use 128-point FFT for the test. The actual order doesn't matter (but
the error threshold | 83 // Use 128-point FFT for the test. The actual order doesn't matter (but
the error threshold |
| 91 // depends on the order). | 84 // depends on the order). |
| 92 var options = { | 85 var options = { |
| 93 order: 7, | 86 order: 7, |
| 94 smoothing: 0, | 87 smoothing: 0, |
| 95 floatRelError: 1.2548e-6 | 88 floatRelError: 1.2548e-6 |
| 96 }; | 89 }; |
| 97 var graph = createGraph(options); | 90 var graph = createGraph(options); |
| 98 var context = graph.context; | 91 var context = graph.context; |
| 99 var analyser = graph.analyser; | 92 var analyser = graph.analyser; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 117 context.suspend(suspendFrame / sampleRate).then(function () { | 110 context.suspend(suspendFrame / sampleRate).then(function () { |
| 118 var timeData = new Float32Array(analyser.fftSize); | 111 var timeData = new Float32Array(analyser.fftSize); |
| 119 var freqData = new Float32Array(analyser.frequencyBinCount); | 112 var freqData = new Float32Array(analyser.frequencyBinCount); |
| 120 | 113 |
| 121 // Grab the time domain and frequency domain data | 114 // Grab the time domain and frequency domain data |
| 122 analyser.getFloatTimeDomainData(timeData); | 115 analyser.getFloatTimeDomainData(timeData); |
| 123 analyser.getFloatFrequencyData(freqData); | 116 analyser.getFloatFrequencyData(freqData); |
| 124 | 117 |
| 125 var expected = computeFFTMagnitude(timeData, options.order).map(linear
ToDb); | 118 var expected = computeFFTMagnitude(timeData, options.order).map(linear
ToDb); |
| 126 var comparison = compareFloatFreq(Math.pow(2, options.order) + "-point
float FFT", | 119 var comparison = compareFloatFreq(Math.pow(2, options.order) + "-point
float FFT", |
| 127 freqData, expected, options); | 120 freqData, expected, should, options); |
| 128 basicTestsPassed = basicTestsPassed && comparison.success; | 121 basicTestsPassed = basicTestsPassed && comparison.success; |
| 129 | |
| 130 Should("Smoothing constant of 0", comparison.success) | |
| 131 .summarize("correctly handled", "incorrectly handled"); | |
| 132 }).then(context.resume.bind(context)); | 122 }).then(context.resume.bind(context)); |
| 133 | 123 |
| 134 context.startRendering().then(done); | 124 context.startRendering().then(() => task.done()); |
| 135 }); | 125 }); |
| 136 | 126 |
| 137 audit.defineTask("finish", function (done) { | 127 audit.run(); |
| 138 done(); | |
| 139 }); | |
| 140 | |
| 141 audit.runTasks(); | |
| 142 | 128 |
| 143 // Run a simple test of the AnalyserNode's frequency domain data. Both th
e float and byte | 129 // Run a simple test of the AnalyserNode's frequency domain data. Both th
e float and byte |
| 144 // frequency data are tested. The byte tests depend on the float tests be
ing correct. | 130 // frequency data are tested. The byte tests depend on the float tests be
ing correct. |
| 145 // | 131 // |
| 146 // The parameters of the test are given by |options| which is a property b
ag consisting of the | 132 // The parameters of the test are given by |options| which is a property b
ag consisting of the |
| 147 // following: | 133 // following: |
| 148 // | 134 // |
| 149 // order: Order of the FFT to test. | 135 // order: Order of the FFT to test. |
| 150 // smoothing: smoothing time constant for the analyser. | 136 // smoothing: smoothing time constant for the analyser. |
| 151 // minDecibels: min decibels value for the analyser. | 137 // minDecibels: min decibels value for the analyser. |
| 152 // floatRelError: max allowed relative error for the float FFT data | 138 // floatRelError: max allowed relative error for the float FFT data |
| 153 function basicFFTTest(options) { | 139 function basicFFTTest(should, options) { |
| 154 var graph = createGraph(options); | 140 var graph = createGraph(options); |
| 155 var context = graph.context; | 141 var context = graph.context; |
| 156 var analyser = graph.analyser; | 142 var analyser = graph.analyser; |
| 157 | 143 |
| 158 var suspendTime = Math.max(128, analyser.fftSize) / sampleRate; | 144 var suspendTime = Math.max(128, analyser.fftSize) / sampleRate; |
| 159 context.suspend(suspendTime).then(function () { | 145 context.suspend(suspendTime).then(function () { |
| 160 var timeData = new Float32Array(analyser.fftSize); | 146 var timeData = new Float32Array(analyser.fftSize); |
| 161 var freqData = new Float32Array(analyser.frequencyBinCount); | 147 var freqData = new Float32Array(analyser.frequencyBinCount); |
| 162 | 148 |
| 163 // Grab the time domain and frequency domain data | 149 // Grab the time domain and frequency domain data |
| 164 analyser.getFloatTimeDomainData(timeData); | 150 analyser.getFloatTimeDomainData(timeData); |
| 165 analyser.getFloatFrequencyData(freqData); | 151 analyser.getFloatFrequencyData(freqData); |
| 166 | 152 |
| 167 var expected = computeFFTMagnitude(timeData, options.order).map(linear
ToDb); | 153 var expected = computeFFTMagnitude(timeData, options.order).map(linear
ToDb); |
| 168 var comparison = compareFloatFreq(Math.pow(2, options.order) + "-point
float FFT", | 154 var comparison = compareFloatFreq(Math.pow(2, options.order) + "-point
float FFT", |
| 169 freqData, expected, options); | 155 freqData, expected, should, options); |
| 170 basicTestsPassed = basicTestsPassed && comparison.success; | 156 basicTestsPassed = basicTestsPassed && comparison.success; |
| 171 var expected = comparison.expected; | 157 var expected = comparison.expected; |
| 172 | 158 |
| 173 // For the byte test to be better, check that there are some samples t
hat are outside the | 159 // For the byte test to be better, check that there are some samples t
hat are outside the |
| 174 // range of minDecibels and maxDecibels. If there aren't the test sho
uld update the | 160 // range of minDecibels and maxDecibels. If there aren't the test sho
uld update the |
| 175 // minDecibels and maxDecibels values for the analyser. | 161 // minDecibels and maxDecibels values for the analyser. |
| 176 | 162 |
| 177 var minValue = Math.min(...expected); | 163 var minValue = Math.min(...expected); |
| 178 var maxValue = Math.max(...expected); | 164 var maxValue = Math.max(...expected); |
| 179 | 165 |
| 180 basicTestsPassed = Should("Order: " + options.order + | 166 should(minValue, "Order: " + options.order + |
| 181 ": Min FFT value", minValue, { | 167 ": Min FFT value") |
| 182 brief: true | 168 .beLessThanOrEqualTo(analyser.minDecibels); |
| 183 }) | 169 should(maxValue, "Order: " + options.order + |
| 184 .beLessThanOrEqualTo(analyser.minDecibels) && basicTestsPassed; | 170 ": Max FFT value") |
| 185 basicTestsPassed = Should("Order: " + options.order + | 171 .beGreaterThanOrEqualTo(analyser.maxDecibels); |
| 186 ": Max FFT value", maxValue, { | |
| 187 brief: true | |
| 188 }) | |
| 189 .beGreaterThanOrEqualTo(analyser.maxDecibels) && basicTestsPassed; | |
| 190 // Test the byte frequency data. | 172 // Test the byte frequency data. |
| 191 var byteFreqData = new Uint8Array(analyser.frequencyBinCount); | 173 var byteFreqData = new Uint8Array(analyser.frequencyBinCount); |
| 192 var expectedByteData = new Float32Array(analyser.frequencyBinCount); | 174 var expectedByteData = new Float32Array(analyser.frequencyBinCount); |
| 193 analyser.getByteFrequencyData(byteFreqData); | 175 analyser.getByteFrequencyData(byteFreqData); |
| 194 | 176 |
| 195 // Convert the expected float frequency data to byte data. | 177 // Convert the expected float frequency data to byte data. |
| 196 var expectedByteData = convertFloatToByte(expected, analyser.minDecibe
ls, | 178 var expectedByteData = convertFloatToByte(expected, analyser.minDecibe
ls, |
| 197 analyser.maxDecibels); | 179 analyser.maxDecibels); |
| 198 | 180 |
| 199 basicTestsPassed = Should(analyser.fftSize + "-point byte FFT", byteFr
eqData) | 181 should(byteFreqData, analyser.fftSize + "-point byte FFT") |
| 200 .beCloseToArray(expectedByteData, 0) && basicTestsPassed; | 182 .beCloseToArray(expectedByteData, 0); |
| 201 | 183 |
| 202 }).then(context.resume.bind(context)); | 184 }).then(context.resume.bind(context)); |
| 203 | 185 |
| 204 return context.startRendering(); | 186 return context.startRendering(); |
| 205 } | 187 } |
| 206 </script> | 188 </script> |
| 207 </body> | 189 </body> |
| 208 </html> | 190 </html> |
| OLD | NEW |