Chromium Code Reviews| Index: third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-loop-points.html |
| diff --git a/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-loop-points.html b/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-loop-points.html |
| index acfd67bda054543c17835610fa901334810bf559..b7f558a1716d8352013e9e8b10a9e5475737bdc3 100644 |
| --- a/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-loop-points.html |
| +++ b/third_party/WebKit/LayoutTests/webaudio/AudioBufferSource/audiobuffersource-loop-points.html |
| @@ -6,105 +6,114 @@ Tests that AudioBufferSourceNode supports loop-points with .loopStart and .loopE |
| <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> |
| </head> |
| <body> |
| <script> |
| +let audit = Audit.createTaskRunner(); |
| -window.onload = init; |
| +let sampleRate = 44100.0; |
| +let numberOfNotes = 60; // play over a 5 octave range |
| +let noteDuration = 0.025; |
| +let noteSpacing = |
| + noteDuration + 0.005; // leave 5ms of silence between each "note" |
| +let lengthInSeconds = numberOfNotes * noteSpacing; |
| -var sampleRate = 44100.0; |
| -var numberOfNotes = 60; // play over a 5 octave range |
| -var noteDuration = 0.025; |
| -var noteSpacing = noteDuration + 0.005; // leave 5ms of silence between each "note" |
| -var lengthInSeconds = numberOfNotes * noteSpacing; |
| - |
| -var context = 0; |
| -var buffer = 0; |
| +let context = 0; |
| +let buffer = 0; |
| function createTestBuffer(frequency, sampleRate) { |
| - // Create a buffer containing two periods at this frequency. |
| - // The 1st half is a pure sine wave period scaled by a linear ramp from 0 -> 1. |
| - // The 2nd half of the buffer corresponds exactly to one pure sine wave period. |
| - var onePeriodDuration = 1 / frequency; |
| - var sampleFrameLength = 2 * onePeriodDuration * sampleRate; |
| + // Create a buffer containing two periods at this frequency. |
| + // The 1st half is a pure sine wave period scaled by a linear ramp from 0 -> |
| + // 1. The 2nd half of the buffer corresponds exactly to one pure sine wave |
| + // period. |
| + let onePeriodDuration = 1 / frequency; |
| + let sampleFrameLength = 2 * onePeriodDuration * sampleRate; |
| - var audioBuffer = context.createBuffer(1, sampleFrameLength, sampleRate); |
| + let audioBuffer = context.createBuffer(1, sampleFrameLength, sampleRate); |
| - var n = audioBuffer.length; |
| - var channelData = audioBuffer.getChannelData(0); |
| + let n = audioBuffer.length; |
| + let channelData = audioBuffer.getChannelData(0); |
| - for (var i = 0; i < n; ++i) { |
| - var sample = Math.sin(frequency * 2.0*Math.PI * i / sampleRate); |
| + for (let i = 0; i < n; ++i) { |
| + let sample = Math.sin(frequency * 2.0 * Math.PI * i / sampleRate); |
| - // Linear ramp from 0 -> 1 for the first period. |
| - // Stay at 1 for the 2nd period. |
| - var scale = i < n / 2 ? i / (n / 2) : 1; |
| - sample *= scale; |
| + // Linear ramp from 0 -> 1 for the first period. |
| + // Stay at 1 for the 2nd period. |
| + let scale = i < n / 2 ? i / (n / 2) : 1; |
| + sample *= scale; |
| - channelData[i] = sample; |
| - } |
| + channelData[i] = sample; |
| + } |
| - return audioBuffer; |
| + return audioBuffer; |
| } |
| function playNote(time, duration, playbackRate) { |
| - var source = context.createBufferSource(); |
| - source.buffer = buffer; |
| - source.playbackRate.value = playbackRate; |
| - |
| - var gainNode = context.createGain(); |
| - source.connect(gainNode); |
| - gainNode.connect(context.destination); |
| - |
| - // Loop the 2nd half of the buffer. |
| - // We should be able to hear any problems as glitches if the looping incorrectly indexes to |
| - // anywhere outside of the desired loop-points, since only the 2nd half is a perfect sine-wave cycle, |
| - // while the 1st half of the buffer contains a linear ramp of a sine-wave cycle. |
| - source.loop = true; |
| - source.loopStart = 0.5 * buffer.duration; |
| - source.loopEnd = buffer.duration; |
| - |
| - // Play for the given duration. |
| - source.start(time); |
| - source.stop(time + duration); |
| - |
| - // Apply a quick linear fade-out to avoid a click at the end of the note. |
| - gainNode.gain.value = 1; |
| - gainNode.gain.setValueAtTime(1, time + duration - 0.005); |
| - gainNode.gain.linearRampToValueAtTime(0, time + duration); |
| + let source = context.createBufferSource(); |
| + source.buffer = buffer; |
| + source.playbackRate.value = playbackRate; |
| + |
| + let gainNode = context.createGain(); |
| + source.connect(gainNode); |
| + gainNode.connect(context.destination); |
| + |
| + // Loop the 2nd half of the buffer. |
| + // We should be able to hear any problems as glitches if the looping |
| + // incorrectly indexes to anywhere outside of the desired loop-points, since |
| + // only the 2nd half is a perfect sine-wave cycle, while the 1st half of the |
| + // buffer contains a linear ramp of a sine-wave cycle. |
| + source.loop = true; |
| + source.loopStart = 0.5 * buffer.duration; |
| + source.loopEnd = buffer.duration; |
| + |
| + // Play for the given duration. |
| + source.start(time); |
| + source.stop(time + duration); |
| + |
| + // Apply a quick linear fade-out to avoid a click at the end of the note. |
| + gainNode.gain.value = 1; |
| + gainNode.gain.setValueAtTime(1, time + duration - 0.005); |
| + gainNode.gain.linearRampToValueAtTime(0, time + duration); |
| } |
| -function init() { |
| - if (!window.testRunner) |
| - return; |
| +audit.define('test', (task, should) => { |
| + should(window.testRunner, 'window.testRunner').notBeEqualTo(undefined); |
| - // Create offline audio context. |
| - context = new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate); |
| + // Create offline audio context. |
| + context = |
| + new OfflineAudioContext(2, sampleRate * lengthInSeconds, sampleRate); |
| - // Create the test buffer. |
| - // We'll loop this with the loop-points set for the 2nd half of this buffer. |
| - buffer = createTestBuffer(440.0, sampleRate); |
| + // Create the test buffer. |
| + // We'll loop this with the loop-points set for the 2nd half of this buffer. |
| + buffer = createTestBuffer(440.0, sampleRate); |
| - // Play all the notes as a chromatic scale. |
| - for (var i = 0; i < numberOfNotes; ++i) { |
| - var time = i * noteSpacing; |
| - var semitone = i - numberOfNotes/2; // start three octaves down |
| + // Play all the notes as a chromatic scale. |
| + for (let i = 0; i < numberOfNotes; ++i) { |
| + let time = i * noteSpacing; |
| + let semitone = i - numberOfNotes / 2; // start three octaves down |
|
hongchan
2017/02/27 18:05:34
This comment can be between l.98 and l.99.
|
| - // Convert from semitone to rate. |
| - var playbackRate = Math.pow(2, semitone / 12); |
| + // Convert from semitone to rate. |
| + let playbackRate = Math.pow(2, semitone / 12); |
| - playNote(time, noteDuration, playbackRate); |
| - } |
| + playNote(time, noteDuration, playbackRate); |
| + } |
| - context.oncomplete = finishAudioTest; |
| - context.startRendering(); |
| + context.oncomplete = (event) => { |
|
hongchan
2017/02/27 18:05:34
Can we use promise?
Raymond Toy
2017/02/27 18:13:23
Yes, I think we can, but we need to keep some test
hongchan
2017/02/27 18:19:22
If we want to test that, that should be in the OAC
|
| + finishAudioTest(event); |
| + task.done(); |
| + }; |
| - testRunner.waitUntilDone(); |
| -} |
| + context.startRendering(); |
| + testRunner.waitUntilDone(); |
| +}); |
| + |
| +audit.run(); |
| </script> |