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

Commit 8a9e791c authored by Eric Laurent's avatar Eric Laurent Committed by Android (Google) Code Review
Browse files

Merge "Limit maximum equalizer gain." into jb-mr1-dev

parents ac19caca 1b6c677c
Loading
Loading
Loading
Loading
+66 −40
Original line number Diff line number Diff line
@@ -299,6 +299,10 @@ extern "C" int EffectCreate(const effect_uuid_t *uuid,
        pContext->pBundledContext->SamplesToExitCountBb     = 0;
        pContext->pBundledContext->SamplesToExitCountEq     = 0;

        for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
            pContext->pBundledContext->bandGaindB[i] = EQNB_5BandSoftPresets[i];
        }

        ALOGV("\tEffectCreate - Calling LvmBundle_init");
        ret = LvmBundle_init(pContext);

@@ -1194,36 +1198,71 @@ void VirtualizerSetStrength(EffectContext *pContext, uint32_t strength){
    //ALOGV("\tVirtualizerSetStrength Succesfully called LVM_SetControlParameters\n\n");
}    /* end setStrength */


//----------------------------------------------------------------------------
// EqualizerGetBandLevel()
// EqualizerLimitBandLevels()
//----------------------------------------------------------------------------
// Purpose: Retrieve the gain currently being used for the band passed in
// Purpose: limit all EQ band gains to a value less than MAX_BAND_GAIN_DB while
//          preserving the relative band levels.
//
// Inputs:
//  band:       band number
//  pContext:   effect engine context
//
// Outputs:
//
//----------------------------------------------------------------------------
int32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){

    int32_t Gain =0;
void EqualizerLimitBandLevels(EffectContext *pContext) {
    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
    LVM_EQNB_BandDef_t      *BandDef;

    /* Get the current settings */
    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance,
                                         &ActiveParams);
    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerLimitBandLevels")
    //ALOGV("\tEqualizerLimitBandLevels Succesfully returned from LVM_GetControlParameters\n");
    //ALOGV("\tEqualizerLimitBandLevels just Got -> %d\n",
    //          ActiveParams.pEQNB_BandDefinition[band].Gain);

    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetBandLevel")
    int gainCorrection = 0;
    for (int i = 0; i < FIVEBAND_NUMBANDS; i++) {
        int level = pContext->pBundledContext->bandGaindB[i] + ActiveParams.VC_EffectLevel;
        if (level > MAX_BAND_GAIN_DB) {
            int correction = MAX_BAND_GAIN_DB -level;
            if (correction < gainCorrection) {
                gainCorrection = correction;
            }
        }
    }

    /* Set local EQ parameters */
    BandDef = ActiveParams.pEQNB_BandDefinition;
    Gain    = (int32_t)BandDef[band].Gain*100;    // Convert to millibels
    for (int i=0; i < FIVEBAND_NUMBANDS; i++) {
        ActiveParams.pEQNB_BandDefinition[i].Gain = pContext->pBundledContext->bandGaindB[i] +
                gainCorrection;
    }
    /* Activate the initial settings */
    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerLimitBandLevels")
    //ALOGV("\tEqualizerLimitBandLevels just Set -> %d\n",
    //          ActiveParams.pEQNB_BandDefinition[band].Gain);
}


    //ALOGV("\tEqualizerGetBandLevel -> %d\n", Gain );
    //ALOGV("\tEqualizerGetBandLevel Succesfully returned from LVM_GetControlParameters\n");
    return Gain;
//----------------------------------------------------------------------------
// EqualizerGetBandLevel()
//----------------------------------------------------------------------------
// Purpose: Retrieve the gain currently being used for the band passed in
//
// Inputs:
//  band:       band number
//  pContext:   effect engine context
//
// Outputs:
//
//----------------------------------------------------------------------------
int32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){
    //ALOGV("\tEqualizerGetBandLevel -> %d\n", pContext->pBundledContext->bandGaindB[band] );
    return pContext->pBundledContext->bandGaindB[band] * 100;
}

//----------------------------------------------------------------------------
@@ -1248,30 +1287,12 @@ void EqualizerSetBandLevel(EffectContext *pContext, int band, short Gain){
        gainRounded = (int)((Gain-50)/100);
    }
    //ALOGV("\tEqualizerSetBandLevel(%d)->(%d)", Gain, gainRounded);


    LVM_ControlParams_t     ActiveParams;              /* Current control Parameters */
    LVM_ReturnStatus_en     LvmStatus=LVM_SUCCESS;     /* Function call status */
    LVM_EQNB_BandDef_t      *BandDef;

    /* Get the current settings */
    LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
    LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetBandLevel")
    //ALOGV("\tEqualizerSetBandLevel Succesfully returned from LVM_GetControlParameters\n");
    //ALOGV("\tEqualizerSetBandLevel just Got -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain);

    /* Set local EQ parameters */
    BandDef = ActiveParams.pEQNB_BandDefinition;
    ActiveParams.pEQNB_BandDefinition[band].Gain = gainRounded;

    /* Activate the initial settings */
    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetBandLevel")
    //ALOGV("\tEqualizerSetBandLevel just Set -> %d\n",ActiveParams.pEQNB_BandDefinition[band].Gain);

    pContext->pBundledContext->bandGaindB[band] = gainRounded;
    pContext->pBundledContext->CurPreset = PRESET_CUSTOM;
    return;

    EqualizerLimitBandLevels(pContext);
}

//----------------------------------------------------------------------------
// EqualizerGetCentreFrequency()
//----------------------------------------------------------------------------
@@ -1410,13 +1431,15 @@ void EqualizerSetPreset(EffectContext *pContext, int preset){
    {
        ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i];
        ActiveParams.pEQNB_BandDefinition[i].QFactor   = EQNB_5BandPresetsQFactors[i];
        ActiveParams.pEQNB_BandDefinition[i].Gain
        = EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
        pContext->pBundledContext->bandGaindB[i] =
                EQNB_5BandSoftPresets[i + preset * FIVEBAND_NUMBANDS];
    }
    /* Activate the new settings */
    LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams);
    LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "EqualizerSetPreset")

    EqualizerLimitBandLevels(pContext);

    //ALOGV("\tEqualizerSetPreset Succesfully called LVM_SetControlParameters\n");
    return;
}
@@ -1494,6 +1517,9 @@ int VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){
        ALOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks");
        pContext->pBundledContext->firstVolume = LVM_FALSE;
    }

    EqualizerLimitBandLevels(pContext);

    return 0;
}    /* end VolumeSetVolumeLevel */

+2 −0
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ extern "C" {
#define VOLUME_CUP_LOAD_ARM9E      0      // Expressed in 0.1 MIPS
#define BUNDLE_MEM_USAGE           25     // Expressed in kB
//#define LVM_PCM
#define MAX_BAND_GAIN_DB           4

#ifndef OPENSL_ES_H_
static const effect_uuid_t SL_IID_VOLUME_ = { 0x09e8ede0, 0xddde, 0x11db, 0xb4f6,
@@ -95,6 +96,7 @@ struct BundledEffectContext{
    int                             SamplesToExitCountVirt;
    LVM_INT16                       *workBuffer;
    int                             frameCount;
    int32_t                         bandGaindB[FIVEBAND_NUMBANDS];
    #ifdef LVM_PCM
    FILE                            *PcmInPtr;
    FILE                            *PcmOutPtr;