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

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

Issue 2895963003: Apply layout-test-tidy to LayoutTests/webaudio (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 <title>
5 Test Analyser getFloatFrequencyData and getByteFrequencyData, No
6 Smoothing
7 </title>
4 <script src="../../resources/testharness.js"></script> 8 <script src="../../resources/testharness.js"></script>
5 <script src="../../resources/testharnessreport.js"></script> 9 <script src="../../resources/testharnessreport.js"></script>
6 <script src="../resources/audit-util.js"></script> 10 <script src="../resources/audit-util.js"></script>
7 <script src="../resources/audit.js"></script> 11 <script src="../resources/audit.js"></script>
8 <script src="../resources/realtimeanalyser-testing.js"></script> 12 <script src="../resources/realtimeanalyser-testing.js"></script>
9 <script src="../resources/fft.js"></script> 13 <script src="../resources/fft.js"></script>
10 <title>Test Analyser getFloatFrequencyData and getByteFrequencyData, No Smoo thing</title>
11 </head> 14 </head>
12
13 <body> 15 <body>
14 <script> 16 <script id="layout-test-code">
15 // Use a power of two to eliminate any round-off in the computation of the times for 17 // Use a power of two to eliminate any round-off in the computation of the
16 // context.suspend(). 18 // times for context.suspend().
17 let sampleRate = 32768; 19 let sampleRate = 32768;
18 20
19 // The largest FFT size for the analyser node is 32768. We want to render longer than this so 21 // The largest FFT size for the analyser node is 32768. We want to render
20 // that we have at least one complete buffer of data of 32768 samples. 22 // longer than this so that we have at least one complete buffer of data
23 // of 32768 samples.
21 let renderFrames = 2 * 32768; 24 let renderFrames = 2 * 32768;
22 let renderDuration = renderFrames / sampleRate; 25 let renderDuration = renderFrames / sampleRate;
23 26
24 let audit = Audit.createTaskRunner(); 27 let audit = Audit.createTaskRunner();
25 28
26 // Options for basic tests of the AnalyserNode frequency domain data. The thresholds are 29 // Options for basic tests of the AnalyserNode frequency domain data. The
27 // experimentally determined. 30 // thresholds are experimentally determined.
28 let testConfig = [{ 31 let testConfig = [
29 order: 5, 32 {
30 // For this order, need to specify a higher minDecibels value for the an alyser because the 33 order: 5,
31 // FFT doesn't get that small. This allows us to test that (a changed) m inDecibels has an 34 // For this order, need to specify a higher minDecibels value for the
32 // effect and that we properly clip the byte data. 35 // analyser because the FFT doesn't get that small. This allows us to
33 minDecibels: -50, 36 // test that (a changed) minDecibels has an effect and that we
34 floatRelError: 9.6549e-7, 37 // properly clip the byte data.
35 }, { 38 minDecibels: -50,
36 order: 6, 39 floatRelError: 9.6549e-7,
37 floatRelError: 6.8366e-6 40 },
38 }, { 41 {order: 6, floatRelError: 6.8366e-6},
39 order: 7, 42 {order: 7, floatRelError: 1.4602e-6},
40 floatRelError: 1.4602e-6 43 {order: 8, floatRelError: 8.4828e-7},
41 }, { 44 {order: 9, floatRelError: 2.3906e-5},
42 order: 8, 45 {order: 10, floatRelError: 2.0483e-5},
43 floatRelError: 8.4828e-7 46 {order: 11, floatRelError: 1.3456e-5},
44 }, { 47 {order: 12, floatRelError: 4.6116e-7},
45 order: 9, 48 {order: 13, floatRelError: 3.2106e-7},
46 floatRelError: 2.3906e-5 49 {order: 14, floatRelError: 1.1756e-7},
47 }, { 50 {order: 15, floatRelError: 1.1756e-7}
48 order: 10, 51 ];
49 floatRelError: 2.0483e-5
50 }, {
51 order: 11,
52 floatRelError: 1.3456e-5
53 }, {
54 order: 12,
55 floatRelError: 4.6116e-7
56 }, {
57 order: 13,
58 floatRelError: 3.2106e-7
59 }, {
60 order: 14,
61 floatRelError: 1.1756e-7
62 }, {
63 order: 15,
64 floatRelError: 1.1756e-7
65 }];
66 52
67 // True if all of the basic tests passed. 53 // True if all of the basic tests passed.
68 let basicTestsPassed = true; 54 let basicTestsPassed = true;
69 55
70 // Generate tests for each entry in testConfig. 56 // Generate tests for each entry in testConfig.
71 for (let k = 0; k < testConfig.length; ++k) { 57 for (let k = 0; k < testConfig.length; ++k) {
72 let name = testConfig[k].order + "-order FFT"; 58 let name = testConfig[k].order + '-order FFT';
73 (function (config) { 59 (function(config) {
74 audit.define(name, (task, should) => { 60 audit.define(name, (task, should) => {
75 basicFFTTest(should, config).then(() => task.done()); 61 basicFFTTest(should, config).then(() => task.done());
76 }); 62 });
77 })(testConfig[k]); 63 })(testConfig[k]);
78 } 64 }
79 65
80 // Test that smoothing isn't done and we have the expected data, calling g etFloatFrequencyData 66 // Test that smoothing isn't done and we have the expected data, calling
81 // twice at different times. 67 // getFloatFrequencyData twice at different times.
82 audit.define("no smoothing", (task, should) => { 68 audit.define('no smoothing', (task, should) => {
83 // Use 128-point FFT for the test. The actual order doesn't matter (but the error threshold 69 // Use 128-point FFT for the test. The actual order doesn't matter (but
84 // depends on the order). 70 // the error threshold depends on the order).
85 let options = { 71 let options = {order: 7, smoothing: 0, floatRelError: 1.2548e-6};
86 order: 7,
87 smoothing: 0,
88 floatRelError: 1.2548e-6
89 };
90 let graph = createGraph(options); 72 let graph = createGraph(options);
91 let context = graph.context; 73 let context = graph.context;
92 let analyser = graph.analyser; 74 let analyser = graph.analyser;
93 75
94 // Be sure to suspend after the analyser fftSize so we get a full buffer of data. We will 76 // Be sure to suspend after the analyser fftSize so we get a full buffer
95 // grab the FFT data to prime the pump for smoothing. We don't need to check the results 77 // of data. We will grab the FFT data to prime the pump for smoothing.
96 // (because this is tested above in the basicFFTTests). 78 // We don't need to check the results (because this is tested above in
79 // the basicFFTTests).
97 let suspendFrame = Math.max(128, analyser.fftSize); 80 let suspendFrame = Math.max(128, analyser.fftSize);
98 context.suspend(suspendFrame / sampleRate).then(function () { 81 context.suspend(suspendFrame / sampleRate)
99 // Grab the time and frequency data. But we don't care what values we get now; we just 82 .then(function() {
100 // want to prime the analyser. 83 // Grab the time and frequency data. But we don't care what
101 let freqData = new Float32Array(analyser.frequencyBinCount); 84 // values we get now; we just want to prime the analyser.
85 let freqData = new Float32Array(analyser.frequencyBinCount);
102 86
103 // Grab the frequency domain data 87 // Grab the frequency domain data
104 analyser.getFloatFrequencyData(freqData); 88 analyser.getFloatFrequencyData(freqData);
105 }).then(context.resume.bind(context)); 89 })
90 .then(context.resume.bind(context));
106 91
107 // Grab another set of data after one rendering quantum. We will test t his to make sure 92 // Grab another set of data after one rendering quantum. We will test
108 // smoothing was not done. 93 // this to make sure smoothing was not done.
109 suspendFrame += 128; 94 suspendFrame += 128;
110 context.suspend(suspendFrame / sampleRate).then(function () { 95 context.suspend(suspendFrame / sampleRate)
111 let timeData = new Float32Array(analyser.fftSize); 96 .then(function() {
112 let freqData = new Float32Array(analyser.frequencyBinCount); 97 let timeData = new Float32Array(analyser.fftSize);
98 let freqData = new Float32Array(analyser.frequencyBinCount);
113 99
114 // Grab the time domain and frequency domain data 100 // Grab the time domain and frequency domain data
115 analyser.getFloatTimeDomainData(timeData); 101 analyser.getFloatTimeDomainData(timeData);
116 analyser.getFloatFrequencyData(freqData); 102 analyser.getFloatFrequencyData(freqData);
117 103
118 let expected = computeFFTMagnitude(timeData, options.order).map(linear ToDb); 104 let expected =
119 let comparison = compareFloatFreq(Math.pow(2, options.order) + "-point float FFT", 105 computeFFTMagnitude(timeData, options.order).map(linearToDb);
120 freqData, expected, should, options); 106 let comparison = compareFloatFreq(
121 basicTestsPassed = basicTestsPassed && comparison.success; 107 Math.pow(2, options.order) + '-point float FFT', freqData,
122 }).then(context.resume.bind(context)); 108 expected, should, options);
109 basicTestsPassed = basicTestsPassed && comparison.success;
110 })
111 .then(context.resume.bind(context));
123 112
124 context.startRendering().then(() => task.done()); 113 context.startRendering().then(() => task.done());
125 }); 114 });
126 115
127 audit.run(); 116 audit.run();
128 117
129 // Run a simple test of the AnalyserNode's frequency domain data. Both th e float and byte 118 // Run a simple test of the AnalyserNode's frequency domain data. Both
130 // frequency data are tested. The byte tests depend on the float tests be ing correct. 119 // the float and byte frequency data are tested. The byte tests depend on
120 // the float tests being correct.
131 // 121 //
132 // The parameters of the test are given by |options| which is a property b ag consisting of the 122 // The parameters of the test are given by |options| which is a property
133 // following: 123 // bag consisting of the following:
134 // 124 //
135 // order: Order of the FFT to test. 125 // order: Order of the FFT to test.
136 // smoothing: smoothing time constant for the analyser. 126 // smoothing: smoothing time constant for the analyser.
137 // minDecibels: min decibels value for the analyser. 127 // minDecibels: min decibels value for the analyser.
138 // floatRelError: max allowed relative error for the float FFT data 128 // floatRelError: max allowed relative error for the float FFT data
139 function basicFFTTest(should, options) { 129 function basicFFTTest(should, options) {
140 let graph = createGraph(options); 130 let graph = createGraph(options);
141 let context = graph.context; 131 let context = graph.context;
142 let analyser = graph.analyser; 132 let analyser = graph.analyser;
143 133
144 let suspendTime = Math.max(128, analyser.fftSize) / sampleRate; 134 let suspendTime = Math.max(128, analyser.fftSize) / sampleRate;
145 context.suspend(suspendTime).then(function () { 135 context.suspend(suspendTime)
146 let timeData = new Float32Array(analyser.fftSize); 136 .then(function() {
147 let freqData = new Float32Array(analyser.frequencyBinCount); 137 let timeData = new Float32Array(analyser.fftSize);
138 let freqData = new Float32Array(analyser.frequencyBinCount);
148 139
149 // Grab the time domain and frequency domain data 140 // Grab the time domain and frequency domain data
150 analyser.getFloatTimeDomainData(timeData); 141 analyser.getFloatTimeDomainData(timeData);
151 analyser.getFloatFrequencyData(freqData); 142 analyser.getFloatFrequencyData(freqData);
152 143
153 let expected = computeFFTMagnitude(timeData, options.order).map(linear ToDb); 144 let expected =
154 let comparison = compareFloatFreq(Math.pow(2, options.order) + "-point float FFT", 145 computeFFTMagnitude(timeData, options.order).map(linearToDb);
155 freqData, expected, should, options); 146 let comparison = compareFloatFreq(
156 basicTestsPassed = basicTestsPassed && comparison.success; 147 Math.pow(2, options.order) + '-point float FFT', freqData,
157 expected = comparison.expected; 148 expected, should, options);
149 basicTestsPassed = basicTestsPassed && comparison.success;
150 expected = comparison.expected;
158 151
159 // For the byte test to be better, check that there are some samples t hat are outside the 152 // For the byte test to be better, check that there are some
160 // range of minDecibels and maxDecibels. If there aren't the test sho uld update the 153 // samples that are outside the range of minDecibels and
161 // minDecibels and maxDecibels values for the analyser. 154 // maxDecibels. If there aren't the test should update the
155 // minDecibels and maxDecibels values for the analyser.
162 156
163 let minValue = Math.min(...expected); 157 let minValue = Math.min(...expected);
164 let maxValue = Math.max(...expected); 158 let maxValue = Math.max(...expected);
165 159
166 should(minValue, "Order: " + options.order + 160 should(minValue, 'Order: ' + options.order + ': Min FFT value')
167 ": Min FFT value") 161 .beLessThanOrEqualTo(analyser.minDecibels);
168 .beLessThanOrEqualTo(analyser.minDecibels); 162 should(maxValue, 'Order: ' + options.order + ': Max FFT value')
169 should(maxValue, "Order: " + options.order + 163 .beGreaterThanOrEqualTo(analyser.maxDecibels);
170 ": Max FFT value") 164 // Test the byte frequency data.
171 .beGreaterThanOrEqualTo(analyser.maxDecibels); 165 let byteFreqData = new Uint8Array(analyser.frequencyBinCount);
172 // Test the byte frequency data. 166 analyser.getByteFrequencyData(byteFreqData);
173 let byteFreqData = new Uint8Array(analyser.frequencyBinCount);
174 analyser.getByteFrequencyData(byteFreqData);
175 167
176 // Convert the expected float frequency data to byte data. 168 // Convert the expected float frequency data to byte data.
177 let expectedByteData = convertFloatToByte(expected, analyser.minDecibe ls, 169 let expectedByteData = convertFloatToByte(
178 analyser.maxDecibels); 170 expected, analyser.minDecibels, analyser.maxDecibels);
179 171
180 should(byteFreqData, analyser.fftSize + "-point byte FFT") 172 should(byteFreqData, analyser.fftSize + '-point byte FFT')
181 .beCloseToArray(expectedByteData, 0); 173 .beCloseToArray(expectedByteData, 0);
182 174
183 }).then(context.resume.bind(context)); 175 })
176 .then(context.resume.bind(context));
184 177
185 return context.startRendering(); 178 return context.startRendering();
186 } 179 }
187 </script> 180 </script>
188 </body> 181 </body>
189 </html> 182 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698