Skip to content

Commit

Permalink
Bug 865650 - Ensure that looping will only happen if the start offset…
Browse files Browse the repository at this point in the history
… is less than the end offset; r=padenot
  • Loading branch information
ehsan committed Apr 25, 2013
1 parent 2c64a8e commit 2b705f0
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 4 deletions.
11 changes: 7 additions & 4 deletions content/media/webaudio/AudioBufferSourceNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,8 +562,6 @@ AudioBufferSourceNode::SendDopplerShiftToStream(double aDopplerShift)
void
AudioBufferSourceNode::SendLoopParametersToStream()
{
SendInt32ParameterToStream(LOOP, mLoop ? 1 : 0);

// Don't compute and set the loop parameters unnecessarily
if (mLoop && mBuffer) {
float rate = mBuffer->SampleRate();
Expand All @@ -580,8 +578,13 @@ AudioBufferSourceNode::SendLoopParametersToStream()
}
int32_t loopStartTicks = NS_lround(actualLoopStart * rate);
int32_t loopEndTicks = NS_lround(actualLoopEnd * rate);
SendInt32ParameterToStream(LOOPSTART, loopStartTicks);
SendInt32ParameterToStream(LOOPEND, loopEndTicks);
if (loopStartTicks < loopEndTicks) {
SendInt32ParameterToStream(LOOPSTART, loopStartTicks);
SendInt32ParameterToStream(LOOPEND, loopEndTicks);
SendInt32ParameterToStream(LOOP, 1);
}
} else if (!mLoop) {
SendInt32ParameterToStream(LOOP, 0);
}
}

Expand Down
1 change: 1 addition & 0 deletions content/media/webaudio/test/Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ MOCHITEST_FILES := \
test_audioBufferSourceNode.html \
test_audioBufferSourceNodeLoop.html \
test_audioBufferSourceNodeLoopStartEnd.html \
test_audioBufferSourceNodeLoopStartEndSame.html \
test_audioBufferSourceNodeNullBuffer.html \
test_badConnect.html \
test_biquadFilterNode.html \
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test AudioBufferSourceNode looping</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="webaudio.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();
addLoadEvent(function() {
SpecialPowers.setBoolPref("media.webaudio.enabled", true);

var context = new AudioContext();
var buffer = context.createBuffer(1, 0, context.sampleRate);

var expectedBuffer = context.createBuffer(1, 2048, context.sampleRate);

var source = context.createBufferSource();
source.buffer = buffer;

var sp = context.createScriptProcessor(2048, 1);
source.loop = true;
source.start(0);
source.connect(sp);
sp.connect(context.destination);
sp.onaudioprocess = function(e) {
is(e.inputBuffer.numberOfChannels, 1, "input buffer must have only one channel");
compareBuffers(e.inputBuffer.getChannelData(0), expectedBuffer.getChannelData(0));

sp.onaudioprocess = null;

SpecialPowers.clearUserPref("media.webaudio.enabled");
SimpleTest.finish();
};
});

</script>
</pre>
</body>
</html>

0 comments on commit 2b705f0

Please sign in to comment.