summaryrefslogtreecommitdiffstats
path: root/media/libeffects
diff options
context:
space:
mode:
authorEric Laurent <elaurent@google.com>2012-09-11 08:33:52 -0700
committerAndroid (Google) Code Review <android-gerrit@google.com>2012-09-11 08:33:53 -0700
commit8a9e791c0642084c1c6e758b7887b274392f5bb0 (patch)
tree98d16057b23f3e125142987921c736c4855ed60c /media/libeffects
parentac19caca75e7268c0a87bfcb2db73df1dd964616 (diff)
parent1b6c677c4bad5c1aea4f01277cf5aa234ad4cab4 (diff)
downloadframeworks_av-8a9e791c0642084c1c6e758b7887b274392f5bb0.zip
frameworks_av-8a9e791c0642084c1c6e758b7887b274392f5bb0.tar.gz
frameworks_av-8a9e791c0642084c1c6e758b7887b274392f5bb0.tar.bz2
Merge "Limit maximum equalizer gain." into jb-mr1-dev
Diffstat (limited to 'media/libeffects')
-rw-r--r--media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp106
-rw-r--r--media/libeffects/lvm/wrapper/Bundle/EffectBundle.h2
2 files changed, 68 insertions, 40 deletions
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;