Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 88ee0902 authored by David Li's avatar David Li
Browse files

AudioFlinger: avoid doing balance before downmixing

If both mMixerBufferValid and mEffectBufferValid are valid, do balance
and downmix on mEffectBuffer.

Bug: 235912550
Test: mm libaudioflinger
Test: Enable mono, balance and adaptive sound. Play music in YTMusic.
Change-Id: I183f49866081e2e375aa0deae00d7ff2c92bce88
parent cb9f076c
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -3967,20 +3967,25 @@ bool AudioFlinger::PlaybackThread::threadLoop()
                void *buffer = mEffectBufferValid ? mEffectBuffer : mSinkBuffer;
                audio_format_t format = mEffectBufferValid ? mEffectBufferFormat : mFormat;

                // Apply mono blending and balancing if the effect buffer is not valid. Otherwise,
                // do these processes after effects are applied.
                if (!mEffectBufferValid) {
                    // mono blend occurs for mixer threads only (not direct or offloaded)
                    // and is handled here if we're going directly to the sink.
                if (requireMonoBlend() && !mEffectBufferValid) {
                    mono_blend(mMixerBuffer, mMixerBufferFormat, mChannelCount, mNormalFrameCount,
                               true /*limit*/);
                    if (requireMonoBlend()) {
                        mono_blend(mMixerBuffer, mMixerBufferFormat, mChannelCount,
                                mNormalFrameCount, true /*limit*/);
                    }

                    if (!hasFastMixer()) {
                        // Balance must take effect after mono conversion.
                        // We do it here if there is no FastMixer.
                    // mBalance detects zero balance within the class for speed (not needed here).
                        // mBalance detects zero balance within the class for speed
                        // (not needed here).
                        mBalance.setBalance(mMasterBalance.load());
                        mBalance.process((float *)mMixerBuffer, mNormalFrameCount);
                    }
                }

                memcpy_by_audio_format(buffer, format, mMixerBuffer, mMixerBufferFormat,
                        mNormalFrameCount * (mixerChannelCount + mHapticChannelCount));