Repository navigation
Detecting audiocallback invocation after a pause, and purging residual samples - #8587
Conversation
e655f19 to
3d56380
Compare
saintmatthieu
left a comment
There was a problem hiding this comment.
I think the approach is a good one. I raised a clarification/simplification point I'd like to discuss before approving.
There was a problem hiding this comment.
Minor: to make it a bit simpler, did you consider/try calling ->Get with framesPerBuffer as last argument in all calls? Looks like RingBuffer::Get has some protection against the user asking for too many samples.
There was a problem hiding this comment.
I did that and it worked, so yes, a bit less math needed indeed! I didn't think of Get having that protection.
There was a problem hiding this comment.
It would not work if this statement were executed without the if clause (meaning state would be stored even if false) ?
There was a problem hiding this comment.
Indeed removing the check breaks the functionality.
I'm guessing it is because of the order of execution, but haven't checked more deeply.
There was a problem hiding this comment.
I guess that we want/need to do this purge only once when transitioning from pause to play, right? In which case, a small simplification would be to call here const auto wasPaused = mWasPaused.exchange(false). Then we wouldn't need the
if (!IsPaused()) {
mWasPaused.store(false, std::memory_order_relaxed);
}at the end of the method.
If that makes sense, then mWasPaused should probably be renamed to mPurgeNeeded or something like this.
There was a problem hiding this comment.
Then I'd need to move this out of the for loop, and have an extra for loop. Which actually may be just as well, since then it can be extracted into it's own method. I'll give it a spin!
There was a problem hiding this comment.
An extra loop ? I meant
const auto wasPaused = mWasPaused.exchange(false);
for (unsigned n = 0; n < numPlaybackChannels; ++n) {
//! Purging queued samples from before pause.
if (wasPaused && !IsPaused()) {
auto totalPurged = static_cast<int>(nAvailable);wouldn't that work? (Not that I want to restrain your from giving it its own method :) )
There was a problem hiding this comment.
You're right, that should have worked too, but you made me look twice and I remembered that it's better to extract to its own method even if I iterate over n channels an extra time.
There was a problem hiding this comment.
@saintmatthieu Initially I thought this name was best because it describes what it detects. But you're right it's better renamed (and I also moved it), since it's only re-set in the purging logic.
c64f40b to
31f6f5c
Compare
…les from before pause.
… purge iteration logic.
31f6f5c to
78b6ec0
Compare
Resolves: #8469
Only when pausing, setting track volume to 0, and unpausing, there is playback from the mPlaybackBuffer RingBuffer samples that is a residual from the previous playback.
With full start/stop, this doesn't happen.
Identified cause:
While the buffers written to the RingBuffers in ProcessPlaybackSlices are 0-value samples, for a few callbacks the samples consumed in FillOutputBuffers from the RingBuffers are non-zero, because they are residuals from before the pause.
With pause, the RingBuffer content is intact, with stop/start these are cleared, hence the difference in behaviour.
Solution:
When resuming playback from pause, any samples pending from before pause, are now purged and not used.
Recommended:
Test cases: