From 1b6c677c4bad5c1aea4f01277cf5aa234ad4cab4 Mon Sep 17 00:00:00 2001 From: Eric Laurent Date: Mon, 10 Sep 2012 16:27:35 -0700 Subject: Limit maximum equalizer gain. Limit maximum gain in all EQ bands according to current volume so that total gain (current volume + band gain) does not exceed a certain limit. The gain difference between bands is preserved. Change-Id: Ice5a9705a0b3353e8778b4c539a29ca9cdf60390 --- .../libeffects/lvm/wrapper/Bundle/EffectBundle.cpp | 106 +++++++++++++-------- media/libeffects/lvm/wrapper/Bundle/EffectBundle.h | 2 + 2 files changed, 68 insertions(+), 40 deletions(-) (limited to 'media/libeffects') diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp index d4be9fa..f3f2d1e 100644 --- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp +++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp @@ -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; - LVM_ControlParams_t ActiveParams; /* Current control Parameters */ - LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ +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); - LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetBandLevel") + /* Get the current settings */ + 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); + + 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 */ diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h index 5634ca1..9c58ecd 100644 --- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h +++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h @@ -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; -- cgit v1.1