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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/resources/note-grain-on-testing.js

Issue 2594183003: Convert note-grain-on tests to testharness (Closed)
Patch Set: Address review comments and git cl format Created 3 years, 11 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 | « third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-timing-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/LayoutTests/webaudio/resources/note-grain-on-testing.js
diff --git a/third_party/WebKit/LayoutTests/webaudio/resources/note-grain-on-testing.js b/third_party/WebKit/LayoutTests/webaudio/resources/note-grain-on-testing.js
index 8f93c9edfaf32a128cfadd01fc716513db901642..f19d57e245062dcecda99f33316fecd8819f1a5a 100644
--- a/third_party/WebKit/LayoutTests/webaudio/resources/note-grain-on-testing.js
+++ b/third_party/WebKit/LayoutTests/webaudio/resources/note-grain-on-testing.js
@@ -1,30 +1,30 @@
-var sampleRate = 44100.0;
+let sampleRate = 44100.0;
// HRTF extra frames. This is a magic constant currently in
// AudioBufferSourceNode::process that always extends the
// duration by this number of samples. See bug 77224
// (https://bugs.webkit.org/show_bug.cgi?id=77224).
-var extraFramesHRTF = 512;
+let extraFramesHRTF = 512;
// How many grains to play.
-var numberOfTests = 100;
+let numberOfTests = 100;
// Duration of each grain to be played
-var duration = 0.01;
+let duration = 0.01;
// Time step between the start of each grain. We need to add a little
// bit of silence so we can detect grain boundaries and also account
// for the extra frames for HRTF.
-var timeStep = duration + .005 + extraFramesHRTF / sampleRate;
+let timeStep = duration + .005 + extraFramesHRTF / sampleRate;
// Time step between the start for each grain.
-var grainOffsetStep = 0.001;
+let grainOffsetStep = 0.001;
// How long to render to cover all of the grains.
-var renderTime = (numberOfTests + 1) * timeStep;
+let renderTime = (numberOfTests + 1) * timeStep;
-var context;
-var renderedData;
+let context;
+let renderedData;
// Create a buffer containing the data that we want. The function f
// returns the desired value at sample frame k.
@@ -33,13 +33,15 @@ function createSignalBuffer(context, f) {
// Make sure the buffer has enough data for all of the possible
// grain offsets and durations. Need to include the extra frames
// for HRTF. The additional 1 is for any round-off errors.
- var signalLength = Math.floor(1 + extraFramesHRTF + sampleRate * (numberOfTests * grainOffsetStep + duration));
+ let signalLength = Math.floor(
+ 1 + extraFramesHRTF +
+ sampleRate * (numberOfTests * grainOffsetStep + duration));
- var buffer = context.createBuffer(2, signalLength, sampleRate);
- var data = buffer.getChannelData(0);
+ let buffer = context.createBuffer(2, signalLength, sampleRate);
+ let data = buffer.getChannelData(0);
- for (var k = 0; k < signalLength; ++k) {
- data[k] = f(k);
+ for (let k = 0; k < signalLength; ++k) {
+ data[k] = f(k);
}
return buffer;
@@ -49,56 +51,56 @@ function createSignalBuffer(context, f) {
// grain. This depends on the data having 0's between grain, and
// that the grain is always strictly non-zero.
function findStartAndEndSamples(data) {
- var nSamples = data.length;
-
- var startTime = [];
- var endTime = [];
- var lookForStart = true;
-
- // Look through the rendered data to find the start and stop
- // times of each grain.
- for (var k = 0; k < nSamples; ++k) {
- if (lookForStart) {
- // Find a non-zero point and record the start. We're not
- // concerned with the value in this test, only that the
- // grain started here.
- if (renderedData[k]) {
- startTime.push(k);
- lookForStart = false;
- }
- } else {
- // Find a zero and record the end of the grain.
- if (!renderedData[k]) {
- endTime.push(k);
- lookForStart = true;
- }
- }
+ let nSamples = data.length;
+
+ let startTime = [];
+ let endTime = [];
+ let lookForStart = true;
+
+ // Look through the rendered data to find the start and stop
+ // times of each grain.
+ for (let k = 0; k < nSamples; ++k) {
+ if (lookForStart) {
+ // Find a non-zero point and record the start. We're not
+ // concerned with the value in this test, only that the
+ // grain started here.
+ if (renderedData[k]) {
+ startTime.push(k);
+ lookForStart = false;
+ }
+ } else {
+ // Find a zero and record the end of the grain.
+ if (!renderedData[k]) {
+ endTime.push(k);
+ lookForStart = true;
+ }
+ }
}
return {start : startTime, end : endTime};
}
function playGrain(context, source, time, offset, duration) {
- var bufferSource = context.createBufferSource();
+ let bufferSource = context.createBufferSource();
- bufferSource.buffer = source;
- bufferSource.connect(context.destination);
- bufferSource.start(time, offset, duration);
+ bufferSource.buffer = source;
+ bufferSource.connect(context.destination);
+ bufferSource.start(time, offset, duration);
}
// Play out all grains. Returns a object containing two arrays, one
// for the start time and one for the grain offset time.
function playAllGrains(context, source, numberOfNotes) {
- var startTimes = new Array(numberOfNotes);
- var offsets = new Array(numberOfNotes);
+ let startTimes = new Array(numberOfNotes);
+ let offsets = new Array(numberOfNotes);
- for (var k = 0; k < numberOfNotes; ++k) {
- var timeOffset = k * timeStep;
- var grainOffset = k * grainOffsetStep;
+ for (let k = 0; k < numberOfNotes; ++k) {
+ let timeOffset = k * timeStep;
+ let grainOffset = k * grainOffsetStep;
- playGrain(context, source, timeOffset, grainOffset, duration);
- startTimes[k] = timeOffset;
- offsets[k] = grainOffset;
+ playGrain(context, source, timeOffset, grainOffset, duration);
+ startTimes[k] = timeOffset;
+ offsets[k] = grainOffset;
}
return { startTimes : startTimes, grainOffsetTimes : offsets };
@@ -106,74 +108,60 @@ function playAllGrains(context, source, numberOfNotes) {
// Verify that the start and end frames for each grain match our
// expected start and end frames.
-function verifyStartAndEndFrames(startEndFrames) {
- var startFrames = startEndFrames.start;
- var endFrames = startEndFrames.end;
-
- var success = true;
-
- // Count of how many grains started at the incorrect time.
- var errorCountStart = 0;
-
- // Count of how many grains ended at the incorrect time.
- var errorCountEnd = 0;
-
- if (startFrames.length != endFrames.length) {
- testFailed("Could not find the beginning or end of a grain.");
- success = false;
- }
-
- if (startFrames.length == numberOfTests && endFrames.length == numberOfTests) {
- testPassed("Found all " + numberOfTests + " grains.");
- } else {
- testFailed("Did not find all " + numberOfTests + " grains.");
- }
-
- // Examine the start and stop times to see if they match our
- // expectations.
- for (var k = 0; k < startFrames.length; ++k) {
- var expectedStart = timeToSampleFrame(k * timeStep, sampleRate);
- // The end point is the duration, plus the extra frames
- // for HRTF.
- var expectedEnd = extraFramesHRTF + expectedStart + grainLengthInSampleFrames(k * grainOffsetStep, duration, sampleRate);
-
- if (startFrames[k] != expectedStart) {
- testFailed("Pulse " + k + " started at " + startFrames[k] + " but expected at " + expectedStart);
- ++errorCountStart;
- success = false;
- }
-
- if (endFrames[k] != expectedEnd) {
- testFailed("Pulse " + k + " ended at " + endFrames[k] + " but expected at " + expectedEnd);
- ++errorCountEnd;
- success = false;
- }
- }
-
- // Check that all the grains started or ended at the correct time.
- if (!errorCountStart) {
- if (startFrames.length == numberOfTests) {
- testPassed("All " + numberOfTests + " grains started at the correct time.");
- } else {
- testFailed("All grains started at the correct time, but only " + startFrames.length + " grains found.");
- success = false;
- }
- } else {
- testFailed(errorCountStart + " out of " + numberOfTests + " grains started at the wrong time.");
- success = false;
- }
-
- if (!errorCountEnd) {
- if (endFrames.length == numberOfTests) {
- testPassed("All " + numberOfTests + " grains ended at the correct time.");
- } else {
- testFailed("All grains ended at the correct time, but only " + endFrames.length + " grains found.");
- success = false;
- }
- } else {
- testFailed(errorCountEnd + " out of " + numberOfTests + " grains ended at the wrong time.");
- success = false;
- }
-
- return success;
+function verifyStartAndEndFrames(startEndFrames, should) {
+ let startFrames = startEndFrames.start;
+ let endFrames = startEndFrames.end;
+
+ // Count of how many grains started at the incorrect time.
+ let errorCountStart = 0;
+
+ // Count of how many grains ended at the incorrect time.
+ let errorCountEnd = 0;
+
+ should(
+ startFrames.length == endFrames.length, 'Found all grain starts and ends')
+ .beTrue();
+
+ should(startFrames.length, 'Number of start frames').beEqualTo(numberOfTests);
+ should(endFrames.length, 'Number of end frames').beEqualTo(numberOfTests);
+
+ // Examine the start and stop times to see if they match our
+ // expectations.
+ for (let k = 0; k < startFrames.length; ++k) {
+ let expectedStart = timeToSampleFrame(k * timeStep, sampleRate);
+ // The end point is the duration, plus the extra frames
+ // for HRTF.
+ let expectedEnd = extraFramesHRTF + expectedStart +
+ grainLengthInSampleFrames(k * grainOffsetStep, duration, sampleRate);
+
+ if (startFrames[k] != expectedStart)
+ ++errorCountStart;
+ if (endFrames[k] != expectedEnd)
+ ++errorCountEnd;
+
+ should([startFrames[k], endFrames[k]], 'Pulse ' + k + ' boundary')
+ .beEqualToArray([expectedStart, expectedEnd]);
+ }
+
+ // Check that all the grains started or ended at the correct time.
+ if (!errorCountStart) {
+ should(
+ startFrames.length, 'Number of grains that started at the correct time')
+ .beEqualTo(numberOfTests);
+ } else {
+ should(
+ errorCountStart, 'Number of grains out of ' + numberOfTests +
+ 'that started at the wrong time')
+ .beEqualTo(0);
+ }
+
+ if (!errorCountEnd) {
+ should(endFrames.length, 'Number of grains that ended at the correct time')
+ .beEqualTo(numberOfTests);
+ } else {
+ should(
+ errorCountEnd, 'Number of grains out of ' + numberOfTests +
+ ' that ended at the wrong time')
+ .beEqualTo(0);
+ }
}
« no previous file with comments | « third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/note-grain-on-timing-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698