Skip to content

Commit 8b4529e

Browse files
author
Eric Laurent
committed
Fix problem in lvm effect bundle wrapper.
When an effect is disabled, the process function should either copy or accumulate the content of the input buffer to the output buffer depending on the behavior requested by the framework. Current implementation is copying the input buffer unconditionally. Related to issue 5433942. Change-Id: Ic488ca97eadcc4c763de570d7e6c6f5b7a979415
1 parent f9d8faf commit 8b4529e

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ extern "C" const struct effect_interface_s gLvmEffectInterface;
4949
}\
5050
}
5151

52+
53+
static inline int16_t clamp16(int32_t sample)
54+
{
55+
// check overflow for both positive and negative values:
56+
// all bits above short range must me equal to sign bit
57+
if ((sample>>15) ^ (sample>>31))
58+
sample = 0x7FFF ^ (sample>>31);
59+
return sample;
60+
}
61+
5262
// Namespaces
5363
namespace android {
5464
namespace {
@@ -707,13 +717,6 @@ int LvmBundle_init(EffectContext *pContext){
707717
} /* end LvmBundle_init */
708718

709719

710-
static inline int16_t clamp16(int32_t sample)
711-
{
712-
if ((sample>>15) ^ (sample>>31))
713-
sample = 0x7FFF ^ (sample>>31);
714-
return sample;
715-
}
716-
717720
//----------------------------------------------------------------------------
718721
// LvmBundle_process()
719722
//----------------------------------------------------------------------------
@@ -2683,12 +2686,19 @@ int Effect_process(effect_handle_t self,
26832686
LOGV("\tLVM_ERROR : LvmBundle_process returned error %d", lvmStatus);
26842687
return lvmStatus;
26852688
}
2686-
}else{
2689+
} else {
26872690
//LOGV("\tEffect_process Not Calling process with %d effects enabled, %d called: Effect %d",
26882691
//pContext->pBundledContext->NumberEffectsEnabled,
26892692
//pContext->pBundledContext->NumberEffectsCalled, pContext->EffectType);
26902693
// 2 is for stereo input
2691-
memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
2694+
if (pContext->config.outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE) {
2695+
for (size_t i=0; i < outBuffer->frameCount*2; i++){
2696+
outBuffer->s16[i] =
2697+
clamp16((LVM_INT32)outBuffer->s16[i] + (LVM_INT32)inBuffer->s16[i]);
2698+
}
2699+
} else {
2700+
memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2);
2701+
}
26922702
}
26932703

26942704
return status;

0 commit comments

Comments
 (0)