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

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

Issue 2777983002: Convert Analyser tests to use new Audit. (Closed)
Patch Set: Remove console.logs Created 3 years, 8 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-downmix.html » ('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> 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/audio-testing.js"></script> 7 <script src="../resources/audit.js"></script>
8 <title>Test Analyser.getByteTimeDomainData()</title> 8 <title>Test Analyser.getByteTimeDomainData()</title>
9 </head> 9 </head>
10 10
11 <body> 11 <body>
12 <script> 12 <script>
13 var sampleRate = 48000; 13 var sampleRate = 48000;
14 // The size of the analyser frame. Anything larger than 128 is ok, but sh ould be long enough 14 // The size of the analyser frame. Anything larger than 128 is ok, but sh ould be long enough
15 // to capture the peaks of the oscillator waveform. 15 // to capture the peaks of the oscillator waveform.
16 var fftSize = 256; 16 var fftSize = 256;
17 // Number of frames to render. Should be greater than the fftSize, but is otherwise 17 // Number of frames to render. Should be greater than the fftSize, but is otherwise
18 // arbitrary. 18 // arbitrary.
19 var renderFrames = 2 * fftSize; 19 var renderFrames = 2 * fftSize;
20 20
21 var audit = Audit.createTaskRunner(); 21 var audit = Audit.createTaskRunner();
22 22
23 // Test that getByteTimeDomainData returns the correct values. This test depends on 23 // Test that getByteTimeDomainData returns the correct values. This test depends on
24 // getFloatTimeDomainData returning the correct data (for which there is a lready a test). 24 // getFloatTimeDomainData returning the correct data (for which there is a lready a test).
25 audit.defineTask("byte-data", function (done) { 25 audit.define("byte-data", (task, should) => {
26 var context = new OfflineAudioContext(1, renderFrames, sampleRate); 26 var context = new OfflineAudioContext(1, renderFrames, sampleRate);
27 27
28 // Create a sawtooth as the signal under test. A sine wave or triangle wave would probably 28 // Create a sawtooth as the signal under test. A sine wave or triangle wave would probably
29 // also work. 29 // also work.
30 var src = context.createOscillator(); 30 var src = context.createOscillator();
31 src.type = "sawtooth"; 31 src.type = "sawtooth";
32 // Choose a frequency high enough that we get at least a full period in one analyser fftSize 32 // Choose a frequency high enough that we get at least a full period in one analyser fftSize
33 // frame. Otherwise, the frequency is arbitrary. 33 // frame. Otherwise, the frequency is arbitrary.
34 src.frequency.value = 440; 34 src.frequency.value = 440;
35 35
(...skipping 26 matching lines...) Expand all
62 var value = Math.fround(128 * Math.fround(1 + floatData[k])); 62 var value = Math.fround(128 * Math.fround(1 + floatData[k]));
63 // Clip the result to lie in the range [0, 255]. 63 // Clip the result to lie in the range [0, 255].
64 expected[k] = Math.floor(Math.min(255, Math.max(0, value))); 64 expected[k] = Math.floor(Math.min(255, Math.max(0, value)));
65 } 65 }
66 66
67 // Find the first index of the first sample that exceeds +1 or -1. Th e test MUST have at 67 // Find the first index of the first sample that exceeds +1 or -1. Th e test MUST have at
68 // least one such value. 68 // least one such value.
69 var indexMax = floatData.findIndex(function (x) { return x > 1; }); 69 var indexMax = floatData.findIndex(function (x) { return x > 1; });
70 var indexMin = floatData.findIndex(function (x) { return x < -1; }); 70 var indexMin = floatData.findIndex(function (x) { return x < -1; });
71 71
72 Should("Index of first sample greater than +1", indexMax, { 72 should(indexMax, "Index of first sample greater than +1").beGreaterTha nOrEqualTo(0);
73 brief: true 73 should(indexMin, "Index of first sample less than -1").beGreaterThanOr EqualTo(0);
74 }).beGreaterThanOrEqualTo(0);
75 Should("Index of first sample less than -1", indexMin, {
76 brief: true
77 }).beGreaterThanOrEqualTo(0);
78 74
79 // Verify explicitly that clipping happened correctly at the above ind ices. 75 // Verify explicitly that clipping happened correctly at the above ind ices.
80 Should("Clip " + floatData[indexMax].toPrecision(6) + ": byteData[" + indexMax + "]", 76 should(
81 byteData[indexMax]).beEqualTo(255); 77 byteData[indexMax],
82 Should("Clip " + floatData[indexMin].toPrecision(6) + ": byteData[" + indexMin + "]", 78 "Clip " + floatData[indexMax].toPrecision(6) + ": byteData[" +
83 byteData[indexMin]).beEqualTo(0); 79 indexMax + "]").beEqualTo(255);
80 should(
81 byteData[indexMin],
82 "Clip " + floatData[indexMin].toPrecision(6) + ": byteData[" +
83 indexMin + "]").beEqualTo(0);
84 84
85 // Verify that all other samples are computed correctly. 85 // Verify that all other samples are computed correctly.
86 Should("Byte data", byteData).beEqualToArray(expected); 86 should(byteData, "Byte data").beEqualToArray(expected);
87 }).then(context.resume.bind(context)) 87 }).then(context.resume.bind(context))
88 88
89 src.start(); 89 src.start();
90 context.startRendering().then(done); 90 context.startRendering().then(() => task.done());
91 }); 91 });
92 92
93 audit.defineTask("finish", function (done) { 93 audit.run();
94 done();
95 });
96
97 audit.runTasks();
98 </script> 94 </script>
99 </body> 95 </body>
100 </html> 96 </html>
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-downmix.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698