Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/webaudio/AudioBuffer/audiobuffer-resample.html |
| diff --git a/third_party/WebKit/LayoutTests/webaudio/AudioBuffer/audiobuffer-resample.html b/third_party/WebKit/LayoutTests/webaudio/AudioBuffer/audiobuffer-resample.html |
| index d45aa6cd78aa1c4a3cc787418641ef178cd519bd..bb306754ae4b501e60c0db9208349df7067dc547 100644 |
| --- a/third_party/WebKit/LayoutTests/webaudio/AudioBuffer/audiobuffer-resample.html |
| +++ b/third_party/WebKit/LayoutTests/webaudio/AudioBuffer/audiobuffer-resample.html |
| @@ -1,140 +1,113 @@ |
| <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|
hongchan
2017/01/04 00:38:12
If this file includes manual changes, please simpl
Raymond Toy
2017/01/04 19:05:02
Done.
|
| <html> |
| <head> |
| - <script src="../../resources/js-test.js"></script> |
| + <script src="../../resources/testharness.js"></script> |
| + <script src="../../resources/testharnessreport.js"></script> |
| <script src="../resources/audit-util.js"></script> |
| - <script src="../resources/audio-testing.js"></script> |
| + <script src="../resources/audit.js"></script> |
| </head> |
| <body> |
| - <div id="description"></div> |
| - <div id="console"></div> |
| - |
| <script> |
| + let audit = Audit.createTaskRunner(); |
| + |
| // These are global to make debugging a little easier. |
| - var context; |
| - var buffer; |
| - var source; |
| - var renderedData; |
| - var trueData; |
| - var signalEnergy; |
| - var noiseEnergy; |
| - var maxError; |
| + let context; |
| + let buffer; |
| + let source; |
| + let renderedData; |
| + let trueData; |
| + let signalEnergy; |
| + let noiseEnergy; |
| + let maxError; |
| // Context sample rate. |
| - var sampleRate = 48000; |
| + let sampleRate = 48000; |
| // The sample rate of the buffer. |
| - var bufferRate = 3000; |
| + let bufferRate = 3000; |
| // The audio buffer is a sine wave of this frequency. |
| - var toneFrequency = 440; |
| + let toneFrequency = 440; |
| // How long test is |
| - var lengthInSeconds = 0.5; |
| - // The maximum allowed peak error between the actual and true output. This value was |
| - // experimentally determined for the given bufferRate. |
| - var peakThreshold = 0.11; |
| + let lengthInSeconds = 0.5; |
| + // The maximum allowed peak error between the actual and true output. This |
| + // value was experimentally determined for the given bufferRate. |
| + let peakThreshold = 0.11; |
| // The minimum SNR allowed between the actual and true output. |
| - var snrThreshold = 22.35; |
| + let snrThreshold = 22.35; |
| - description("Test resampling of an AudioBuffer at " + bufferRate + " Hz"); |
| - function log10(x) { |
| - return Math.log(x)/Math.LN10; |
| - } |
| - |
| - // Generate a sine wave in an AudioBuffer using the given |freq|. The AudioBuffer has the |
| - // sample rate of |rate|. |
| + // Generate a sine wave in an AudioBuffer using the given |freq|. The |
| + // AudioBuffer has the sample rate of |rate|. |
| function createSineBuffer(context, freq, rate) { |
| - var buf = context.createBuffer(1, lengthInSeconds * rate, rate); |
| - var omega = 2 * Math.PI * freq / rate; |
| - var signal = buf.getChannelData(0); |
| - var length = signal.length; |
| - for (var k = 0; k < length; ++k) |
| - signal[k] = Math.sin(omega * k); |
| - |
| - return buf; |
| + let buf = context.createBuffer(1, lengthInSeconds * rate, rate); |
| + let omega = 2 * Math.PI * freq / rate; |
| + let signal = buf.getChannelData(0); |
| + let length = signal.length; |
| + for (let k = 0; k < length; ++k) |
| + signal[k] = Math.sin(omega * k); |
| + |
| + return buf; |
| } |
| // Check the output against the expected output. |
| - function checkResult(event) { |
| - renderedData = event.renderedBuffer.getChannelData(0); |
| - var length = renderedData.length; |
| - // Generate a reference sine wave at the context rate |
| - var trueReference = createSineBuffer(context, toneFrequency, context.sampleRate); |
| - trueData = trueReference.getChannelData(0); |
| - |
| - // To compare the actual output against the reference, we compute the peak error and the |
| - // SNR between the two. |
| - signalEnergy = 0; |
| - noiseEnergy = 0; |
| - maxError = -1; |
| - |
| - var success = true; |
| - |
| - // Compute the peak error and the SNR. |
| - for (var k = 0; k < length / 2; ++k) { |
| - var diff = renderedData[k] - trueData[k]; |
| - noiseEnergy += diff * diff; |
| - signalEnergy += trueData[k] * trueData[k]; |
| - if (Math.abs(diff) > maxError) |
| - maxError = Math.abs(diff); |
| - } |
| - |
| - var snr; |
| - |
| - if (noiseEnergy == 0) |
| - snr = 1000; |
| - else |
| - snr = 10 * log10(signalEnergy / noiseEnergy); |
| - |
| - if (maxError < peakThreshold) { |
| - testPassed("Peak error between actual and reference data below threshold of " + |
| - peakThreshold + "."); |
| - } else { |
| - testFailed("Peak error of " + maxError + " exceeds threshold of " + |
| - peakThreshold + "."); |
| - success = false; |
| - } |
| - |
| - if (snr > snrThreshold) { |
| - testPassed("SNR exceeds threshold of " + snrThreshold + " dB."); |
| - } else { |
| - testFailed("SNR of " + snr + " is below the threshold of " + snrThreshold + "."); |
| - success = false; |
| - } |
| - |
| - if (success) |
| - testPassed("AudioBuffer resampling is accurate for buffer rate of " + |
| - bufferRate + " Hz."); |
| - else |
| - testFailed("AudioBuffer resampling is not accurate enough for buffer rate of " + |
| - bufferRate + " Hz."); |
| - |
| - finishJSTest(); |
| + function checkResult(buffer, should) { |
| + renderedData = buffer.getChannelData(0); |
| + let length = renderedData.length; |
| + // Generate a reference sine wave at the context rate |
| + let trueReference = createSineBuffer(context, toneFrequency, context.sampleRate); |
| + trueData = trueReference.getChannelData(0); |
| + |
| + // To compare the actual output against the reference, we compute the |
| + // peak error and the SNR between the two. |
| + signalEnergy = 0; |
| + noiseEnergy = 0; |
| + maxError = -1; |
| + |
| + let success = true; |
| + |
| + // Compute the peak error and the SNR. |
| + for (let k = 0; k < length / 2; ++k) { |
| + let diff = renderedData[k] - trueData[k]; |
| + noiseEnergy += diff * diff; |
| + signalEnergy += trueData[k] * trueData[k]; |
| + if (Math.abs(diff) > maxError) |
| + maxError = Math.abs(diff); |
| + } |
| + |
| + let snr; |
| + |
| + if (noiseEnergy == 0) |
| + snr = 1000; |
| + else |
| + snr = 10 * Math.log10(signalEnergy / noiseEnergy); |
| + |
| + should(maxError, "Peak error between actual and reference data") |
| + .beLessThan(peakThreshold); |
|
hongchan
2017/01/04 00:38:12
It looks like the new audit pays off. Happy to hav
Raymond Toy
2017/01/04 19:05:02
To be fair, the old Audit would have simplified th
|
| + |
| + should(snr, "SNR") |
| + .beGreaterThan(snrThreshold); |
| } |
| - function runTest() { |
| - if (window.testRunner) { |
| - testRunner.dumpAsText(); |
| - testRunner.waitUntilDone(); |
| - } |
| - |
| - window.jsTestIsAsync = true; |
| - |
| - context = new OfflineAudioContext(1, lengthInSeconds * sampleRate, sampleRate); |
| - |
| - // Create a sine wave in a buffer that's different from the context rate to test |
| - // resampling. |
| - buffer = createSineBuffer(context, toneFrequency, bufferRate); |
| - source = context.createBufferSource(); |
| - source.buffer = buffer; |
| - source.connect(context.destination); |
| - source.start(); |
| - |
| - context.oncomplete = checkResult; |
| - context.startRendering(); |
| - } |
| - runTest(); |
| - successfullyParsed = true; |
| + audit.define("Test resampling of an AudioBuffer", function (task, should) { |
|
hongchan
2017/01/04 00:38:12
Please wrap this line.
Raymond Toy
2017/01/04 19:05:03
Done.
|
| + context = new OfflineAudioContext(1, lengthInSeconds * sampleRate, |
| + sampleRate); |
| + |
| + // Create a sine wave in a buffer that's different from the context rate to test |
|
hongchan
2017/01/04 00:38:12
ditto.
Raymond Toy
2017/01/04 19:05:02
Done.
|
| + // resampling. |
| + buffer = createSineBuffer(context, toneFrequency, bufferRate); |
| + source = context.createBufferSource(); |
| + source.buffer = buffer; |
| + source.connect(context.destination); |
| + source.start(); |
| + |
| + context.startRendering() |
| + .then(function (buffer) { |
| + checkResult(buffer, should); |
| + }) |
| + .then(task.done.bind(task)); |
| + }); |
| + |
| + audit.run(); |
| </script> |
| </body> |
| </html> |