diff options
author | Eric Laurent <elaurent@google.com> | 2011-11-14 08:38:05 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2011-11-14 08:38:05 -0800 |
commit | 030bb99814157b6424c0bf290bd2ede217b5ba77 (patch) | |
tree | 8991845d852715aa01a9fc7b5270013b20421753 /services | |
parent | 2858749704ea7b130499cf2ac7b3e1c3331f1582 (diff) | |
parent | f9c361dec4b9380db2b7eeaed68c828e154681ed (diff) | |
download | frameworks_base-030bb99814157b6424c0bf290bd2ede217b5ba77.zip frameworks_base-030bb99814157b6424c0bf290bd2ede217b5ba77.tar.gz frameworks_base-030bb99814157b6424c0bf290bd2ede217b5ba77.tar.bz2 |
Merge "audioflinger: fix noise when skipping to next song" into ics-mr1
Diffstat (limited to 'services')
-rw-r--r-- | services/audioflinger/AudioFlinger.cpp | 39 | ||||
-rw-r--r-- | services/audioflinger/AudioFlinger.h | 9 |
2 files changed, 35 insertions, 13 deletions
diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index ff262f1..780c0d2 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -7028,11 +7028,17 @@ void AudioFlinger::EffectHandle::dump(char* buffer, size_t size) AudioFlinger::EffectChain::EffectChain(const wp<ThreadBase>& wThread, int sessionId) - : mThread(wThread), mSessionId(sessionId), mActiveTrackCnt(0), mTrackCnt(0), + : mThread(wThread), mSessionId(sessionId), mActiveTrackCnt(0), mTrackCnt(0), mTailBufferCount(0), mOwnInBuffer(false), mVolumeCtrlIdx(-1), mLeftVolume(UINT_MAX), mRightVolume(UINT_MAX), mNewLeftVolume(UINT_MAX), mNewRightVolume(UINT_MAX) { mStrategy = AudioSystem::getStrategyForStream(AUDIO_STREAM_MUSIC); + sp<ThreadBase> thread = mThread.promote(); + if (thread == 0) { + return; + } + mMaxTailBuffers = ((kProcessTailDurationMs * thread->sampleRate()) / 1000) / + thread->frameCount(); } AudioFlinger::EffectChain::~EffectChain() @@ -7100,22 +7106,31 @@ void AudioFlinger::EffectChain::process_l() } bool isGlobalSession = (mSessionId == AUDIO_SESSION_OUTPUT_MIX) || (mSessionId == AUDIO_SESSION_OUTPUT_STAGE); - bool tracksOnSession = false; + // always process effects unless no more tracks are on the session and the effect tail + // has been rendered + bool doProcess = true; if (!isGlobalSession) { - tracksOnSession = (trackCnt() != 0); - } + bool tracksOnSession = (trackCnt() != 0); - // if no track is active, input buffer must be cleared here as the mixer process - // will not do it - if (tracksOnSession && - activeTrackCnt() == 0) { - size_t numSamples = thread->frameCount() * thread->channelCount(); - memset(mInBuffer, 0, numSamples * sizeof(int16_t)); + if (!tracksOnSession && mTailBufferCount == 0) { + doProcess = false; + } + + if (activeTrackCnt() == 0) { + // if no track is active and the effect tail has not been rendered, + // the input buffer must be cleared here as the mixer process will not do it + if (tracksOnSession || mTailBufferCount > 0) { + size_t numSamples = thread->frameCount() * thread->channelCount(); + memset(mInBuffer, 0, numSamples * sizeof(int16_t)); + if (mTailBufferCount > 0) { + mTailBufferCount--; + } + } + } } size_t size = mEffects.size(); - // do not process effect if no track is present in same audio session - if (isGlobalSession || tracksOnSession) { + if (doProcess) { for (size_t i = 0; i < size; i++) { mEffects[i]->process(); } diff --git a/services/audioflinger/AudioFlinger.h b/services/audioflinger/AudioFlinger.h index 4b794ef..897bc78 100644 --- a/services/audioflinger/AudioFlinger.h +++ b/services/audioflinger/AudioFlinger.h @@ -1247,6 +1247,10 @@ private: // corresponding to a suspend all request. static const int kKeyForSuspendAll = 0; + // minimum duration during which we force calling effect process when last track on + // a session is stopped or removed to allow effect tail to be rendered + static const int kProcessTailDurationMs = 1000; + void process_l(); void lock() { @@ -1287,7 +1291,8 @@ private: void decTrackCnt() { android_atomic_dec(&mTrackCnt); } int32_t trackCnt() { return mTrackCnt;} - void incActiveTrackCnt() { android_atomic_inc(&mActiveTrackCnt); } + void incActiveTrackCnt() { android_atomic_inc(&mActiveTrackCnt); + mTailBufferCount = mMaxTailBuffers; } void decActiveTrackCnt() { android_atomic_dec(&mActiveTrackCnt); } int32_t activeTrackCnt() { return mActiveTrackCnt;} @@ -1338,6 +1343,8 @@ private: int16_t *mOutBuffer; // chain output buffer volatile int32_t mActiveTrackCnt; // number of active tracks connected volatile int32_t mTrackCnt; // number of tracks connected + int32_t mTailBufferCount; // current effect tail buffer count + int32_t mMaxTailBuffers; // maximum effect tail buffers bool mOwnInBuffer; // true if the chain owns its input buffer int mVolumeCtrlIdx; // index of insert effect having control over volume uint32_t mLeftVolume; // previous volume on left channel |