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

Side by Side Diff: third_party/WebKit/LayoutTests/webaudio/resources/audit-util.js

Issue 2728613003: Add support creating and saving a new reference file. (Closed)
Patch Set: Address review comments. Created 3 years, 9 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 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 5
6 /** 6 /**
7 * @fileOverview This file includes legacy utility functions for the layout 7 * @fileOverview This file includes legacy utility functions for the layout
8 * test. 8 * test.
9 */ 9 */
10 10
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 function createAudioData(audioBuffer) { 102 function createAudioData(audioBuffer) {
103 return createWaveFileData(audioBuffer); 103 return createWaveFileData(audioBuffer);
104 } 104 }
105 105
106 function finishAudioTest(event) { 106 function finishAudioTest(event) {
107 var audioData = createAudioData(event.renderedBuffer); 107 var audioData = createAudioData(event.renderedBuffer);
108 testRunner.setAudioData(audioData); 108 testRunner.setAudioData(audioData);
109 testRunner.notifyDone(); 109 testRunner.notifyDone();
110 } 110 }
111 111
112 // Save the given |audioBuffer| to a 16-bit WAV file using the name
113 // given by |filename|. This is intended to be run from a browser.
114 // The developer is expected to use the console to run
115 // downloadAudioBuffer when necessary to create a new reference file
116 // for a test.
117 function downloadAudioBuffer(audioBuffer, filename) {
118 // Convert the audio buffer to an array containing the WAV file
119 // contents. Then convert it to a blob that can be saved as a WAV
120 // file.
121 let wavData = createAudioData(audioBuffer);
122 let blob = new Blob([wavData], {type: 'audio/wav'});
123 // Manually create html tags for downloading, and simulate a click
124 // to download the file to the given file name.
125 let a = document.createElement('a');
126 a.style.display = 'none';
127 a.download = filename;
128 let audioURL = window.URL.createObjectURL(blob);
129 let audio = new Audio();
130 audio.src = audioURL;
131 a.href = audioURL;
132 document.body.appendChild(a);
133 a.click();
134 }
135
112 // Compare two arrays (commonly extracted from buffer.getChannelData()) with 136 // Compare two arrays (commonly extracted from buffer.getChannelData()) with
113 // constraints: 137 // constraints:
114 // options.thresholdSNR: Minimum allowed SNR between the actual and expected 138 // options.thresholdSNR: Minimum allowed SNR between the actual and expected
115 // signal. The default value is 10000. 139 // signal. The default value is 10000.
116 // options.thresholdDiffULP: Maximum allowed difference between the actual 140 // options.thresholdDiffULP: Maximum allowed difference between the actual
117 // and expected signal in ULP(Unit in the last place). The default is 0. 141 // and expected signal in ULP(Unit in the last place). The default is 0.
118 // options.thresholdDiffCount: Maximum allowed number of sample differences 142 // options.thresholdDiffCount: Maximum allowed number of sample differences
119 // which exceeds the threshold. The default is 0. 143 // which exceeds the threshold. The default is 0.
120 // options.bitDepth: The expected result is assumed to come from an audio 144 // options.bitDepth: The expected result is assumed to come from an audio
121 // file with this number of bits of precision. The default is 16. 145 // file with this number of bits of precision. The default is 16.
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
268 var length = Math.min(actual.length, expected.length); 292 var length = Math.min(actual.length, expected.length);
269 293
270 for (var k = 0; k < length; ++k) { 294 for (var k = 0; k < length; ++k) {
271 var diff = actual[k] - expected[k]; 295 var diff = actual[k] - expected[k];
272 signalPower += expected[k] * expected[k]; 296 signalPower += expected[k] * expected[k];
273 noisePower += diff * diff; 297 noisePower += diff * diff;
274 } 298 }
275 299
276 return signalPower / noisePower; 300 return signalPower / noisePower;
277 } 301 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698