5 <script src=
"resources/compatibility.js"></script>
6 <script src=
"resources/audio-testing.js"></script>
7 <script src=
"resources/audiobuffersource-testing.js"></script>
8 <script src=
"../resources/js-test.js"></script>
13 <div id=
"description"></div>
14 <div id=
"console"></div>
17 description("Tests AudioBufferSourceNode start() with a variety of offsets and durations.");
19 // The following test cases assume an AudioBuffer of length 8 whose PCM data is a linear ramp, 0, 1, 2, 3,...
23 { description
: "start(when): implicitly play whole buffer from beginning to end",
24 offsetFrame
: "none", durationFrames
: "none", renderFrames
: 16, playbackRate
: 1, expected
: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] },
26 { description
: "start(when, 0): play whole buffer from beginning to end explicitly giving offset of 0",
27 offsetFrame
: 0, durationFrames
: "none", renderFrames
: 16, playbackRate
: 1, expected
: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] },
29 { description
: "start(when, 0, 8_frames): play whole buffer from beginning to end explicitly giving offset of 0 and duration of 8 frames",
30 offsetFrame
: 0, durationFrames
: 8, renderFrames
: 16, playbackRate
: 1, expected
: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] },
32 { description
: "start(when, 4_frames): play with explicit non-zero offset",
33 offsetFrame
: 4, durationFrames
: "none", renderFrames
: 16, playbackRate
: 1, expected
: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] },
35 { description
: "start(when, 4_frames, 4_frames): play with explicit non-zero offset and duration",
36 offsetFrame
: 4, durationFrames
: 4, renderFrames
: 16, playbackRate
: 1, expected
: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] },
38 { description
: "start(when, 7_frames): play with explicit non-zero offset near end of buffer",
39 offsetFrame
: 7, durationFrames
: 1, renderFrames
: 16, playbackRate
: 1, expected
: [7,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] },
41 { description
: "start(when, 8_frames): play with explicit offset at end of buffer",
42 offsetFrame
: 8, durationFrames
: 0, renderFrames
: 16, playbackRate
: 1, expected
: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] },
44 { description
: "start(when, 9_frames): play with explicit offset past end of buffer",
45 offsetFrame
: 8, durationFrames
: 0, renderFrames
: 16, playbackRate
: 1, expected
: [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0] },
47 // When the duration exceeds the buffer, just play to the end of the buffer.
48 // (This is different from the case when we're looping, which is tested in loop-comprehensive.)
49 { description
: "start(when, 0, 15_frames): play with whole buffer, with long duration (clipped)",
50 offsetFrame
: 0, durationFrames
: 15, renderFrames
: 16, playbackRate
: 1, expected
: [0,1,2,3,4,5,6,7,0,0,0,0,0,0,0,0] },
52 // Enable test when AudioBufferSourceNode hack is fixed: https://bugs.webkit.org/show_bug.cgi?id=77224
53 // { description: "start(when, 3_frames, 3_frames): play a middle section with explicit offset and duration",
54 // offsetFrame: 3, durationFrames: 3, renderFrames: 16, playbackRate: 1, expected: [4,5,6,7,0,0,0,0,0,0,0,0,0,0,0,0] },
58 var sampleRate
= 44100;
60 var bufferFrameLength
= 8;
61 var testSpacingFrames
= 32;
62 var testSpacingSeconds
= testSpacingFrames
/ sampleRate
;
63 var totalRenderLengthFrames
= tests
.length
* testSpacingFrames
;
65 function runLoopTest(context
, testNumber
, test
) {
66 var source
= context
.createBufferSource();
68 source
.buffer
= buffer
;
69 source
.playbackRate
.value
= test
.playbackRate
;
71 source
.connect(context
.destination
);
73 // Render each test one after the other, spaced apart by testSpacingSeconds.
74 var startTime
= testNumber
* testSpacingSeconds
;
76 if (test
.offsetFrame
== "none" && test
.durationFrames
== "none") {
77 source
.start(startTime
);
78 } else if (test
.durationFrames
== "none") {
79 var offset
= test
.offsetFrame
/ context
.sampleRate
;
80 source
.start(startTime
, offset
);
82 var offset
= test
.offsetFrame
/ context
.sampleRate
;
83 var duration
= test
.durationFrames
/ context
.sampleRate
;
84 source
.start(startTime
, offset
, duration
);
89 if (window
.testRunner
) {
90 testRunner
.dumpAsText();
91 testRunner
.waitUntilDone();
94 window
.jsTestIsAsync
= true;
96 // Create offline audio context.
97 var context
= new OfflineAudioContext(1, totalRenderLengthFrames
, sampleRate
);
98 buffer
= createTestBuffer(context
, bufferFrameLength
);
100 for (var i
= 0; i
< tests
.length
; ++i
)
101 runLoopTest(context
, i
, tests
[i
]);
103 context
.oncomplete
= checkAllTests
;
104 context
.startRendering();
108 successfullyParsed
= true;