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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/Gain/gain.html

Issue 2671883002: Convert GainNode tests to testharness (Closed)
Patch Set: Address review comments. Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/Gain/gain-basic.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/webaudio/Gain/gain.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/Gain/gain.html b/third_party/WebKit/LayoutTests/webaudio/Gain/gain.html
index 0a6c2b8f568885e7a9b60158c31f58a5f6838db1..bc66ed6c431b680c4eb4d1b8eae0cda8d081dccf 100644
--- a/third_party/WebKit/LayoutTests/webaudio/Gain/gain.html
+++ b/third_party/WebKit/LayoutTests/webaudio/Gain/gain.html
@@ -8,77 +8,105 @@ The 11th note will be of gain 0.0, so it should be silent (at the end in the ren
<html>
<head>
+<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>
+<script src="../resources/buffer-loader.js"></script>
</head>
<body>
<script>
+let audit = Audit.createTaskRunner();
-window.onload = init;
-
-var sampleRate = 44100.0;
-var bufferDurationSeconds = 0.125;
-var numberOfNotes = 11;
-var noteSpacing = bufferDurationSeconds + 0.020; // leave 20ms of silence between each "note"
-var lengthInSeconds = numberOfNotes * noteSpacing;
+let sampleRate = 44100.0;
+let bufferDurationSeconds = 0.125;
+let numberOfNotes = 11;
+let noteSpacing =
+ bufferDurationSeconds + 0.020; // leave 20ms of silence between each "note"
+let lengthInSeconds = numberOfNotes * noteSpacing;
-var context = 0;
-var sinWaveBuffer = 0;
+let context = 0;
+let sinWaveBuffer = 0;
+let reference = 0;
function createSinWaveBuffer(lengthInSeconds, frequency) {
- var audioBuffer = context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);
+ let audioBuffer =
+ context.createBuffer(2, lengthInSeconds * sampleRate, sampleRate);
- var n = audioBuffer.length;
- var channelL = audioBuffer.getChannelData(0);
- var channelR = audioBuffer.getChannelData(1);
+ let n = audioBuffer.length;
+ let channelL = audioBuffer.getChannelData(0);
+ let channelR = audioBuffer.getChannelData(1);
- for (var i = 0; i < n; ++i) {
- channelL[i] = Math.sin(frequency * 2.0*Math.PI * i / sampleRate);
- channelR[i] = channelL[i];
- }
+ for (let i = 0; i < n; ++i) {
+ channelL[i] = Math.sin(frequency * 2.0 * Math.PI * i / sampleRate);
+ channelR[i] = channelL[i];
+ }
- return audioBuffer;
+ return audioBuffer;
}
function playNote(time, gain) {
- var source = context.createBufferSource();
- source.buffer = sinWaveBuffer;
-
- var gainNode = context.createGain();
- gainNode.gain.value = gain;
-
- source.connect(gainNode);
- gainNode.connect(context.destination);
-
- source.start(time);
-}
-
-function init() {
- if (!window.testRunner)
- return;
-
- // Create offline audio context.
- context = new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
-
- // Create a buffer for a short "note".
- sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0);
+ let source = context.createBufferSource();
+ source.buffer = sinWaveBuffer;
- // Render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1.
- // The last note will be of gain 0.0, so shouldn't be perceptible in the rendered output.
- for (var i = 0; i < numberOfNotes; ++i) {
- var time = i * noteSpacing;
- var gain = 1.0 - i / (numberOfNotes - 1);
- playNote(time, gain);
- }
+ let gainNode = context.createGain();
+ gainNode.gain.value = gain;
- context.oncomplete = finishAudioTest;
- context.startRendering();
+ source.connect(gainNode);
+ gainNode.connect(context.destination);
- testRunner.waitUntilDone();
+ source.start(time);
}
+audit.define('create context', function(task, should) {
+ task.describe('Create context for test');
+ // Create offline audio context.
+ context =
+ new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate);
+ task.done();
+});
+
+audit.define('load-ref', function(task, should) {
+ task.describe('Load reference audio file');
+ let bufferLoader =
+ new BufferLoader(context, ['gain-expected.wav'], bufferList => {
+ reference = bufferList[0].getChannelData(0);
+ task.done();
+ });
+
+ bufferLoader.load();
+});
+
+audit.define('test', function(task, should) {
+ task.describe('GainNode functionality');
+
+ // Create a buffer for a short "note".
+ sinWaveBuffer = createSinWaveBuffer(bufferDurationSeconds, 880.0);
+
+ // Render 11 notes, starting at a gain of 1.0, decreasing in gain by 0.1.
+ // The last note will be of gain 0.0, so shouldn't be perceptible in the
+ // rendered output.
+ for (let i = 0; i < numberOfNotes; ++i) {
+ let time = i * noteSpacing;
+ let gain = 1.0 - i / (numberOfNotes - 1);
+ playNote(time, gain);
+ }
+
+ context.startRendering()
+ .then(buffer => {
+ let actual = buffer.getChannelData(0);
+ should(actual, 'Output from gain node').beCloseToArray(reference, {
+ absoluteThreshold: 3.0503e-5
+ });
+ let snr = 10 * Math.log10(computeSNR(actual, reference));
+ should(snr, 'SNR (in dB)').beGreaterThanOrEqualTo(89.088);
+ })
+ .then(() => task.done());
+ ;
+});
+
+audit.run();
</script>
</body>
« no previous file with comments | « no previous file | third_party/WebKit/LayoutTests/webaudio/Gain/gain-basic.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698