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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-freq-data.html

Issue 2892803002: Fix layout tests to prevent errors from layout-test-tidy (Closed)
Patch Set: Created 3 years, 7 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
OLDNEW
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/audit.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 let sampleRate = 32768;
18 18
19 // The largest FFT size for the analyser node is 32768. We want to render longer than this so 19 // The largest FFT size for the analyser node is 32768. We want to render longer than this so
20 // that we have at least one complete buffer of data of 32768 samples. 20 // that we have at least one complete buffer of data of 32768 samples.
21 var renderFrames = 2 * 32768; 21 let renderFrames = 2 * 32768;
22 var renderDuration = renderFrames / sampleRate; 22 let renderDuration = renderFrames / sampleRate;
23 23
24 var audit = Audit.createTaskRunner(); 24 let audit = Audit.createTaskRunner();
25 25
26 // Options for basic tests of the AnalyserNode frequency domain data. The thresholds are 26 // Options for basic tests of the AnalyserNode frequency domain data. The thresholds are
27 // experimentally determined. 27 // experimentally determined.
28 var testConfig = [{ 28 let testConfig = [{
29 order: 5, 29 order: 5,
30 // For this order, need to specify a higher minDecibels value for the an alyser because the 30 // For this order, need to specify a higher minDecibels value for the an alyser because the
31 // FFT doesn't get that small. This allows us to test that (a changed) m inDecibels has an 31 // FFT doesn't get that small. This allows us to test that (a changed) m inDecibels has an
32 // effect and that we properly clip the byte data. 32 // effect and that we properly clip the byte data.
33 minDecibels: -50, 33 minDecibels: -50,
34 floatRelError: 9.6549e-7, 34 floatRelError: 9.6549e-7,
35 }, { 35 }, {
36 order: 6, 36 order: 6,
37 floatRelError: 6.8366e-6 37 floatRelError: 6.8366e-6
38 }, { 38 }, {
(...skipping 19 matching lines...) Expand all
58 floatRelError: 3.2106e-7 58 floatRelError: 3.2106e-7
59 }, { 59 }, {
60 order: 14, 60 order: 14,
61 floatRelError: 1.1756e-7 61 floatRelError: 1.1756e-7
62 }, { 62 }, {
63 order: 15, 63 order: 15,
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 let 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 (let k = 0; k < testConfig.length; ++k) {
72 var name = testConfig[k].order + "-order FFT"; 72 let name = testConfig[k].order + "-order FFT";
73 (function (config) { 73 (function (config) {
74 audit.define(name, (task, should) => { 74 audit.define(name, (task, should) => {
75 basicFFTTest(should, config).then(() => task.done()); 75 basicFFTTest(should, config).then(() => task.done());
76 }); 76 });
77 })(testConfig[k]); 77 })(testConfig[k]);
78 } 78 }
79 79
80 // 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
81 // twice at different times. 81 // twice at different times.
82 audit.define("no smoothing", (task, should) => { 82 audit.define("no smoothing", (task, should) => {
83 // 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
84 // depends on the order). 84 // depends on the order).
85 var options = { 85 let options = {
86 order: 7, 86 order: 7,
87 smoothing: 0, 87 smoothing: 0,
88 floatRelError: 1.2548e-6 88 floatRelError: 1.2548e-6
89 }; 89 };
90 var graph = createGraph(options); 90 let graph = createGraph(options);
91 var context = graph.context; 91 let context = graph.context;
92 var analyser = graph.analyser; 92 let analyser = graph.analyser;
93 93
94 // Be sure to suspend after the analyser fftSize so we get a full buffer of data. We will 94 // Be sure to suspend after the analyser fftSize so we get a full buffer of data. We will
95 // grab the FFT data to prime the pump for smoothing. We don't need to check the results 95 // grab the FFT data to prime the pump for smoothing. We don't need to check the results
96 // (because this is tested above in the basicFFTTests). 96 // (because this is tested above in the basicFFTTests).
97 var suspendFrame = Math.max(128, analyser.fftSize); 97 let suspendFrame = Math.max(128, analyser.fftSize);
98 context.suspend(suspendFrame / sampleRate).then(function () { 98 context.suspend(suspendFrame / sampleRate).then(function () {
99 // Grab the time and frequency data. But we don't care what values we get now; we just 99 // Grab the time and frequency data. But we don't care what values we get now; we just
100 // want to prime the analyser. 100 // want to prime the analyser.
101 var freqData = new Float32Array(analyser.frequencyBinCount); 101 let freqData = new Float32Array(analyser.frequencyBinCount);
102 102
103 // Grab the frequency domain data 103 // Grab the frequency domain data
104 analyser.getFloatFrequencyData(freqData); 104 analyser.getFloatFrequencyData(freqData);
105 }).then(context.resume.bind(context)); 105 }).then(context.resume.bind(context));
106 106
107 // Grab another set of data after one rendering quantum. We will test t his to make sure 107 // Grab another set of data after one rendering quantum. We will test t his to make sure
108 // smoothing was not done. 108 // smoothing was not done.
109 suspendFrame += 128; 109 suspendFrame += 128;
110 context.suspend(suspendFrame / sampleRate).then(function () { 110 context.suspend(suspendFrame / sampleRate).then(function () {
111 var timeData = new Float32Array(analyser.fftSize); 111 let timeData = new Float32Array(analyser.fftSize);
112 var freqData = new Float32Array(analyser.frequencyBinCount); 112 let freqData = new Float32Array(analyser.frequencyBinCount);
113 113
114 // Grab the time domain and frequency domain data 114 // Grab the time domain and frequency domain data
115 analyser.getFloatTimeDomainData(timeData); 115 analyser.getFloatTimeDomainData(timeData);
116 analyser.getFloatFrequencyData(freqData); 116 analyser.getFloatFrequencyData(freqData);
117 117
118 var expected = computeFFTMagnitude(timeData, options.order).map(linear ToDb); 118 let expected = computeFFTMagnitude(timeData, options.order).map(linear ToDb);
119 var comparison = compareFloatFreq(Math.pow(2, options.order) + "-point float FFT", 119 let comparison = compareFloatFreq(Math.pow(2, options.order) + "-point float FFT",
120 freqData, expected, should, options); 120 freqData, expected, should, options);
121 basicTestsPassed = basicTestsPassed && comparison.success; 121 basicTestsPassed = basicTestsPassed && comparison.success;
122 }).then(context.resume.bind(context)); 122 }).then(context.resume.bind(context));
123 123
124 context.startRendering().then(() => task.done()); 124 context.startRendering().then(() => task.done());
125 }); 125 });
126 126
127 audit.run(); 127 audit.run();
128 128
129 // 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
130 // 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.
131 // 131 //
132 // 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
133 // following: 133 // following:
134 // 134 //
135 // order: Order of the FFT to test. 135 // order: Order of the FFT to test.
136 // smoothing: smoothing time constant for the analyser. 136 // smoothing: smoothing time constant for the analyser.
137 // minDecibels: min decibels value for the analyser. 137 // minDecibels: min decibels value for the analyser.
138 // floatRelError: max allowed relative error for the float FFT data 138 // floatRelError: max allowed relative error for the float FFT data
139 function basicFFTTest(should, options) { 139 function basicFFTTest(should, options) {
140 var graph = createGraph(options); 140 let graph = createGraph(options);
141 var context = graph.context; 141 let context = graph.context;
142 var analyser = graph.analyser; 142 let analyser = graph.analyser;
143 143
144 var suspendTime = Math.max(128, analyser.fftSize) / sampleRate; 144 let suspendTime = Math.max(128, analyser.fftSize) / sampleRate;
145 context.suspend(suspendTime).then(function () { 145 context.suspend(suspendTime).then(function () {
146 var timeData = new Float32Array(analyser.fftSize); 146 let timeData = new Float32Array(analyser.fftSize);
147 var freqData = new Float32Array(analyser.frequencyBinCount); 147 let freqData = new Float32Array(analyser.frequencyBinCount);
148 148
149 // Grab the time domain and frequency domain data 149 // Grab the time domain and frequency domain data
150 analyser.getFloatTimeDomainData(timeData); 150 analyser.getFloatTimeDomainData(timeData);
151 analyser.getFloatFrequencyData(freqData); 151 analyser.getFloatFrequencyData(freqData);
152 152
153 var expected = computeFFTMagnitude(timeData, options.order).map(linear ToDb); 153 let expected = computeFFTMagnitude(timeData, options.order).map(linear ToDb);
154 var comparison = compareFloatFreq(Math.pow(2, options.order) + "-point float FFT", 154 let comparison = compareFloatFreq(Math.pow(2, options.order) + "-point float FFT",
155 freqData, expected, should, options); 155 freqData, expected, should, options);
156 basicTestsPassed = basicTestsPassed && comparison.success; 156 basicTestsPassed = basicTestsPassed && comparison.success;
157 var expected = comparison.expected; 157 expected = comparison.expected;
Raymond Toy 2017/05/19 13:53:37 So the real change here is the double declaration
hongchan 2017/05/19 16:15:29 Yes.
158 158
159 // 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
160 // 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
161 // minDecibels and maxDecibels values for the analyser. 161 // minDecibels and maxDecibels values for the analyser.
162 162
163 var minValue = Math.min(...expected); 163 let minValue = Math.min(...expected);
164 var maxValue = Math.max(...expected); 164 let maxValue = Math.max(...expected);
165 165
166 should(minValue, "Order: " + options.order + 166 should(minValue, "Order: " + options.order +
167 ": Min FFT value") 167 ": Min FFT value")
168 .beLessThanOrEqualTo(analyser.minDecibels); 168 .beLessThanOrEqualTo(analyser.minDecibels);
169 should(maxValue, "Order: " + options.order + 169 should(maxValue, "Order: " + options.order +
170 ": Max FFT value") 170 ": Max FFT value")
171 .beGreaterThanOrEqualTo(analyser.maxDecibels); 171 .beGreaterThanOrEqualTo(analyser.maxDecibels);
172 // Test the byte frequency data. 172 // Test the byte frequency data.
173 var byteFreqData = new Uint8Array(analyser.frequencyBinCount); 173 let byteFreqData = new Uint8Array(analyser.frequencyBinCount);
174 var expectedByteData = new Float32Array(analyser.frequencyBinCount);
hongchan 2017/05/19 16:15:29 Also this does not need the declaration.
175 analyser.getByteFrequencyData(byteFreqData); 174 analyser.getByteFrequencyData(byteFreqData);
176 175
177 // Convert the expected float frequency data to byte data. 176 // Convert the expected float frequency data to byte data.
178 var expectedByteData = convertFloatToByte(expected, analyser.minDecibe ls, 177 let expectedByteData = convertFloatToByte(expected, analyser.minDecibe ls,
179 analyser.maxDecibels); 178 analyser.maxDecibels);
180 179
181 should(byteFreqData, analyser.fftSize + "-point byte FFT") 180 should(byteFreqData, analyser.fftSize + "-point byte FFT")
182 .beCloseToArray(expectedByteData, 0); 181 .beCloseToArray(expectedByteData, 0);
183 182
184 }).then(context.resume.bind(context)); 183 }).then(context.resume.bind(context));
185 184
186 return context.startRendering(); 185 return context.startRendering();
187 } 186 }
188 </script> 187 </script>
189 </body> 188 </body>
190 </html> 189 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698