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

Commit a8a56a8d authored by Andy Hung's avatar Andy Hung Committed by Automerger Merge Worker
Browse files

Merge "libeffects: Fix saturating add function" am: 28a7e941 am: 38a8de1e

Original change: https://android-review.googlesource.com/c/platform/frameworks/av/+/1543473

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I16ad5c1f38dd306ac070649c43949999d7da6287
parents 6a11026b 38a8de1e
Loading
Loading
Loading
Loading
+8 −24
Original line number Diff line number Diff line
@@ -18,7 +18,7 @@
/**********************************************************************************
   INCLUDE FILES
***********************************************************************************/

#include <algorithm>
#include "LVC_Mixer_Private.h"
#include "ScalarArithmetic.h"
#include "LVM_Macros.h"
@@ -26,16 +26,8 @@
/**********************************************************************************
   FUNCTION LVC_Core_MixSoft_1St_2i_D16C31_WRA
***********************************************************************************/
static LVM_FLOAT ADD2_SAT_FLOAT(LVM_FLOAT a, LVM_FLOAT b, LVM_FLOAT c) {
    LVM_FLOAT temp;
    temp = a + b;
    if (temp < -1.0f)
        c = -1.0f;
    else if (temp > 1.0f)
        c = 1.0f;
    else
        c = temp;
    return c;
static inline LVM_FLOAT ADD2_SAT_FLOAT(LVM_FLOAT a, LVM_FLOAT b) {
    return std::clamp(a + b, -1.0f, 1.0f);
}
void LVC_Core_MixSoft_1St_2i_D16C31_WRA(LVMixer3_FLOAT_st* ptrInstance1,
                                        LVMixer3_FLOAT_st* ptrInstance2, const LVM_FLOAT* src,
@@ -54,15 +46,12 @@ void LVC_Core_MixSoft_1St_2i_D16C31_WRA(LVMixer3_FLOAT_st* ptrInstance1,
    LVM_FLOAT CurrentR = pInstanceR->Current;
    LVM_FLOAT TargetR = pInstanceR->Target;

    LVM_FLOAT Temp = 0;

    InLoop = (LVM_INT16)(n >> 2); /* Process per 4 samples */
    OutLoop = (LVM_INT16)(n - (InLoop << 2));

    if (OutLoop) {
        if (CurrentL < TargetL) {
            ADD2_SAT_FLOAT(CurrentL, DeltaL, Temp);
            CurrentL = Temp;
            CurrentL = ADD2_SAT_FLOAT(CurrentL, DeltaL);
            if (CurrentL > TargetL) CurrentL = TargetL;
        } else {
            CurrentL -= DeltaL;
@@ -70,8 +59,7 @@ void LVC_Core_MixSoft_1St_2i_D16C31_WRA(LVMixer3_FLOAT_st* ptrInstance1,
        }

        if (CurrentR < TargetR) {
            ADD2_SAT_FLOAT(CurrentR, DeltaR, Temp);
            CurrentR = Temp;
            CurrentR = ADD2_SAT_FLOAT(CurrentR, DeltaR);
            if (CurrentR > TargetR) CurrentR = TargetR;
        } else {
            CurrentR -= DeltaR;
@@ -86,8 +74,7 @@ void LVC_Core_MixSoft_1St_2i_D16C31_WRA(LVMixer3_FLOAT_st* ptrInstance1,

    for (ii = InLoop * 2; ii != 0; ii -= 2) {
        if (CurrentL < TargetL) {
            ADD2_SAT_FLOAT(CurrentL, DeltaL, Temp);
            CurrentL = Temp;
            CurrentL = ADD2_SAT_FLOAT(CurrentL, DeltaL);
            if (CurrentL > TargetL) CurrentL = TargetL;
        } else {
            CurrentL -= DeltaL;
@@ -95,8 +82,7 @@ void LVC_Core_MixSoft_1St_2i_D16C31_WRA(LVMixer3_FLOAT_st* ptrInstance1,
        }

        if (CurrentR < TargetR) {
            ADD2_SAT_FLOAT(CurrentR, DeltaR, Temp);
            CurrentR = Temp;
            CurrentR = ADD2_SAT_FLOAT(CurrentR, DeltaR);
            if (CurrentR > TargetR) CurrentR = TargetR;
        } else {
            CurrentR -= DeltaR;
@@ -118,7 +104,6 @@ void LVC_Core_MixSoft_1St_2i_D16C31_WRA(LVMixer3_FLOAT_st* ptrInstance1,
void LVC_Core_MixSoft_1St_MC_float_WRA(Mix_Private_FLOAT_st** ptrInstance, const LVM_FLOAT* src,
                                       LVM_FLOAT* dst, LVM_INT16 NrFrames, LVM_INT16 NrChannels) {
    LVM_INT32 ii, ch;
    LVM_FLOAT Temp = 0.0f;
    LVM_FLOAT tempCurrent[NrChannels];
    for (ch = 0; ch < NrChannels; ch++) {
        tempCurrent[ch] = ptrInstance[ch]->Current;
@@ -130,8 +115,7 @@ void LVC_Core_MixSoft_1St_MC_float_WRA(Mix_Private_FLOAT_st** ptrInstance, const
            LVM_FLOAT Current = tempCurrent[ch];
            const LVM_FLOAT Target = pInstance->Target;
            if (Current < Target) {
                ADD2_SAT_FLOAT(Current, Delta, Temp);
                Current = Temp;
                Current = ADD2_SAT_FLOAT(Current, Delta);
                if (Current > Target) Current = Target;
            } else {
                Current -= Delta;