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 |