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

Unified Diff: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate.html

Issue 2895963003: Apply layout-test-tidy to LayoutTests/webaudio (Closed)
Patch Set: Created 3 years, 7 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
Index: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate.html
diff --git a/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate.html b/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate.html
index d1b1aabdd737571ea067736e12c648a744fb4d53..a0084ae310b98631a0cfaea7a0774ecdec50c149 100644
--- a/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate.html
+++ b/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-playbackrate.html
@@ -1,136 +1,128 @@
<!DOCTYPE html>
<html>
-<head>
- <title>AudioBufferSourceNode - playbackRate test</title>
- <script src="../../resources/testharness.js"></script>
- <script src="../../resources/testharnessreport.js"></script>
- <script src="../resources/audit-util.js"></script>
- <script src="../resources/audit.js"></script>
-</head>
-<body>
- <script>
- let audit = Audit.createTaskRunner();
-
- // Any sample rate mutiple of 128 is valid for this test, but here it uses
- // 48000Hz because it is a commonly used number that happens to be multiple
- // of 128.
- let sampleRate = 48000;
-
- // The test iterates over 60 pitches starting from 36. (MIDI pitch of C2)
- let fundamentalPitch = 36;
- let numberOfPitches = 60;
-
- let noteDuration = 0.025;
- let totalDuration = noteDuration * numberOfPitches;
-
- // Test constraints for each octave.
- let testConstraints = [{
- thresholdSNR: 103.8508,
- thresholdDiffULP: 0.3028
- }, {
- thresholdSNR: 103.8657,
- thresholdDiffULP: 0.3029
- }, {
- thresholdSNR: 103.8141,
- thresholdDiffULP: 0.3047
- }, {
- thresholdSNR: 103.6818,
- thresholdDiffULP: 0.3262
- }, {
- thresholdSNR: 103.1514,
- thresholdDiffULP: 0.3946
- }];
-
- function pitchToFrequency(midiPitch) {
- return 440 * Math.pow(2, (Math.floor(midiPitch) - 69) / 12);
- }
-
- function pitchDiffToPlaybackRate(midiPitchDiff) {
- return Math.pow(2, midiPitchDiff / 12);
- }
-
- function createSineWaveBuffer(context, frequency, duration) {
- let buffer = context.createBuffer(1, duration * sampleRate, sampleRate);
- let data = buffer.getChannelData(0);
- let omega = 2 * Math.PI * frequency / sampleRate;
- for (let i = 0; i < data.length; i++)
- data[i] = Math.sin(omega * i);
-
- return buffer;
- }
-
- // This is the fundamental buffer for playbackRate modulation. The duration
- // of this buffer is arbitrary but long enough to produce the sound without
- // running short.
- let fundamentalBuffer;
-
- // A unit test consists of 2 sources: the 'actual' source runs a buffer with
- // the playback rate modulated and the 'expected' source runs a
- // mathmatically generated sound buffer.
- function runUnitTest(context, noteStart, notePitch) {
- let actualSrc = context.createBufferSource();
- let expectedSrc = context.createBufferSource();
- let merger = context.createChannelMerger(2);
-
- actualSrc.buffer = fundamentalBuffer;
- expectedSrc.buffer = createSineWaveBuffer(context,
- pitchToFrequency(notePitch), noteDuration);
- actualSrc.playbackRate.value =
- pitchDiffToPlaybackRate(notePitch - fundamentalPitch);
-
- actualSrc.connect(merger, 0, 0);
- expectedSrc.connect(merger, 0, 1);
- merger.connect(context.destination);
-
- actualSrc.start(noteStart);
- actualSrc.stop(noteStart + noteDuration);
- expectedSrc.start(noteStart);
- expectedSrc.stop(noteStart + noteDuration);
- }
-
-
- // Test if AudioBufferSourceNode.playbackRate can playback at different rates
- // properly.
- audit.define("playbackrate-test", (task, should) => {
- let context = new OfflineAudioContext(2, totalDuration *
- sampleRate,
- sampleRate);
- fundamentalBuffer = createSineWaveBuffer(context,
- pitchToFrequency(fundamentalPitch), totalDuration);
-
- // Schedule tests up to 60 pitches above from the fundamental pitch.
- for (let iteration = 0; iteration < numberOfPitches; iteration++)
- runUnitTest(context, noteDuration * iteration, fundamentalPitch +
- iteration);
-
- // Once the rendering is complete, split the buffer into 5 octaves. Then
- // perform the SNR and the maximum difference ULP check for each octave
- // with different constraints.
- context.startRendering()
- .then(function (renderedBuffer) {
- let actual = renderedBuffer.getChannelData(0);
- let expected = renderedBuffer.getChannelData(1);
- let octaveLength = Math.floor(noteDuration * 12 * sampleRate);
-
- for (let i = 0; i < numberOfPitches / 12; i++) {
- let start = i * octaveLength;
- let end = (i + 1) * octaveLength;
- let octaveActual = actual.subarray(start, end);
- let octaveExpected = expected.subarray(start, end);
-
- compareBuffersWithConstraints(should, octaveActual, octaveExpected,
- {
- prefix: i,
- thresholdSNR: testConstraints[i].thresholdSNR,
- thresholdDiffULP: testConstraints[i].thresholdDiffULP
- });
- }
-
- })
- .then(() => task.done());
- });
-
- audit.run();
- </script>
-</body>
+ <head>
+ <title>
+ AudioBufferSourceNode - playbackRate test
+ </title>
+ <script src="../../resources/testharness.js"></script>
+ <script src="../../resources/testharnessreport.js"></script>
+ <script src="../resources/audit-util.js"></script>
+ <script src="../resources/audit.js"></script>
+ </head>
+ <body>
+ <script id="layout-test-code">
+ let audit = Audit.createTaskRunner();
+
+ // Any sample rate mutiple of 128 is valid for this test, but here it uses
+ // 48000Hz because it is a commonly used number that happens to be
+ // multiple of 128.
+ let sampleRate = 48000;
+
+ // The test iterates over 60 pitches starting from 36. (MIDI pitch of C2)
+ let fundamentalPitch = 36;
+ let numberOfPitches = 60;
+
+ let noteDuration = 0.025;
+ let totalDuration = noteDuration * numberOfPitches;
+
+ // Test constraints for each octave.
+ let testConstraints = [
+ {thresholdSNR: 103.8508, thresholdDiffULP: 0.3028},
+ {thresholdSNR: 103.8657, thresholdDiffULP: 0.3029},
+ {thresholdSNR: 103.8141, thresholdDiffULP: 0.3047},
+ {thresholdSNR: 103.6818, thresholdDiffULP: 0.3262},
+ {thresholdSNR: 103.1514, thresholdDiffULP: 0.3946}
+ ];
+
+ function pitchToFrequency(midiPitch) {
+ return 440 * Math.pow(2, (Math.floor(midiPitch) - 69) / 12);
+ }
+
+ function pitchDiffToPlaybackRate(midiPitchDiff) {
+ return Math.pow(2, midiPitchDiff / 12);
+ }
+
+ function createSineWaveBuffer(context, frequency, duration) {
+ let buffer = context.createBuffer(1, duration * sampleRate, sampleRate);
+ let data = buffer.getChannelData(0);
+ let omega = 2 * Math.PI * frequency / sampleRate;
+ for (let i = 0; i < data.length; i++)
+ data[i] = Math.sin(omega * i);
+
+ return buffer;
+ }
+
+ // This is the fundamental buffer for playbackRate modulation. The
+ // duration of this buffer is arbitrary but long enough to produce the
+ // sound without running short.
+ let fundamentalBuffer;
+
+ // A unit test consists of 2 sources: the 'actual' source runs a buffer
+ // with the playback rate modulated and the 'expected' source runs a
+ // mathmatically generated sound buffer.
+ function runUnitTest(context, noteStart, notePitch) {
+ let actualSrc = context.createBufferSource();
+ let expectedSrc = context.createBufferSource();
+ let merger = context.createChannelMerger(2);
+
+ actualSrc.buffer = fundamentalBuffer;
+ expectedSrc.buffer = createSineWaveBuffer(
+ context, pitchToFrequency(notePitch), noteDuration);
+ actualSrc.playbackRate.value =
+ pitchDiffToPlaybackRate(notePitch - fundamentalPitch);
+
+ actualSrc.connect(merger, 0, 0);
+ expectedSrc.connect(merger, 0, 1);
+ merger.connect(context.destination);
+
+ actualSrc.start(noteStart);
+ actualSrc.stop(noteStart + noteDuration);
+ expectedSrc.start(noteStart);
+ expectedSrc.stop(noteStart + noteDuration);
+ }
+
+
+ // Test if AudioBufferSourceNode.playbackRate can playback at different
+ // rates properly.
+ audit.define('playbackrate-test', (task, should) => {
+ let context =
+ new OfflineAudioContext(2, totalDuration * sampleRate, sampleRate);
+ fundamentalBuffer = createSineWaveBuffer(
+ context, pitchToFrequency(fundamentalPitch), totalDuration);
+
+ // Schedule tests up to 60 pitches above from the fundamental pitch.
+ for (let iteration = 0; iteration < numberOfPitches; iteration++)
+ runUnitTest(
+ context, noteDuration * iteration, fundamentalPitch + iteration);
+
+ // Once the rendering is complete, split the buffer into 5 octaves. Then
+ // perform the SNR and the maximum difference ULP check for each octave
+ // with different constraints.
+ context.startRendering()
+ .then(function(renderedBuffer) {
+ let actual = renderedBuffer.getChannelData(0);
+ let expected = renderedBuffer.getChannelData(1);
+ let octaveLength = Math.floor(noteDuration * 12 * sampleRate);
+
+ for (let i = 0; i < numberOfPitches / 12; i++) {
+ let start = i * octaveLength;
+ let end = (i + 1) * octaveLength;
+ let octaveActual = actual.subarray(start, end);
+ let octaveExpected = expected.subarray(start, end);
+
+ compareBuffersWithConstraints(
+ should, octaveActual, octaveExpected, {
+ prefix: i,
+ thresholdSNR: testConstraints[i].thresholdSNR,
+ thresholdDiffULP: testConstraints[i].thresholdDiffULP
+ });
+ }
+
+ })
+ .then(() => task.done());
+ });
+
+ audit.run();
+ </script>
+ </body>
</html>

Powered by Google App Engine
This is Rietveld 408576698