From 60e182437228312cc28469a5b0dfde77ac848e1a Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Thu, 29 Jul 2010 06:50:24 -0700 Subject: Fixed underrun in audioflinger mixer. When all audio tracks have been disabled and the mixer is running idle before the output stream is placed in standby, the mixer sometimes fails to write to the output stream on time to avoid underrun. This is because the sleep period used to wait before the next write to output stream is too close to the actual buffer duration. In fact this sleep time is not critical as if we write too early to the output stream, the kernel driver will wait for free buffers from the audio DSP DMA and we will sleep anyways. The fix consists in dividing the calculated wait period by 2 to increase the margin. Change-Id: I5730887dc2ccce2a511bc858494a6f7da6b392a0 --- services/audioflinger/AudioFlinger.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'services') diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index 4a7243f..252b42a 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -2015,7 +2015,7 @@ uint32_t AudioFlinger::MixerThread::activeSleepTimeUs() uint32_t AudioFlinger::MixerThread::idleSleepTimeUs() { - return (uint32_t)((mFrameCount * 1000) / mSampleRate) * 1000; + return (uint32_t)(((mFrameCount * 1000) / mSampleRate) * 1000) / 2; } // ---------------------------------------------------------------------------- @@ -2476,7 +2476,7 @@ uint32_t AudioFlinger::DirectOutputThread::idleSleepTimeUs() { uint32_t time; if (AudioSystem::isLinearPCM(mFormat)) { - time = (uint32_t)((mFrameCount * 1000) / mSampleRate) * 1000; + time = (uint32_t)(((mFrameCount * 1000) / mSampleRate) * 1000) / 2; } else { time = 10000; } -- cgit v1.1