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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/Analyser/realtimeanalyser-multiple-calls.html

Issue 2777983002: Convert Analyser tests to use new Audit. (Closed)
Patch Set: Rebase 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
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 Multiple Calls to getFloatFrequencyData</title> 8 <title>Test Multiple Calls to getFloatFrequencyData</title>
9 </head> 9 </head>
10 10
11 <body> 11 <body>
12 <script> 12 <script>
13 var sampleRate = 48000; 13 var sampleRate = 48000;
14 // Render enough data to run the test. 14 // Render enough data to run the test.
15 var renderFrames = 2*1024; 15 var renderFrames = 2*1024;
16 var renderDuration = renderFrames / sampleRate; 16 var renderDuration = renderFrames / sampleRate;
17 17
18 var audit = Audit.createTaskRunner(); 18 var audit = Audit.createTaskRunner();
19 19
20 audit.defineTask("test", function (done) { 20 audit.define("test", (task, should) => {
21 21
22 var context = new OfflineAudioContext(1, renderFrames, sampleRate); 22 var context = new OfflineAudioContext(1, renderFrames, sampleRate);
23 23
24 // Use sawtooth oscillator as the source because it has quite a bit of h armonic content. 24 // Use sawtooth oscillator as the source because it has quite a bit of h armonic content.
25 // Otherwise, the type doesn't really matter. 25 // Otherwise, the type doesn't really matter.
26 var osc = context.createOscillator(); 26 var osc = context.createOscillator();
27 osc.type = "sawtooth"; 27 osc.type = "sawtooth";
28 28
29 // Create an analyser with 256-point FFT. The FFT size doesn't really m atter much. 29 // Create an analyser with 256-point FFT. The FFT size doesn't really m atter much.
30 var analyser = context.createAnalyser(); 30 var analyser = context.createAnalyser();
31 analyser.fftSize = 256; 31 analyser.fftSize = 256;
32 32
33 osc.connect(analyser); 33 osc.connect(analyser);
34 analyser.connect(context.destination); 34 analyser.connect(context.destination);
35 35
36 var success = true; 36 var success = true;
37 37
38 // Suspend after getting a full analyser frame. (Not really necessary, b ut it's nice that 38 // Suspend after getting a full analyser frame. (Not really necessary, b ut it's nice that
39 // the frame doesn't include any initial zeroes. 39 // the frame doesn't include any initial zeroes.
40 var suspendFrame = analyser.fftSize; 40 var suspendFrame = analyser.fftSize;
41 context.suspend(suspendFrame / sampleRate).then(function () { 41 context.suspend(suspendFrame / sampleRate).then(function () {
42 // Test successive calls to getFloatFrequencyData in the same renderin g quantum. 42 // Test successive calls to getFloatFrequencyData in the same renderin g quantum.
43 var f1 = new Float32Array(analyser.frequencyBinCount); 43 let f1 = new Float32Array(analyser.frequencyBinCount);
44 var f2 = new Float32Array(analyser.frequencyBinCount); 44 let f2 = new Float32Array(analyser.frequencyBinCount);
45 45
46 analyser.getFloatFrequencyData(f1); 46 analyser.getFloatFrequencyData(f1);
47 analyser.getFloatFrequencyData(f2); 47 analyser.getFloatFrequencyData(f2);
48 48 should(f2, "Second call to getFloatFrequencyData")
49 success = Should("Second call to getFloatFrequencyData", f2, { 49 .beEqualToArray(f1);
50 precision: 5
51 }).beEqualToArray(f1) && success;
52 }).then(context.resume.bind(context)); 50 }).then(context.resume.bind(context));
53 51
54 suspendFrame += 128; 52 suspendFrame += 128;
55 context.suspend(suspendFrame / sampleRate).then(function () { 53 context.suspend(suspendFrame / sampleRate).then(function () {
56 // Test successive calls to getByteFrequencyData in the same rendering quantum. 54 // Test successive calls to getByteFrequencyData in the same rendering quantum.
57 var f1 = new Uint8Array(analyser.frequencyBinCount); 55 let f1 = new Uint8Array(analyser.frequencyBinCount);
58 var f2 = new Uint8Array(analyser.frequencyBinCount); 56 let f2 = new Uint8Array(analyser.frequencyBinCount);
59 57
60 analyser.getByteFrequencyData(f1); 58 analyser.getByteFrequencyData(f1);
61 analyser.getByteFrequencyData(f2); 59 analyser.getByteFrequencyData(f2);
62 60
63 success = Should("Second call to getByteFrequencyData", f2) 61 console.log("f1");
64 .beEqualToArray(f1) && success; 62 console.log(f1);
63 console.log("f2");
64 console.log(f2);
hongchan 2017/03/29 21:07:02 Remove all the console.logs.
Raymond Toy 2017/03/29 21:44:31 Heh. This is how I found out beEqualToArray didn't
65 should(f2, "Second call to getByteFrequencyData")
66 .beEqualToArray(f1);
65 }).then(context.resume.bind(context)); 67 }).then(context.resume.bind(context));
66 68
67 suspendFrame += 128; 69 suspendFrame += 128;
68 context.suspend(suspendFrame / sampleRate).then(function () { 70 context.suspend(suspendFrame / sampleRate).then(function () {
69 // Test calls to getFloatFrequencyData followed by getByteFrequencyDat a. The float data, 71 // Test calls to getFloatFrequencyData followed by getByteFrequencyDat a. The float data,
70 // when converted to byte values should be identical to the result fro m 72 // when converted to byte values should be identical to the result fro m
71 // getByteFrequencyData. 73 // getByteFrequencyData.
72 var f1 = new Float32Array(analyser.frequencyBinCount); 74 let f1 = new Float32Array(analyser.frequencyBinCount);
73 var f2 = new Uint8Array(analyser.frequencyBinCount); 75 let f2 = new Uint8Array(analyser.frequencyBinCount);
74 76
75 analyser.getFloatFrequencyData(f1); 77 analyser.getFloatFrequencyData(f1);
76 analyser.getByteFrequencyData(f2); 78 analyser.getByteFrequencyData(f2);
77 79
78 var byteValuesFromFloat = convertFloatToByte(f1, analyser.minDecibels, analyser.maxDecibels); 80 var byteValuesFromFloat = convertFloatToByte(f1, analyser.minDecibels, analyser.maxDecibels);
79 success = Should("Output of getByteFrequencyData after getFloatFrequen cyData", 81 should(byteValuesFromFloat, "Output of getByteFrequencyData after getF loatFrequencyData")
80 byteValuesFromFloat) 82 .beEqualToArray(f2);
81 .beEqualToArray(f2) && success;
82 }).then(context.resume.bind(context)); 83 }).then(context.resume.bind(context));
83 84
84 suspendFrame += 128; 85 suspendFrame += 128;
85 context.suspend(suspendFrame / sampleRate).then(function () { 86 context.suspend(suspendFrame / sampleRate).then(function () {
86 // Test calls to getByteFrequencyData followed by getFloatFrequencyDat a. The float data, 87 // Test calls to getByteFrequencyData followed by getFloatFrequencyDat a. The float data,
87 // when converted to byte values should be identical to the result fro m 88 // when converted to byte values should be identical to the result fro m
88 // getByteFrequencyData. 89 // getByteFrequencyData.
89 var f1 = new Uint8Array(analyser.frequencyBinCount); 90 var f1 = new Uint8Array(analyser.frequencyBinCount);
90 var f2 = new Float32Array(analyser.frequencyBinCount); 91 var f2 = new Float32Array(analyser.frequencyBinCount);
91 92
92 analyser.getByteFrequencyData(f1); 93 analyser.getByteFrequencyData(f1);
93 analyser.getFloatFrequencyData(f2); 94 analyser.getFloatFrequencyData(f2);
94 95
95 var byteValuesFromFloat = convertFloatToByte(f2, analyser.minDecibels, analyser.maxDecibels); 96 var byteValuesFromFloat = convertFloatToByte(f2, analyser.minDecibels, analyser.maxDecibels);
96 success = Should( 97 should(f1,
97 "Output of getFloatFrequenycData (converted to byte) after getByte FrequencyData", 98 "Output of getFloatFrequenycData (converted to byte) after getByte FrequencyData")
98 f1) 99 .beEqualToArray(byteValuesFromFloat);
99 .beEqualToArray(byteValuesFromFloat) && success;
100 }).then(context.resume.bind(context)); 100 }).then(context.resume.bind(context));
101 101
102 osc.start(); 102 osc.start();
103 context.startRendering().then(done); 103 context.startRendering().then(() => task.done());
104 }); 104 });
105 105
106 audit.defineTask("finish", function (done) { 106 audit.run();
107 done();
108 });
109
110 audit.runTasks();
111 107
112 // Convert the float frequency data (in dB), |floatFreqData|, to byte valu es using the dB 108 // Convert the float frequency data (in dB), |floatFreqData|, to byte valu es using the dB
113 // limits |minDecibels| and |maxDecibels|. The new byte array is returned . 109 // limits |minDecibels| and |maxDecibels|. The new byte array is returned .
114 function convertFloatToByte(floatFreqData, minDecibels, maxDecibels) { 110 function convertFloatToByte(floatFreqData, minDecibels, maxDecibels) {
115 var scale = 255 / (maxDecibels - minDecibels); 111 var scale = 255 / (maxDecibels - minDecibels);
116 112
117 return floatFreqData.map(function (x) { 113 return floatFreqData.map(function (x) {
118 var value = Math.floor(scale * (x - minDecibels)); 114 var value = Math.floor(scale * (x - minDecibels));
119 return Math.min(255, Math.max(0, value)); 115 return Math.min(255, Math.max(0, value));
120 }); 116 });
121 } 117 }
122 </script> 118 </script>
123 </body> 119 </body>
124 </html> 120 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698