Skip to content

Commit 19ddf0e

Browse files
author
Eric Laurent
committed
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
1 parent f9d8faf commit 19ddf0e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

services/audioflinger/AudioFlinger.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,16 @@ uint32_t AudioFlinger::MixerThread::prepareTracks_l(const SortedVector< wp<Track
20662066
// The first time a track is added we wait
20672067
// for all its buffers to be filled before processing it
20682068
mAudioMixer->setActiveTrack(track->name());
2069-
if (cblk->framesReady() && track->isReady() &&
2069+
// make sure that we have enough frames to mix one full buffer
2070+
uint32_t minFrames = 1;
2071+
if (!track->isStopped() && !track->isPausing()) {
2072+
if (t->sampleRate() == (int)mSampleRate) {
2073+
minFrames = mFrameCount;
2074+
} else {
2075+
minFrames = (mFrameCount * t->sampleRate()) / mSampleRate + 1;
2076+
}
2077+
}
2078+
if ((cblk->framesReady() >= minFrames) && track->isReady() &&
20702079
!track->isPaused() && !track->isTerminated())
20712080
{
20722081
//LOGV("track %d u=%08x, s=%08x [OK] on thread %p", track->name(), cblk->user, cblk->server, this);

0 commit comments

Comments
 (0)