audioflinger: fix clicks on 48kHz audio.
The calculation done in prepareTracks_l() for the minimum amount
off frames needed to mix one output buffer had 2 issues:
- the additional sample needed for interpolation was not included
- the fact that the resampler does not acknowledge the frames consumed
immediately after each mixing round but only once all frames requested have been used
was not taken into account.
Thus the number of frames available in track buffer could be considered sufficient although
it was not and the resampler would abort producing a short silence perceived as a click.
Issue 5727099.
Change-Id: I7419847a7474c7d9f9170bedd0a636132262142c
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp
index e9ac3f9..060a632 100644
--- a/services/audioflinger/AudioFlinger.cpp
+++ b/services/audioflinger/AudioFlinger.cpp
@@ -2111,7 +2111,15 @@
if (t->sampleRate() == (int)mSampleRate) {
minFrames = mFrameCount;
} else {
- minFrames = (mFrameCount * t->sampleRate()) / mSampleRate + 1;
+ // +1 for rounding and +1 for additional sample needed for interpolation
+ minFrames = (mFrameCount * t->sampleRate()) / mSampleRate + 1 + 1;
+ // add frames already consumed but not yet released by the resampler
+ // because cblk->framesReady() will include these frames
+ minFrames += mAudioMixer->getUnreleasedFrames(track->name());
+ // the minimum track buffer size is normally twice the number of frames necessary
+ // to fill one buffer and the resampler should not leave more than one buffer worth
+ // of unreleased frames after each pass, but just in case...
+ LOG_ASSERT(minFrames <= cblk->frameCount);
}
}
if ((cblk->framesReady() >= minFrames) && track->isReady() &&