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

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

Issue 1097373003: Fix issue with failing to call AudioBufferSource.onended in some cases (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix comment. Created 5 years, 8 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 | « ManualTests/webaudio/audiobuffersource-resampling-onended.html ('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 399249364d8bcdde9118834ffe34dae80d774d43..3766ec606a405c7de0787a5753f0eb85a6067baf 100644
--- a/Source/modules/webaudio/AudioBufferSourceNode.cpp
+++ b/Source/modules/webaudio/AudioBufferSourceNode.cpp
@@ -489,8 +489,10 @@ double AudioBufferSourceHandler::computePlaybackRate()
// Normally it's not an issue because buffers are loaded at the
// AudioContext's sample-rate, but we can handle it in any case.
double sampleRateFactor = 1.0;
- if (buffer())
- sampleRateFactor = buffer()->sampleRate() / sampleRate();
+ if (buffer()) {
+ // Use doubles to compute this to full accuracy.
+ sampleRateFactor = buffer()->sampleRate() / static_cast<double>(sampleRate());
+ }
// Use finalValue() to incorporate changes of AudioParamTimeline and
// AudioSummingJunction from m_playbackRate AudioParam.
@@ -541,7 +543,16 @@ void AudioBufferSourceHandler::handleStoppableSourceNode()
// If the source node is not looping, and we have a buffer, we can determine when the
// source would stop playing.
if (!loop() && buffer() && isPlayingOrScheduled()) {
- double stopTime = m_startTime + buffer()->duration();
+ // See crbug.com/478301. If a source node is started via start(), the source won't start at
+ // that time but one quantum (128 frames) later. But we compute the stop time based on the
+ // start time and the duration, so we end up stopping one quantum too early. Thus, add one
hongchan 2015/04/21 21:39:08 I think 'one quantum early' reads better.
Raymond Toy 2015/04/21 22:00:05 Done.
+ // quantum to the stop time. Then add one more just for good measure; we don't need to be
+ // extra precise here. We just need to stop the source sometime after it should have
+ // stopped if it hadn't already.
+ // FIXME: Expose the rendering quantom somehow instead of hardwiring a value here.
hongchan 2015/04/21 21:39:08 quantom -> quantum
Raymond Toy 2015/04/21 22:00:05 Done.
+ double extraStopTime = 256 / static_cast<double>(context()->sampleRate());
hongchan 2015/04/21 21:39:08 Can we use an extra variable for '256' at the top
Raymond Toy 2015/04/21 22:00:05 Done.
+ double stopTime = m_startTime + buffer()->duration() + extraStopTime;
+
if (context()->currentTime() > stopTime) {
// The context time has passed the time when the source nodes should have stopped
// playing. Stop the node now and deref it. (But don't run the onEnded event because the
« no previous file with comments | « ManualTests/webaudio/audiobuffersource-resampling-onended.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698