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

Commit 47affe5c authored by jiabin's avatar jiabin
Browse files

Copy haptic data directly from effect in buffer to out buffer.

The haptic data will be partially interleaved at the end of the buffer
after processing audio mixing. When processing audio effect, only audio
data will be handled. In that case, haptic data will be missed if there
is any audio effect. Copying haptic data directly from audio effect in
buffer to out buffer could help solve the problem.

Bug: 129956425
Test: play haptic with audio effect.
Change-Id: I2b48bb43bec10167d4eacbcaa5c27959e0d44c32
parent 0e5a1b3b
Loading
Loading
Loading
Loading
+22 −0
Original line number Diff line number Diff line
@@ -3610,8 +3610,30 @@ bool AudioFlinger::PlaybackThread::threadLoop()

            // only process effects if we're going to write
            if (mSleepTimeUs == 0 && mType != OFFLOAD) {
                audio_session_t activeHapticId = AUDIO_SESSION_NONE;
                if (mHapticChannelCount > 0 && effectChains.size() > 0) {
                    for (auto track : mActiveTracks) {
                        if (track->getHapticPlaybackEnabled()) {
                            activeHapticId = track->sessionId();
                            break;
                        }
                    }
                }
                for (size_t i = 0; i < effectChains.size(); i ++) {
                    effectChains[i]->process_l();
                    // TODO: Write haptic data directly to sink buffer when mixing.
                    if (activeHapticId != AUDIO_SESSION_NONE
                            && activeHapticId == effectChains[i]->sessionId()) {
                        // Haptic data is active in this case, copy it directly from
                        // in buffer to out buffer.
                        const size_t audioBufferSize = mNormalFrameCount
                                * audio_bytes_per_frame(mChannelCount, EFFECT_BUFFER_FORMAT);
                        memcpy_by_audio_format(
                                (uint8_t*)effectChains[i]->outBuffer() + audioBufferSize,
                                EFFECT_BUFFER_FORMAT,
                                (const uint8_t*)effectChains[i]->inBuffer() + audioBufferSize,
                                EFFECT_BUFFER_FORMAT, mNormalFrameCount * mHapticChannelCount);
                    }
                }
            }
        }