Index: LayoutTests/webaudio/audiobuffersource-loop-comprehensive.html |
diff --git a/LayoutTests/webaudio/audiobuffersource-loop-comprehensive.html b/LayoutTests/webaudio/audiobuffersource-loop-comprehensive.html |
index 1ff7132db8e641e923f371c1531548bd65e4cd28..1ddb02073c7279d0bea8418fbea25ab9815de685 100644 |
--- a/LayoutTests/webaudio/audiobuffersource-loop-comprehensive.html |
+++ b/LayoutTests/webaudio/audiobuffersource-loop-comprehensive.html |
@@ -23,70 +23,128 @@ description("Tests AudioBufferSourceNode looping with a variety of loop points." |
var tests = [ |
{ description: "loop whole buffer by default with loopStart == loopEnd == 0", |
- loopStartFrame: 0, loopEndFrame: 0, renderFrames: 16, playbackRate: 1, |
+ loopStartFrame: 0, |
+ loopEndFrame: 0, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
{ description: "loop whole buffer explicitly", |
- loopStartFrame: 0, loopEndFrame: 8, renderFrames: 16, playbackRate: 1, |
+ loopStartFrame: 0, |
+ loopEndFrame: 8, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
{ description: "loop from middle to end of buffer", |
- loopStartFrame: 4, loopEndFrame: 8, renderFrames: 16, playbackRate: 1, |
+ loopStartFrame: 4, |
+ loopEndFrame: 8, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,4,5,6,7,4,5,6,7,4,5,6,7] }, |
{ description: "loop from start to middle of buffer", |
- loopStartFrame: 0, loopEndFrame: 4, renderFrames: 16, playbackRate: 1, |
+ loopStartFrame: 0, |
+ loopEndFrame: 4, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,0,1,2,3,0,1,2,3,0,1,2,3] }, |
-{ loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 1, |
+{ loopStartFrame: 4, |
+ loopEndFrame: 6, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,4,5,4,5,4,5,4,5,4,5,4,5] }, |
-{ loopStartFrame: 3, loopEndFrame: 7, renderFrames: 16, playbackRate: 1, |
+{ loopStartFrame: 3, |
+ loopEndFrame: 7, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,4,5,6,3,4,5,6,3,4,5,6,3] }, |
-{ loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 0.5, |
+{ loopStartFrame: 4, |
+ loopEndFrame: 6, |
+ renderFrames: 16, |
+ playbackRate: 0.5, |
expected: [0, 0.5, 1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 4, 4.5, 5, 5.5] }, |
-{ loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 1.5, |
+{ loopStartFrame: 4, |
+ loopEndFrame: 6, |
+ renderFrames: 16, |
+ playbackRate: 1.5, |
expected: [0, 1.5, 3, 4.5, 4, 5.5, 5, 4.5, 4, 5.5, 5, 4.5, 4, 5.5, 5, 4.5] }, |
// Offset past loop end, so playback starts at loop start |
-{ loopStartFrame: 2, loopEndFrame: 5, renderFrames: 16, playbackRate: 1, |
+{ loopStartFrame: 2, |
+ loopEndFrame: 5, |
+ renderFrames: 16, |
+ playbackRate: 1, |
offsetFrame: 6, |
expected: [2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 3, 4, 2, 3, 4, 2] }, |
// Offset before loop start, so start at offset and continue |
-{ loopStartFrame: 3, loopEndFrame: 6, renderFrames: 16, playbackRate: 1, |
+{ loopStartFrame: 3, |
+ loopEndFrame: 6, |
+ renderFrames: 16, |
+ playbackRate: 1, |
offsetFrame: 1, |
expected: [1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4] }, |
// Offset between loop start and loop end, so start at offset and continue |
-{ loopStartFrame: 3, loopEndFrame: 6, renderFrames: 16, playbackRate: 1, |
+{ loopStartFrame: 3, |
+ loopEndFrame: 6, |
+ renderFrames: 16, |
+ playbackRate: 1, |
offsetFrame: 4, |
expected: [4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4] }, |
{ description: "illegal playbackRate of 47 greater than loop length", |
- loopStartFrame: 4, loopEndFrame: 6, renderFrames: 16, playbackRate: 47, |
+ loopStartFrame: 4, |
+ loopEndFrame: 6, |
+ renderFrames: 16, |
+ playbackRate: 47, |
expected: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] }, |
// Try illegal loop-points - they should be ignored and we'll loop the whole buffer. |
{ description: "illegal loop: loopStartFrame > loopEndFrame", |
- loopStartFrame: 7, loopEndFrame: 3, renderFrames: 16, playbackRate: 1, |
+ loopStartFrame: 7, |
+ loopEndFrame: 3, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
{ description: "illegal loop: loopStartFrame == loopEndFrame", |
- loopStartFrame: 3, loopEndFrame: 3, renderFrames: 16, playbackRate: 1, |
+ loopStartFrame: 3, |
+ loopEndFrame: 3, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
{ description: "illegal loop: loopStartFrame < 0", |
- loopStartFrame: -8, loopEndFrame: 3, renderFrames: 16, playbackRate: 1, |
+ loopStartFrame: -8, |
+ loopEndFrame: 3, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
{ description: "illegal loop: loopEndFrame > bufferLength", |
- loopStartFrame: 0, loopEndFrame: 30000, renderFrames: 16, playbackRate: 1, |
+ loopStartFrame: 0, |
+ loopEndFrame: 30000, |
+ renderFrames: 16, |
+ playbackRate: 1, |
expected: [0,1,2,3,4,5,6,7,0,1,2,3,4,5,6,7] }, |
+// Start a loop with a duration longer than the buffer. The output should be the data from frame 1 |
+// to 6, and then looping from 3 to 5 until 30 frames have been played. |
+{ description: "loop from 3 -> 6 with offset 1 for 31 frames", |
+ loopStartFrame: 3, |
+ loopEndFrame: 6, |
+ playbackRate: 1, |
+ offsetFrame: 1, |
+ durationFrames: 30, |
+ expected: [1, 2, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3, 4, 5, 3] }, |
+ |
]; |
var sampleRate = 44100; |
@@ -111,9 +169,26 @@ function runLoopTest(context, testNumber, test) { |
// Render each test one after the other, spaced apart by testSpacingSeconds. |
var startTime = testNumber * testSpacingSeconds; |
- var duration = test.renderFrames / context.sampleRate; |
- source.start(startTime, offset); |
- source.stop(startTime + duration); |
+ |
+ if (test.renderFrames) { |
+ var duration = test.renderFrames / context.sampleRate; |
+ if (test.renderFrames > testSpacingFrames || test.renderFrames < 0) { |
+ testFailed("Test " + testNumber |
+ + ": renderFrames (" + test.renderFrames + ") outside the range [0, " |
+ + testSpacingFrames + "]"); |
+ } |
+ source.start(startTime, offset); |
+ source.stop(startTime + duration); |
+ } else if (test.durationFrames) { |
+ if (test.durationFrames > testSpacingFrames || test.durationFrames < 0) { |
+ testFailed("Test " + testNumber |
+ + ": durationFrames (" + test.durationFrames + ") outside the range [0, " |
+ + testSpacingFrames + "]"); |
+ } |
+ source.start(startTime, offset, test.durationFrames / context.sampleRate); |
+ } else { |
+ testFailed("Test " + testNumber + " must specify one of renderFrames or durationFrames"); |
+ } |
} |
function runTest() { |