Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1526)

Unified Diff: Source/modules/webaudio/AudioBufferSourceNode.cpp

Issue 912803005: Looping AudioBufferSourceNodes stop only if duration is explicitly given. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Update according to review. Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/modules/webaudio/AudioBufferSourceNode.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/modules/webaudio/AudioBufferSourceNode.cpp
diff --git a/Source/modules/webaudio/AudioBufferSourceNode.cpp b/Source/modules/webaudio/AudioBufferSourceNode.cpp
index 488b8ba041c1a2493459b17bfc12935a261757dd..e52fb30cc2d0ac4e28ebfdaa31a213ac34150cc1 100644
--- a/Source/modules/webaudio/AudioBufferSourceNode.cpp
+++ b/Source/modules/webaudio/AudioBufferSourceNode.cpp
@@ -405,7 +405,12 @@ void AudioBufferSourceNode::clampGrainParameters(const AudioBuffer* buffer)
m_grainOffset = clampTo(m_grainOffset, 0.0, bufferDuration);
- if (loop()) {
+ // If the duration was not explicitly given, use the buffer duration to set the grain
+ // duration. Otherwise, we want to use the user-specified value, of course.
+ if (!m_isDurationGiven)
+ m_grainDuration = bufferDuration - m_grainOffset;
+
+ if (m_isDurationGiven && loop()) {
// We're looping a grain with a grain duration specified. Schedule the loop to stop after
// grainDuration seconds after starting, possibly running the loop multiple times if
// grainDuration is larger than the buffer duration. The net effect is as if the user called
@@ -430,11 +435,16 @@ void AudioBufferSourceNode::start(double when, ExceptionState& exceptionState)
void AudioBufferSourceNode::start(double when, double grainOffset, ExceptionState& exceptionState)
{
- start(when, grainOffset, buffer() ? buffer()->duration() : 0, exceptionState);
+ startSource(when, grainOffset, buffer() ? buffer()->duration() : 0, false, exceptionState);
}
void AudioBufferSourceNode::start(double when, double grainOffset, double grainDuration, ExceptionState& exceptionState)
{
+ startSource(when, grainOffset, grainDuration, true, exceptionState);
+}
+
+void AudioBufferSourceNode::startSource(double when, double grainOffset, double grainDuration, bool isDurationGiven, ExceptionState& exceptionState)
+{
ASSERT(isMainThread());
if (m_playbackState != UNSCHEDULED_STATE) {
@@ -465,6 +475,7 @@ void AudioBufferSourceNode::start(double when, double grainOffset, double grainD
return;
}
+ m_isDurationGiven = isDurationGiven;
m_isGrain = true;
m_grainOffset = grainOffset;
m_grainDuration = grainDuration;
« no previous file with comments | « Source/modules/webaudio/AudioBufferSourceNode.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698