Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit ce979bf

Browse files
author
Ehsan Akhgari
committed
Bug 865650 - Ensure that looping will only happen if the start offset is less than the end offset; r=padenot
--HG-- extra : rebase_source : 3de31185083df174f7b6e823d1a135aee39c211d
1 parent 82eb303 commit ce979bf

3 files changed

Lines changed: 52 additions & 4 deletions

File tree

content/media/webaudio/AudioBufferSourceNode.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,8 +562,6 @@ AudioBufferSourceNode::SendDopplerShiftToStream(double aDopplerShift)
562562
void
563563
AudioBufferSourceNode::SendLoopParametersToStream()
564564
{
565-
SendInt32ParameterToStream(LOOP, mLoop ? 1 : 0);
566-
567565
// Don't compute and set the loop parameters unnecessarily
568566
if (mLoop && mBuffer) {
569567
float rate = mBuffer->SampleRate();
@@ -580,8 +578,13 @@ AudioBufferSourceNode::SendLoopParametersToStream()
580578
}
581579
int32_t loopStartTicks = NS_lround(actualLoopStart * rate);
582580
int32_t loopEndTicks = NS_lround(actualLoopEnd * rate);
583-
SendInt32ParameterToStream(LOOPSTART, loopStartTicks);
584-
SendInt32ParameterToStream(LOOPEND, loopEndTicks);
581+
if (loopStartTicks < loopEndTicks) {
582+
SendInt32ParameterToStream(LOOPSTART, loopStartTicks);
583+
SendInt32ParameterToStream(LOOPEND, loopEndTicks);
584+
SendInt32ParameterToStream(LOOP, 1);
585+
}
586+
} else if (!mLoop) {
587+
SendInt32ParameterToStream(LOOP, 0);
585588
}
586589
}
587590

content/media/webaudio/test/Makefile.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ MOCHITEST_FILES := \
2525
test_audioBufferSourceNode.html \
2626
test_audioBufferSourceNodeLoop.html \
2727
test_audioBufferSourceNodeLoopStartEnd.html \
28+
test_audioBufferSourceNodeLoopStartEndSame.html \
2829
test_audioBufferSourceNodeNullBuffer.html \
2930
test_badConnect.html \
3031
test_biquadFilterNode.html \
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<!DOCTYPE HTML>
2+
<html>
3+
<head>
4+
<title>Test AudioBufferSourceNode looping</title>
5+
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
6+
<script type="text/javascript" src="webaudio.js"></script>
7+
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
8+
</head>
9+
<body>
10+
<pre id="test">
11+
<script class="testbody" type="text/javascript">
12+
13+
SimpleTest.waitForExplicitFinish();
14+
addLoadEvent(function() {
15+
SpecialPowers.setBoolPref("media.webaudio.enabled", true);
16+
17+
var context = new AudioContext();
18+
var buffer = context.createBuffer(1, 0, context.sampleRate);
19+
20+
var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);
21+
22+
var source = context.createBufferSource();
23+
source.buffer = buffer;
24+
25+
var sp = context.createScriptProcessor(2048, 1);
26+
source.loop = true;
27+
source.start(0);
28+
source.connect(sp);
29+
sp.connect(context.destination);
30+
sp.onaudioprocess = function(e) {
31+
is(e.inputBuffer.numberOfChannels, 1, "input buffer must have only one channel");
32+
compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));
33+
34+
sp.onaudioprocess = null;
35+
36+
SpecialPowers.clearUserPref("media.webaudio.enabled");
37+
SimpleTest.finish();
38+
};
39+
});
40+
41+
</script>
42+
</pre>
43+
</body>
44+
</html>

0 commit comments

Comments
 (0)