| OLD | NEW |
| 1 <!doctype html> | 1 <!doctype html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <title>Test fftSize Changes Resetting AnalyserNode State </title> | 4 <title>Test fftSize Changes Resetting AnalyserNode State </title> |
| 5 <script src="../../resources/testharness.js"></script> | 5 <script src="../../resources/testharness.js"></script> |
| 6 <script src="../../resources/testharnessreport.js"></script> | 6 <script src="../../resources/testharnessreport.js"></script> |
| 7 <script src="../resources/audit-util.js"></script> | 7 <script src="../resources/audit-util.js"></script> |
| 8 <script src="../resources/audio-testing.js"></script> | 8 <script src="../resources/audit.js"></script> |
| 9 </head> | 9 </head> |
| 10 | 10 |
| 11 <body> | 11 <body> |
| 12 <script> | 12 <script> |
| 13 // Fairly arbitrary sample rate. | 13 // Fairly arbitrary sample rate. |
| 14 var sampleRate = 24000; | 14 var sampleRate = 24000; |
| 15 | 15 |
| 16 var audit = Audit.createTaskRunner(); | 16 var audit = Audit.createTaskRunner(); |
| 17 | 17 |
| 18 // Verify that setting the fftSize resets the memory for the FFT smoothing | 18 // Verify that setting the fftSize resets the memory for the FFT smoothing |
| 19 // operation. Only a few of the possible variations are tested. | 19 // operation. Only a few of the possible variations are tested. |
| 20 | 20 |
| 21 audit.defineTask("128->1024", function (taskDone) { | 21 audit.define("128->1024", (task, should) => { |
| 22 testFFTSize({ | 22 testFFTSize(should, { |
| 23 initialFFTSize: 128, | 23 initialFFTSize: 128, |
| 24 finalFFTSize: 1024, | 24 finalFFTSize: 1024, |
| 25 errorThreshold: { | 25 errorThreshold: { |
| 26 relativeThreshold: 1.9095e-6 | 26 relativeThreshold: 1.9095e-6 |
| 27 } | 27 } |
| 28 }).then(taskDone); | 28 }).then(() => task.done()); |
| 29 }); | 29 }); |
| 30 | 30 |
| 31 audit.defineTask("512->256", function (taskDone) { | 31 audit.define("512->256", (task, should) => { |
| 32 testFFTSize({ | 32 testFFTSize(should, { |
| 33 initialFFTSize: 512, | 33 initialFFTSize: 512, |
| 34 finalFFTSize: 256, | 34 finalFFTSize: 256, |
| 35 errorThreshold: { | 35 errorThreshold: { |
| 36 relativeThreshold: 1.8166e-6 | 36 relativeThreshold: 1.8166e-6 |
| 37 } | 37 } |
| 38 }).then(taskDone); | 38 }).then(() => task.done()); |
| 39 }); | 39 }); |
| 40 | 40 |
| 41 function testFFTSize(options) { | 41 function testFFTSize(should, options) { |
| 42 var { | 42 var { |
| 43 initialFFTSize, finalFFTSize, errorThreshold | 43 initialFFTSize, finalFFTSize, errorThreshold |
| 44 } = options; | 44 } = options; |
| 45 | 45 |
| 46 // The duration is fairly arbitrary as long as it's long enough for the | 46 // The duration is fairly arbitrary as long as it's long enough for the |
| 47 // FFT test. | 47 // FFT test. |
| 48 var context = new OfflineAudioContext(1, sampleRate, sampleRate); | 48 var context = new OfflineAudioContext(1, sampleRate, sampleRate); |
| 49 | 49 |
| 50 // Actual source doesn't matter but a sawtooth is a nice waveform with | 50 // Actual source doesn't matter but a sawtooth is a nice waveform with |
| 51 // lots of harmonic content. | 51 // lots of harmonic content. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 99 | 99 |
| 100 // Convert the FFT data from dB to linear | 100 // Convert the FFT data from dB to linear |
| 101 testFFT = testFFT.map(x => Math.pow(10, x / 20)); | 101 testFFT = testFFT.map(x => Math.pow(10, x / 20)); |
| 102 refFFT = refFFT.map(x => Math.pow(10, x / 20)); | 102 refFFT = refFFT.map(x => Math.pow(10, x / 20)); |
| 103 | 103 |
| 104 // The test data has smoothing applied, but the reference doesn't. | 104 // The test data has smoothing applied, but the reference doesn't. |
| 105 // Apply the smoothing factor to the reference data. | 105 // Apply the smoothing factor to the reference data. |
| 106 var smoothing = 1 - testAnalyser.smoothingTimeConstant; | 106 var smoothing = 1 - testAnalyser.smoothingTimeConstant; |
| 107 refFFT = refFFT.map(x => x * smoothing); | 107 refFFT = refFFT.map(x => x * smoothing); |
| 108 | 108 |
| 109 var success = true; | |
| 110 | |
| 111 // First a basic sanity check that the time domain signals are | 109 // First a basic sanity check that the time domain signals are |
| 112 // exactly the same for both analysers. | 110 // exactly the same for both analysers. |
| 113 success = Should("Time data", testSignal) | 111 should(testSignal, "Time data") |
| 114 .beCloseToArray(refSignal, 0) && success; | 112 .beCloseToArray(refSignal, 0); |
| 115 | 113 |
| 116 success = Should("Linear FFT data after setting fftSize = " + testAn
alyser.fftSize, | 114 should(testFFT, "Linear FFT data after setting fftSize = " + testAna
lyser.fftSize) |
| 117 testFFT) | 115 .beCloseToArray(refFFT, errorThreshold); |
| 118 .beCloseToArray(refFFT, errorThreshold) && success; | |
| 119 | |
| 120 Should("*** Changing fftSize from " + initialFFTSize + " to " + fina
lFFTSize, success) | |
| 121 .summarize( | |
| 122 "correctly reset the smoothing state", | |
| 123 "did not correctly reset the smoothing state"); | |
| 124 }) | 116 }) |
| 125 .then(context.resume.bind(context)); | 117 .then(context.resume.bind(context)); |
| 126 | 118 |
| 127 return context.startRendering(); | 119 return context.startRendering(); |
| 128 } | 120 } |
| 129 | 121 |
| 130 audit.runTasks(); | 122 audit.run(); |
| 131 </script> | 123 </script> |
| 132 </body> | 124 </body> |
| 133 </html> | 125 </html> |
| OLD | NEW |