Skip to content

Commit 79178b8

Browse files
Eric LaurentAndroid (Google) Code Review
authored andcommitted
Merge "Fix problem in lvm effect bundle wrapper." into ics-mr1
2 parents 8242cc4 + 8b4529e commit 79178b8

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)