@@ -7028,11 +7028,17 @@ void AudioFlinger::EffectHandle::dump(char* buffer, size_t size)
70287028
70297029AudioFlinger::EffectChain::EffectChain (const wp<ThreadBase>& wThread,
70307030 int sessionId)
7031- : mThread (wThread), mSessionId (sessionId), mActiveTrackCnt (0 ), mTrackCnt (0 ),
7031+ : mThread (wThread), mSessionId (sessionId), mActiveTrackCnt (0 ), mTrackCnt (0 ), mTailBufferCount ( 0 ),
70327032 mOwnInBuffer (false ), mVolumeCtrlIdx(-1 ), mLeftVolume(UINT_MAX), mRightVolume(UINT_MAX),
70337033 mNewLeftVolume(UINT_MAX), mNewRightVolume(UINT_MAX)
70347034{
70357035 mStrategy = AudioSystem::getStrategyForStream (AUDIO_STREAM_MUSIC);
7036+ sp<ThreadBase> thread = mThread .promote ();
7037+ if (thread == 0 ) {
7038+ return ;
7039+ }
7040+ mMaxTailBuffers = ((kProcessTailDurationMs * thread->sampleRate ()) / 1000 ) /
7041+ thread->frameCount ();
70367042}
70377043
70387044AudioFlinger::EffectChain::~EffectChain ()
@@ -7100,22 +7106,31 @@ void AudioFlinger::EffectChain::process_l()
71007106 }
71017107 bool isGlobalSession = (mSessionId == AUDIO_SESSION_OUTPUT_MIX) ||
71027108 (mSessionId == AUDIO_SESSION_OUTPUT_STAGE);
7103- bool tracksOnSession = false ;
7109+ // always process effects unless no more tracks are on the session and the effect tail
7110+ // has been rendered
7111+ bool doProcess = true ;
71047112 if (!isGlobalSession) {
7105- tracksOnSession = (trackCnt () != 0 );
7106- }
7113+ bool tracksOnSession = (trackCnt () != 0 );
71077114
7108- // if no track is active, input buffer must be cleared here as the mixer process
7109- // will not do it
7110- if (tracksOnSession &&
7111- activeTrackCnt () == 0 ) {
7112- size_t numSamples = thread->frameCount () * thread->channelCount ();
7113- memset (mInBuffer , 0 , numSamples * sizeof (int16_t ));
7115+ if (!tracksOnSession && mTailBufferCount == 0 ) {
7116+ doProcess = false ;
7117+ }
7118+
7119+ if (activeTrackCnt () == 0 ) {
7120+ // if no track is active and the effect tail has not been rendered,
7121+ // the input buffer must be cleared here as the mixer process will not do it
7122+ if (tracksOnSession || mTailBufferCount > 0 ) {
7123+ size_t numSamples = thread->frameCount () * thread->channelCount ();
7124+ memset (mInBuffer , 0 , numSamples * sizeof (int16_t ));
7125+ if (mTailBufferCount > 0 ) {
7126+ mTailBufferCount --;
7127+ }
7128+ }
7129+ }
71147130 }
71157131
71167132 size_t size = mEffects .size ();
7117- // do not process effect if no track is present in same audio session
7118- if (isGlobalSession || tracksOnSession) {
7133+ if (doProcess) {
71197134 for (size_t i = 0 ; i < size; i++) {
71207135 mEffects [i]->process ();
71217136 }
0 commit comments