Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-fft-scaling.html

Issue 2596983004: Convert realtimeanalyser-fft-scaling to testharness (Closed)
Patch Set: Rebase Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-fft-scaling-expected.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> 1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
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/audit-util.js"></script> 6 <script src="../resources/audit-util.js"></script>
6 <script src="../resources/audio-testing.js"></script> 7 <script src="../resources/audit.js"></script>
7 </head> 8 </head>
8 9
9 <body> 10 <body>
10 <div id="description"></div> 11 <div id="description"></div>
11 <div id="console"></div> 12 <div id="console"></div>
12 13
13 <script> 14 <script>
14 description("Test scaling of FFT data for AnalyserNode"); 15 let audit = Audit.createTaskRunner();
15 16
16 // The number of analysers. We have analysers from size for each of the po ssible sizes of 32, 17 // The number of analysers. We have analysers from size for each of the po ssible sizes of 32,
17 // 64, 128, 256, 512, 1024 and 2048 for a total of 7. 18 // 64, 128, 256, 512, 1024 and 2048 for a total of 7.
18 var numberOfAnalysers = 7; 19 let numberOfAnalysers = 7;
19 var sampleRate = 44100; 20 let sampleRate = 44100;
20 var nyquistFrequency = sampleRate / 2; 21 let nyquistFrequency = sampleRate / 2;
21 22
22 // Frequency of the sine wave test signal. Should be high enough so that we get at least one 23 // Frequency of the sine wave test signal. Should be high enough so that we get at least one
23 // full cycle for the 32-point FFT. This should also be such that the fre quency should be 24 // full cycle for the 32-point FFT. This should also be such that the fre quency should be
24 // exactly in one of the FFT bins for each of the possible FFT sizes. 25 // exactly in one of the FFT bins for each of the possible FFT sizes.
25 var oscFrequency = nyquistFrequency/16; 26 let oscFrequency = nyquistFrequency/16;
26 27
27 // The actual peak values from each analyser. Useful for examining the re sults in Chrome. 28 // The actual peak values from each analyser. Useful for examining the re sults in Chrome.
28 var peakValue = new Array(numberOfAnalysers); 29 let peakValue = new Array(numberOfAnalysers);
29 30
30 // For a 0dBFS sine wave, we would expect the FFT magnitude to be 0dB as w ell, but the 31 // For a 0dBFS sine wave, we would expect the FFT magnitude to be 0dB as w ell, but the
31 // analyzer node applies a Blackman window (to smooth the estimate). This reduces the energy 32 // analyzer node applies a Blackman window (to smooth the estimate). This reduces the energy
32 // of the signal so the FFT peak is less than 0dB. The threshold value gi ven here was 33 // of the signal so the FFT peak is less than 0dB. The threshold value gi ven here was
33 // determined experimentally. 34 // determined experimentally.
34 // 35 //
35 // See https://code.google.com/p/chromium/issues/detail?id=341596. 36 // See https://code.google.com/p/chromium/issues/detail?id=341596.
36 var peakThreshold = [-14.43, -13.56, -13.56, -13.56, -13.56, -13.56, -13.5 6]; 37 let peakThreshold = [-14.43, -13.56, -13.56, -13.56, -13.56, -13.56, -13.5 6];
37 38
38 var allTestsPassed = true; 39 function checkResult(order, analyser, should) {
39
40 function checkResult(order, analyser) {
41 return function () { 40 return function () {
42 var index = order - 5; 41 let index = order - 5;
43 var fftSize = 1 << order; 42 let fftSize = 1 << order;
44 var fftData = new Float32Array(fftSize); 43 let fftData = new Float32Array(fftSize);
45 analyser.getFloatFrequencyData(fftData); 44 analyser.getFloatFrequencyData(fftData);
46 45
47 // Compute the frequency bin that should contain the peak. 46 // Compute the frequency bin that should contain the peak.
48 var expectedBin = analyser.frequencyBinCount * (oscFrequency / nyq uistFrequency); 47 let expectedBin = analyser.frequencyBinCount * (oscFrequency / nyq uistFrequency);
49 48
50 // Find the actual bin by finding the bin containing the peak. 49 // Find the actual bin by finding the bin containing the peak.
51 var actualBin = 0; 50 let actualBin = 0;
52 peakValue[index] = -1000; 51 peakValue[index] = -1000;
53 for (k = 0; k < analyser.frequencyBinCount; ++k) { 52 for (k = 0; k < analyser.frequencyBinCount; ++k) {
54 if (fftData[k] > peakValue[index]) { 53 if (fftData[k] > peakValue[index]) {
55 actualBin = k; 54 actualBin = k;
56 peakValue[index] = fftData[k]; 55 peakValue[index] = fftData[k];
57 } 56 }
58 } 57 }
59 58
60 var success = true; 59 should(actualBin, (1 << order) + "-point FFT peak position")
60 .beEqualTo(expectedBin);
61 61
62 if (actualBin == expectedBin) { 62 should(peakValue[index], (1 << order) +
63 testPassed("Actual FFT peak in the expected position (" + expe ctedBin + ")."); 63 "-point FFT peak value in dBFS")
64 } else { 64 .beGreaterThanOrEqualTo(peakThreshold[index]);
65 success = false;
66 testFailed("Actual FFT peak (" + actualBin + ") differs from e xpected (" + expectedBin + ").");
67 }
68
69 if (peakValue[index] >= peakThreshold[index]) {
70 testPassed("Peak value is near " + peakThreshold[index] + " dB FS as expected.");
71 } else {
72 success = false;
73 testFailed("Peak value of " + peakValue[index]
74 + " is incorrect. (Expected approximately "
75 + peakThreshold[index] + ").");
76 }
77
78 if (success) {
79 testPassed("Analyser correctly scaled FFT data of size " + fft Size);
80 } else {
81 testFailed("Analyser incorrectly scaled FFT data of size " + f ftSize);
82 }
83 allTestsPassed = allTestsPassed && success;
84
85 if (fftSize == 2048) {
86 if (allTestsPassed) {
87 testPassed("All Analyser tests passed.");
88 } else {
89 testFailed("At least one Analyser test failed.");
90 }
91
92 finishJSTest();
93 }
94 } 65 }
95 } 66 }
96 67
97 function runTests() { 68 audit.define("FFT scaling tests", function (task, should) {
98 if (window.testRunner) { 69 task.describe("Test Scaling of FFT in AnalyserNode");
99 testRunner.dumpAsText(); 70 let tests = [];
100 testRunner.waitUntilDone(); 71 for (let k = 5; k < 12; ++k)
101 } 72 tests.push(runTest(k, should));
102 73
103 window.jsTestIsAsync = true; 74 Promise.all(tests)
75 .then(task.done.bind(task));
76 });
104 77
105 // Test each analyser size from order 5 (size 32) to 11 (size 2048). 78 function runTest(order, should) {
106 for (order = 5; order < 12; ++order) { 79 let context = new OfflineAudioContext(1, 1 << order, sampleRate);
107 // Create a new offline context for each analyser test with the nu mber of samples 80 // Use a sine wave oscillator as the reference source signal.
108 // exactly equal to the fft size. This ensures that the analyser node gets the 81 let osc = context.createOscillator();
109 // expected data from the oscillator. 82 osc.type = "sine";
110 var context = new OfflineAudioContext(1, 1 << order, sampleRate); 83 osc.frequency.value = oscFrequency;
111 // Use a sine wave oscillator as the reference source signal. 84 osc.connect(context.destination);
112 var osc = context.createOscillator();
113 osc.type = "sine";
114 osc.frequency.value = oscFrequency;
115 osc.connect(context.destination);
116 85
117 var analyser = context.createAnalyser(); 86 let analyser = context.createAnalyser();
118 // No smoothing to simplify the analysis of the result. 87 // No smoothing to simplify the analysis of the result.
119 analyser.smoothingTimeConstant = 0; 88 analyser.smoothingTimeConstant = 0;
120 analyser.fftSize = 1 << order; 89 analyser.fftSize = 1 << order;
121 osc.connect(analyser); 90 osc.connect(analyser);
122 91
123 osc.start(); 92 osc.start();
124 context.oncomplete = checkResult(order, analyser); 93 context.oncomplete = checkResult(order, analyser, should);
125 context.startRendering(); 94 return context.startRendering()
126 } 95 .then(function (audioBuffer) {
96 checkResult(audioBuffer, order, analyser);
97 });
127 } 98 }
128 99
129 runTests(); 100 audit.run();
130 successfullyParsed = true;
131 </script> 101 </script>
132 </body> 102 </body>
133 </html> 103 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-fft-scaling-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698