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
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 04d62fa..822e490 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -3610,8 +3610,30 @@
// 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);
+ }
}
}
}