| OLD | NEW |
| 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 Loading... |
| 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 // Don't download if testRunner is defined; we're running a layout |
| 119 // test where this won't be useful in general. |
| 120 if (window.testRunner) |
| 121 return false; |
| 122 // Convert the audio buffer to an array containing the WAV file |
| 123 // contents. Then convert it to a blob that can be saved as a WAV |
| 124 // file. |
| 125 let wavData = createAudioData(audioBuffer); |
| 126 let blob = new Blob([wavData], {type: 'audio/wav'}); |
| 127 // Manually create html tags for downloading, and simulate a click |
| 128 // to download the file to the given file name. |
| 129 let a = document.createElement('a'); |
| 130 a.style.display = 'none'; |
| 131 a.download = filename; |
| 132 let audioURL = window.URL.createObjectURL(blob); |
| 133 let audio = new Audio(); |
| 134 audio.src = audioURL; |
| 135 a.href = audioURL; |
| 136 document.body.appendChild(a); |
| 137 a.click(); |
| 138 return true; |
| 139 } |
| 140 |
| 112 // Compare two arrays (commonly extracted from buffer.getChannelData()) with | 141 // Compare two arrays (commonly extracted from buffer.getChannelData()) with |
| 113 // constraints: | 142 // constraints: |
| 114 // options.thresholdSNR: Minimum allowed SNR between the actual and expected | 143 // options.thresholdSNR: Minimum allowed SNR between the actual and expected |
| 115 // signal. The default value is 10000. | 144 // signal. The default value is 10000. |
| 116 // options.thresholdDiffULP: Maximum allowed difference between the actual | 145 // options.thresholdDiffULP: Maximum allowed difference between the actual |
| 117 // and expected signal in ULP(Unit in the last place). The default is 0. | 146 // and expected signal in ULP(Unit in the last place). The default is 0. |
| 118 // options.thresholdDiffCount: Maximum allowed number of sample differences | 147 // options.thresholdDiffCount: Maximum allowed number of sample differences |
| 119 // which exceeds the threshold. The default is 0. | 148 // which exceeds the threshold. The default is 0. |
| 120 // options.bitDepth: The expected result is assumed to come from an audio | 149 // 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. | 150 // file with this number of bits of precision. The default is 16. |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 var length = Math.min(actual.length, expected.length); | 297 var length = Math.min(actual.length, expected.length); |
| 269 | 298 |
| 270 for (var k = 0; k < length; ++k) { | 299 for (var k = 0; k < length; ++k) { |
| 271 var diff = actual[k] - expected[k]; | 300 var diff = actual[k] - expected[k]; |
| 272 signalPower += expected[k] * expected[k]; | 301 signalPower += expected[k] * expected[k]; |
| 273 noisePower += diff * diff; | 302 noisePower += diff * diff; |
| 274 } | 303 } |
| 275 | 304 |
| 276 return signalPower / noisePower; | 305 return signalPower / noisePower; |
| 277 } | 306 } |
| OLD | NEW |