From 19ddf0ebb013c0ad1d6c04f0c9d6ce177a0fafae Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 3 Nov 2011 12:16:05 -0700 Subject: AudioFlinger: mix track only when really ready The addition of low power audio playback mode made that audio buffer consumption by audio HAL can now happen in bursts. This makes that requesting audio data from an AudioTrack for mixing can happen at much shorter intervals than before. This revealed an existing problem where AudioFlinger would consider a track ready for mixing although not enough frames were ready to completely fill one output buffer, thus creating short periods of silence. The fix consists in waiting for enough frames to be ready in AudioTrack buffer before declaring a track ready for mixing. This minimum is not applied when the track is stopped to allow the buffer to be emptied completely. Change-Id: I6d04f9b65db5af85b0b53f0a5674be7ec02f9e9f --- services/audioflinger/AudioFlinger.cpp | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 69560e5743c9..96e8eb980fd6 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -2066,7 +2066,16 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wpsetActiveTrack(track->name()); - if (cblk->framesReady() && track->isReady() && + // make sure that we have enough frames to mix one full buffer + uint32_t minFrames = 1; + if (!track->isStopped() && !track->isPausing()) { + if (t->sampleRate() == (int)mSampleRate) { + minFrames = mFrameCount; + } else { + minFrames = (mFrameCount * t->sampleRate()) / mSampleRate + 1; + } + } + if ((cblk->framesReady() >= minFrames) && track->isReady() && !track->isPaused() && !track->isTerminated()) { //LOGV("track %d u=%08x, s=%08x [OK] on thread %p", track->name(), cblk->user, cblk->server, this); -- cgit v1.2.3-59-g8ed1b