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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-freq-data-smoothing.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, Smoothi ng</title> 10 <title>Test Analyser getFloatFrequencyData and getByteFrequencyData, Smoothi ng</title>
11 11
12 </head> 12 </head>
13 13
14 <body> 14 <body>
15 <script> 15 <script>
16 // Use a power of two to eliminate any round-off in the computation of the times for 16 // Use a power of two to eliminate any round-off in the computation of the times for
17 // context.suspend(). 17 // context.suspend().
18 var sampleRate = 32768; 18 let sampleRate = 32768;
19 19
20 // The largest FFT size for the analyser node is 32768. We want to render longer than this so 20 // The largest FFT size for the analyser node is 32768. We want to render longer than this so
21 // that we have at least one complete buffer of data of 32768 samples. 21 // that we have at least one complete buffer of data of 32768 samples.
22 var renderFrames = 2 * 32768; 22 let renderFrames = 2 * 32768;
23 var renderDuration = renderFrames / sampleRate; 23 let renderDuration = renderFrames / sampleRate;
24 24
25 var audit = Audit.createTaskRunner(); 25 let audit = Audit.createTaskRunner();
26 26
27 // Do one basic test of smoothing of the FFT data. 27 // Do one basic test of smoothing of the FFT data.
28 audit.define("smoothing test", (task, should) => { 28 audit.define("smoothing test", (task, should) => {
29 // Test only 512-point FFT. The size isn't too important as long as it' s greater than 128 29 // Test only 512-point FFT. The size isn't too important as long as it' s greater than 128
30 // (a rendering quantum). 30 // (a rendering quantum).
31 var options = { 31 let options = {
32 order: 9, 32 order: 9,
33 smoothing: 0.5, 33 smoothing: 0.5,
34 floatRelError: 5.9207e-6 34 floatRelError: 5.9207e-6
35 }; 35 };
36 36
37 var success = true; 37 let success = true;
38 38
39 var graph = createGraph(options); 39 let graph = createGraph(options);
40 40
41 context = graph.context; 41 context = graph.context;
42 analyser = graph.analyser; 42 analyser = graph.analyser;
43 43
44 var smoothedFloatResult = new Float32Array(analyser.frequencyBinCount); 44 let smoothedFloatResult = new Float32Array(analyser.frequencyBinCount);
45 smoothedFloatResult.fill(0); 45 smoothedFloatResult.fill(0);
46 46
47 // Stop after one analyser frame to get the initial FFT 47 // Stop after one analyser frame to get the initial FFT
48 var suspendFrame = analyser.fftSize; 48 let suspendFrame = analyser.fftSize;
49 context.suspend(suspendFrame / sampleRate).then(function () { 49 context.suspend(suspendFrame / sampleRate).then(function () {
50 var timeData = new Float32Array(analyser.fftSize); 50 let timeData = new Float32Array(analyser.fftSize);
51 var freqData = new Float32Array(analyser.frequencyBinCount); 51 let freqData = new Float32Array(analyser.frequencyBinCount);
52 analyser.getFloatTimeDomainData(timeData); 52 analyser.getFloatTimeDomainData(timeData);
53 analyser.getFloatFrequencyData(freqData); 53 analyser.getFloatFrequencyData(freqData);
54 54
55 var expectedFreq = computeFFTMagnitude(timeData, options.order); 55 let expectedFreq = computeFFTMagnitude(timeData, options.order);
56 smoothFFT(smoothedFloatResult, expectedFreq, options.smoothing); 56 smoothFFT(smoothedFloatResult, expectedFreq, options.smoothing);
57 57
58 var message = "First " + analyser.fftSize + "-point FFT at frame " + ( context.currentTime * 58 let message = "First " + analyser.fftSize + "-point FFT at frame " + ( context.currentTime *
59 sampleRate); 59 sampleRate);
60 var comparison = compareFloatFreq(message, freqData, smoothedFloatResu lt.map( 60 let comparison = compareFloatFreq(message, freqData, smoothedFloatResu lt.map(
61 linearToDb), should, options); 61 linearToDb), should, options);
62 success = success && comparison.success; 62 success = success && comparison.success;
63 63
64 // Test the byte frequency data. 64 // Test the byte frequency data.
65 var byteFreqData = new Uint8Array(analyser.frequencyBinCount); 65 let byteFreqData = new Uint8Array(analyser.frequencyBinCount);
66 var expectedByteData = new Float32Array(analyser.frequencyBinCount);
Raymond Toy 2017/05/19 13:53:37 So, the issue here is the double declaration for e
hongchan 2017/05/19 16:15:29 Not only that, the assigning a new array to it is
67 analyser.getByteFrequencyData(byteFreqData); 66 analyser.getByteFrequencyData(byteFreqData);
68 67
69 // Convert the expected float frequency data to byte data. 68 // Convert the expected float frequency data to byte data.
70 var expectedByteData = convertFloatToByte(smoothedFloatResult.map(line arToDb), 69 let expectedByteData = convertFloatToByte(smoothedFloatResult.map(line arToDb),
71 analyser.minDecibels, analyser.maxDecibels); 70 analyser.minDecibels, analyser.maxDecibels);
72 71
73 should(byteFreqData, analyser.fftSize + "-point byte FFT") 72 should(byteFreqData, analyser.fftSize + "-point byte FFT")
74 .beCloseToArray(expectedByteData, 0); 73 .beCloseToArray(expectedByteData, 0);
75 74
76 }).then(context.resume.bind(context)); 75 }).then(context.resume.bind(context));
77 76
78 // Skip an analyser frame and grab another to verify that the smoothing is done correctly. 77 // Skip an analyser frame and grab another to verify that the smoothing is done correctly.
79 suspendFrame += 2 * analyser.fftSize; 78 suspendFrame += 2 * analyser.fftSize;
80 context.suspend(suspendFrame / sampleRate).then(function () { 79 context.suspend(suspendFrame / sampleRate).then(function () {
81 var timeData = new Float32Array(analyser.fftSize); 80 let timeData = new Float32Array(analyser.fftSize);
82 var freqDataInDb = new Float32Array(analyser.frequencyBinCount); 81 let freqDataInDb = new Float32Array(analyser.frequencyBinCount);
83 82
84 // Grab the time domain and frequency domain data 83 // Grab the time domain and frequency domain data
85 analyser.getFloatTimeDomainData(timeData); 84 analyser.getFloatTimeDomainData(timeData);
86 analyser.getFloatFrequencyData(freqDataInDb); 85 analyser.getFloatFrequencyData(freqDataInDb);
87 86
88 var newFreqData = computeFFTMagnitude(timeData, options.order); 87 let newFreqData = computeFFTMagnitude(timeData, options.order);
89 // Smooth the data together 88 // Smooth the data together
90 89
91 smoothFFT(smoothedFloatResult, newFreqData, options.smoothing); 90 smoothFFT(smoothedFloatResult, newFreqData, options.smoothing);
92 var message = "Smoothed " + analyser.fftSize + "-point FFT at frame " + 91 let message = "Smoothed " + analyser.fftSize + "-point FFT at frame " +
93 (context.currentTime * sampleRate); 92 (context.currentTime * sampleRate);
94 var comparison = compareFloatFreq(message, 93 let comparison = compareFloatFreq(message,
95 freqDataInDb, smoothedFloatResult.map(linearToDb), should, { 94 freqDataInDb, smoothedFloatResult.map(linearToDb), should, {
96 order: options.order, 95 order: options.order,
97 smoothing: options.smoothing, 96 smoothing: options.smoothing,
98 floatRelError: 2.5332e-5 97 floatRelError: 2.5332e-5
99 }); 98 });
100 success = success && comparison.success; 99 success = success && comparison.success;
101 100
102 // Test the byte frequency data. 101 // Test the byte frequency data.
103 var byteFreqData = new Uint8Array(analyser.frequencyBinCount); 102 let byteFreqData = new Uint8Array(analyser.frequencyBinCount);
104 var expectedByteData = new Float32Array(analyser.frequencyBinCount);
105 analyser.getByteFrequencyData(byteFreqData); 103 analyser.getByteFrequencyData(byteFreqData);
106 104
107 // Convert the expected float frequency data to byte data. 105 // Convert the expected float frequency data to byte data.
108 var expectedByteData = convertFloatToByte(smoothedFloatResult.map(line arToDb), 106 let expectedByteData = convertFloatToByte(smoothedFloatResult.map(line arToDb),
109 analyser.minDecibels, analyser.maxDecibels); 107 analyser.minDecibels, analyser.maxDecibels);
110 108
111 should(byteFreqData, analyser.fftSize + "-point byte FFT") 109 should(byteFreqData, analyser.fftSize + "-point byte FFT")
112 .beCloseToArray(expectedByteData, 0); 110 .beCloseToArray(expectedByteData, 0);
113 111
114 }).then(context.resume.bind(context)); 112 }).then(context.resume.bind(context));
115 113
116 context.startRendering().then(() => task.done()); 114 context.startRendering().then(() => task.done());
117 }); 115 });
118 116
119 audit.run(); 117 audit.run();
120 118
121 </script> 119 </script>
122 </body> 120 </body>
123 </html> 121 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698