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

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

Issue 2629543005: Test FFT scaling for all orders (Closed)
Patch Set: Wrap line better 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 | no next file » | 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/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/audit.js"></script> 7 <script src="../resources/audit.js"></script>
8 </head> 8 </head>
9 9
10 <body> 10 <body>
11 <div id="description"></div> 11 <div id="description"></div>
12 <div id="console"></div> 12 <div id="console"></div>
13 13
14 <script> 14 <script>
15 let audit = Audit.createTaskRunner(); 15 let audit = Audit.createTaskRunner();
16 16
17 // 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
18 // 64, 128, 256, 512, 1024 and 2048 for a total of 7. 18 // possible sizes of 2^5 to 2^15 for a total of 11.
19 let numberOfAnalysers = 7; 19 let numberOfAnalysers = 11;
20 let sampleRate = 44100; 20 let sampleRate = 44100;
21 let nyquistFrequency = sampleRate / 2; 21 let nyquistFrequency = sampleRate / 2;
22 22
23 // 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
24 // 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
25 // 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.
26 let oscFrequency = nyquistFrequency/16; 26 let oscFrequency = nyquistFrequency/16;
27 27
28 // 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.
29 let peakValue = new Array(numberOfAnalysers); 29 let peakValue = new Array(numberOfAnalysers);
30 30
31 // 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
32 // 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
33 // 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
34 // determined experimentally. 34 // determined experimentally.
35 // 35 //
36 // See https://code.google.com/p/chromium/issues/detail?id=341596. 36 // See https://code.google.com/p/chromium/issues/detail?id=341596.
37 let 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,
38 -13.56, -13.56, -13.56, -13.56, -13.56
39 ];
38 40
39 function checkResult(order, analyser, should) { 41 function checkResult(order, analyser, should) {
40 return function () { 42 return function () {
41 let index = order - 5; 43 let index = order - 5;
42 let fftSize = 1 << order; 44 let fftSize = 1 << order;
43 let fftData = new Float32Array(fftSize); 45 let fftData = new Float32Array(fftSize);
44 analyser.getFloatFrequencyData(fftData); 46 analyser.getFloatFrequencyData(fftData);
45 47
46 // Compute the frequency bin that should contain the peak. 48 // Compute the frequency bin that should contain the peak.
47 let expectedBin = analyser.frequencyBinCount * (oscFrequency / nyq uistFrequency); 49 let expectedBin = analyser.frequencyBinCount * (oscFrequency / nyq uistFrequency);
(...skipping 13 matching lines...) Expand all
61 63
62 should(peakValue[index], (1 << order) + 64 should(peakValue[index], (1 << order) +
63 "-point FFT peak value in dBFS") 65 "-point FFT peak value in dBFS")
64 .beGreaterThanOrEqualTo(peakThreshold[index]); 66 .beGreaterThanOrEqualTo(peakThreshold[index]);
65 } 67 }
66 } 68 }
67 69
68 audit.define("FFT scaling tests", function (task, should) { 70 audit.define("FFT scaling tests", function (task, should) {
69 task.describe("Test Scaling of FFT in AnalyserNode"); 71 task.describe("Test Scaling of FFT in AnalyserNode");
70 let tests = []; 72 let tests = [];
71 for (let k = 5; k < 12; ++k) 73 for (let k = 5; k <= 15; ++k)
72 tests.push(runTest(k, should)); 74 tests.push(runTest(k, should));
73 75
76 // The order in which the tests finish is not important.
74 Promise.all(tests) 77 Promise.all(tests)
75 .then(task.done.bind(task)); 78 .then(task.done.bind(task));
76 }); 79 });
77 80
78 function runTest(order, should) { 81 function runTest(order, should) {
79 let context = new OfflineAudioContext(1, 1 << order, sampleRate); 82 let context = new OfflineAudioContext(1, 1 << order, sampleRate);
80 // Use a sine wave oscillator as the reference source signal. 83 // Use a sine wave oscillator as the reference source signal.
81 let osc = context.createOscillator(); 84 let osc = context.createOscillator();
82 osc.type = "sine"; 85 osc.type = "sine";
83 osc.frequency.value = oscFrequency; 86 osc.frequency.value = oscFrequency;
(...skipping 10 matching lines...) Expand all
94 return context.startRendering() 97 return context.startRendering()
95 .then(function (audioBuffer) { 98 .then(function (audioBuffer) {
96 checkResult(audioBuffer, order, analyser); 99 checkResult(audioBuffer, order, analyser);
97 }); 100 });
98 } 101 }
99 102
100 audit.run(); 103 audit.run();
101 </script> 104 </script>
102 </body> 105 </body>
103 </html> 106 </html>
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698