Add limiter for mono blend
Bug: 26904791
Change-Id: I76b16e70871cd9fc0a9b8badc66f27069fabe1cb
diff --git a/services/audioflinger/FastMixer.cpp b/services/audioflinger/FastMixer.cpp
index cc9acff..1446d19 100644
--- a/services/audioflinger/FastMixer.cpp
+++ b/services/audioflinger/FastMixer.cpp
@@ -416,7 +416,7 @@
}
if (mMasterMono.load()) { // memory_order_seq_cst
- mono_blend(mMixerBuffer, mMixerBufferFormat, Format_channelCount(mFormat), frameCount);
+ mono_blend(mMixerBuffer, mMixerBufferFormat, Format_channelCount(mFormat), frameCount, true /*limit*/);
}
// prepare the buffer used to write to sink
void *buffer = mSinkBuffer != NULL ? mSinkBuffer : mMixerBuffer;
diff --git a/services/audioflinger/Threads.cpp b/services/audioflinger/Threads.cpp
index 8ae798c..7a29cce 100644
--- a/services/audioflinger/Threads.cpp
+++ b/services/audioflinger/Threads.cpp
@@ -2917,8 +2917,8 @@
// 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);
+ mono_blend(mMixerBuffer, mMixerBufferFormat, mChannelCount, mNormalFrameCount,
+ true /*limit*/);
}
memcpy_by_audio_format(buffer, format, mMixerBuffer, mMixerBufferFormat,
@@ -2958,7 +2958,8 @@
//ALOGV("writing effect buffer to sink buffer format %#x", mFormat);
if (requireMonoBlend()) {
- mono_blend(mEffectBuffer, mEffectBufferFormat, mChannelCount, mNormalFrameCount);
+ mono_blend(mEffectBuffer, mEffectBufferFormat, mChannelCount, mNormalFrameCount,
+ true /*limit*/);
}
memcpy_by_audio_format(mSinkBuffer, mFormat, mEffectBuffer, mEffectBufferFormat,
diff --git a/services/audioflinger/Threads.h b/services/audioflinger/Threads.h
index fa047fa..ae8bbb9 100644
--- a/services/audioflinger/Threads.h
+++ b/services/audioflinger/Threads.h
@@ -927,6 +927,8 @@
}
}
// the FastMixer performs mono blend if it exists.
+ // Blending with limiter is not idempotent,
+ // and blending without limiter is idempotent but inefficient to do twice.
virtual bool requireMonoBlend() { return mMasterMono.load() && !hasFastMixer(); }
};