diff options
Diffstat (limited to 'media/libeffects')
-rw-r--r-- | media/libeffects/data/audio_effects.conf | 39 | ||||
-rw-r--r-- | media/libeffects/factory/EffectsFactory.c | 4 | ||||
-rw-r--r-- | media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c | 5 | ||||
-rw-r--r-- | media/libeffects/lvm/lib/Bundle/src/LVM_Init.c | 7 | ||||
-rw-r--r-- | media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c | 3 | ||||
-rw-r--r-- | media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp | 272 | ||||
-rw-r--r-- | media/libeffects/lvm/wrapper/Bundle/EffectBundle.h | 2 | ||||
-rwxr-xr-x | media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp | 10 | ||||
-rwxr-xr-x | media/libeffects/preprocessing/PreProcessing.cpp | 10 | ||||
-rw-r--r-- | media/libeffects/testlibs/EffectEqualizer.cpp | 10 | ||||
-rw-r--r-- | media/libeffects/testlibs/EffectReverb.c | 8 | ||||
-rw-r--r-- | media/libeffects/visualizer/EffectVisualizer.cpp | 10 |
12 files changed, 211 insertions, 169 deletions
diff --git a/media/libeffects/data/audio_effects.conf b/media/libeffects/data/audio_effects.conf index d681c69..93f27cb 100644 --- a/media/libeffects/data/audio_effects.conf +++ b/media/libeffects/data/audio_effects.conf @@ -15,14 +15,18 @@ libraries { visualizer { path /system/lib/soundfx/libvisualizer.so } - pre_processing { - path /system/lib/soundfx/libaudiopreprocessing.so - } downmix { path /system/lib/soundfx/libdownmix.so } } +# Default pre-processing library. Add to audio_effect.conf "libraries" section if +# audio HAL implements support for default software audio pre-processing effects +# +# pre_processing { +# path /system/lib/soundfx/libaudiopreprocessing.so +# } + # list of effects to load. Each effect element must contain a "library" and a "uuid" element. # The value of the "library" element must correspond to the name of one library element in the # "libraries" element. @@ -79,19 +83,24 @@ effects { library downmix uuid 93f04452-e4fe-41cc-91f9-e475b6d1d69f } - agc { - library pre_processing - uuid aa8130e0-66fc-11e0-bad0-0002a5d5c51b - } - aec { - library pre_processing - uuid bb392ec0-8d4d-11e0-a896-0002a5d5c51b - } - ns { - library pre_processing - uuid c06c8400-8e06-11e0-9cb6-0002a5d5c51b - } } + +# Default pre-processing effects. Add to audio_effect.conf "effects" section if +# audio HAL implements support for them. +# +# agc { +# library pre_processing +# uuid aa8130e0-66fc-11e0-bad0-0002a5d5c51b +# } +# aec { +# library pre_processing +# uuid bb392ec0-8d4d-11e0-a896-0002a5d5c51b +# } +# ns { +# library pre_processing +# uuid c06c8400-8e06-11e0-9cb6-0002a5d5c51b +# } + # Audio preprocessor configurations. # The pre processor configuration consists in a list of elements each describing # pre processor settings for a given input source. Valid input source names are: diff --git a/media/libeffects/factory/EffectsFactory.c b/media/libeffects/factory/EffectsFactory.c index 59cd9e3..f158929 100644 --- a/media/libeffects/factory/EffectsFactory.c +++ b/media/libeffects/factory/EffectsFactory.c @@ -214,7 +214,7 @@ int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescriptor) while (gCurLib) { if (gCurEffect) { if (index == gCurEffectIdx) { - memcpy(pDescriptor, gCurEffect->object, sizeof(effect_descriptor_t)); + *pDescriptor = *(effect_descriptor_t *)gCurEffect->object; ret = 0; break; } else { @@ -251,7 +251,7 @@ int EffectGetDescriptor(const effect_uuid_t *uuid, effect_descriptor_t *pDescrip pthread_mutex_lock(&gLibLock); ret = findEffect(NULL, uuid, &l, &d); if (ret == 0) { - memcpy(pDescriptor, d, sizeof(effect_descriptor_t)); + *pDescriptor = *d; } pthread_mutex_unlock(&gLibLock); return ret; diff --git a/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c b/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c index 3b3c07c..32c4ce0 100644 --- a/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c +++ b/media/libeffects/lvm/lib/Bass/src/LVDBE_Init.c @@ -232,6 +232,10 @@ LVDBE_ReturnStatus_en LVDBE_Init(LVDBE_Handle_t *phInstance, pInstance->pData->AGCInstance.AGC_Gain = pInstance->pData->AGCInstance.AGC_MaxGain; /* Default to the bass boost setting */ + // initialize the mixer with some fixes values since otherwise LVDBE_SetVolume ends up + // reading uninitialized data + pMixer_Instance = &pInstance->pData->BypassVolume; + LVC_Mixer_Init(&pMixer_Instance->MixerStream[0],0x00007FFF,0x00007FFF); /* * Initialise the volume @@ -242,7 +246,6 @@ LVDBE_ReturnStatus_en LVDBE_Init(LVDBE_Handle_t *phInstance, pInstance->pData->AGCInstance.Volume = pInstance->pData->AGCInstance.Target; /* Initialise as the target */ - pMixer_Instance = &pInstance->pData->BypassVolume; MixGain = LVC_Mixer_GetTarget(&pMixer_Instance->MixerStream[0]); LVC_Mixer_Init(&pMixer_Instance->MixerStream[0],MixGain,MixGain); diff --git a/media/libeffects/lvm/lib/Bundle/src/LVM_Init.c b/media/libeffects/lvm/lib/Bundle/src/LVM_Init.c index 20370b7..542c3c8 100644 --- a/media/libeffects/lvm/lib/Bundle/src/LVM_Init.c +++ b/media/libeffects/lvm/lib/Bundle/src/LVM_Init.c @@ -961,6 +961,7 @@ LVM_ReturnStatus_en LVM_ClearAudioBuffers(LVM_Handle_t hInstance) LVM_InstParams_t InstParams; /* Instance parameters */ LVM_ControlParams_t Params; /* Control Parameters */ LVM_Instance_t *pInstance = (LVM_Instance_t *)hInstance; /* Pointer to Instance */ + LVM_HeadroomParams_t HeadroomParams; if(hInstance == LVM_NULL){ @@ -970,6 +971,9 @@ LVM_ReturnStatus_en LVM_ClearAudioBuffers(LVM_Handle_t hInstance) /* Save the control parameters */ /* coverity[unchecked_value] */ /* Do not check return value internal function calls */ LVM_GetControlParameters(hInstance, &Params); + /*Save the headroom parameters*/ + LVM_GetHeadroomParams(hInstance, &HeadroomParams); + /* Retrieve allocated buffers in memtab */ LVM_GetMemoryTable(hInstance, &MemTab, LVM_NULL); @@ -984,6 +988,9 @@ LVM_ReturnStatus_en LVM_ClearAudioBuffers(LVM_Handle_t hInstance) /* Restore control parameters */ /* coverity[unchecked_value] */ /* Do not check return value internal function calls */ LVM_SetControlParameters(hInstance, &Params); + /*Restore the headroom parameters*/ + LVM_SetHeadroomParams(hInstance, &HeadroomParams); + /* DC removal filter */ DC_2I_D16_TRC_WRA_01_Init(&pInstance->DC_RemovalInstance); diff --git a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c index e83e515..c4767a8 100644 --- a/media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c +++ b/media/libeffects/lvm/lib/Eq/src/LVEQNB_Init.c @@ -264,6 +264,9 @@ LVEQNB_ReturnStatus_en LVEQNB_Init(LVEQNB_Handle_t *phInstance, MemSize = (pCapabilities->MaxBands * sizeof(LVEQNB_BandDef_t)); pInstance->pBandDefinitions = (LVEQNB_BandDef_t *)InstAlloc_AddMember(&AllocMem, MemSize); + // clear all the bands, setting their gain to 0, otherwise when applying new params, + // it will compare against uninitialized values + memset(pInstance->pBandDefinitions, 0, MemSize); MemSize = (pCapabilities->MaxBands * sizeof(LVEQNB_BiquadType_en)); pInstance->pBiquadType = (LVEQNB_BiquadType_en *)InstAlloc_AddMember(&AllocMem, MemSize); diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp index 40dffd4..d706c2d 100644 --- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp +++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.cpp @@ -180,16 +180,16 @@ extern "C" int EffectQueryEffect(uint32_t index, effect_descriptor_t *pDescripto } if(index == LVM_BASS_BOOST){ ALOGV("\tEffectQueryEffect processing LVM_BASS_BOOST"); - memcpy(pDescriptor, &gBassBoostDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = gBassBoostDescriptor; }else if(index == LVM_VIRTUALIZER){ ALOGV("\tEffectQueryEffect processing LVM_VIRTUALIZER"); - memcpy(pDescriptor, &gVirtualizerDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = gVirtualizerDescriptor; } else if(index == LVM_EQUALIZER){ ALOGV("\tEffectQueryEffect processing LVM_EQUALIZER"); - memcpy(pDescriptor, &gEqualizerDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = gEqualizerDescriptor; } else if(index == LVM_VOLUME){ ALOGV("\tEffectQueryEffect processing LVM_VOLUME"); - memcpy(pDescriptor, &gVolumeDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = gVolumeDescriptor; } ALOGV("\tEffectQueryEffect end\n"); return 0; @@ -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); @@ -494,7 +498,7 @@ extern "C" int EffectGetDescriptor(const effect_uuid_t *uuid, return -EINVAL; } - memcpy(pDescriptor, desc, sizeof(effect_descriptor_t)); + *pDescriptor = *desc; return 0; } /* end EffectGetDescriptor */ @@ -698,10 +702,10 @@ int LvmBundle_init(EffectContext *pContext){ /* Set the headroom parameters */ HeadroomBandDef[0].Limit_Low = 20; HeadroomBandDef[0].Limit_High = 4999; - HeadroomBandDef[0].Headroom_Offset = 3; + HeadroomBandDef[0].Headroom_Offset = 0; HeadroomBandDef[1].Limit_Low = 5000; HeadroomBandDef[1].Limit_High = 24000; - HeadroomBandDef[1].Headroom_Offset = 4; + HeadroomBandDef[1].Headroom_Offset = 0; HeadroomParams.pHeadroomDefinition = &HeadroomBandDef[0]; HeadroomParams.Headroom_OperatingMode = LVM_HEADROOM_ON; HeadroomParams.NHeadroomBands = 2; @@ -965,7 +969,7 @@ int Effect_setConfig(EffectContext *pContext, effect_config_t *pConfig){ || pConfig->outputCfg.accessMode == EFFECT_BUFFER_ACCESS_ACCUMULATE); CHECK_ARG(pConfig->inputCfg.format == AUDIO_FORMAT_PCM_16_BIT); - memcpy(&pContext->config, pConfig, sizeof(effect_config_t)); + pContext->config = *pConfig; switch (pConfig->inputCfg.samplingRate) { case 8000: @@ -1011,6 +1015,8 @@ int Effect_setConfig(EffectContext *pContext, effect_config_t *pConfig){ LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "Effect_setConfig") if(LvmStatus != LVM_SUCCESS) return -EINVAL; + ActiveParams.SampleRate = SampleRate; + LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "Effect_setConfig") @@ -1041,7 +1047,7 @@ int Effect_setConfig(EffectContext *pContext, effect_config_t *pConfig){ void Effect_getConfig(EffectContext *pContext, effect_config_t *pConfig) { - memcpy(pConfig, &pContext->config, sizeof(effect_config_t)); + *pConfig = pContext->config; } /* end Effect_getConfig */ //---------------------------------------------------------------------------- @@ -1192,36 +1198,120 @@ 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 0 dB while +// preserving the relative band levels. // // Inputs: -// band: band number // pContext: effect engine context // // Outputs: // //---------------------------------------------------------------------------- -int32_t EqualizerGetBandLevel(EffectContext *pContext, int32_t band){ +void EqualizerLimitBandLevels(EffectContext *pContext) { + LVM_ControlParams_t ActiveParams; /* Current control Parameters */ + LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ - int32_t Gain =0; - 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); + + // Apply a volume correction to avoid clipping in the EQ based on 2 factors: + // - the maximum EQ band gain: the volume correction is such that the total of volume + max + // band gain is <= 0 dB + // - the average gain in all bands weighted by their proximity to max gain band. + int maxGain = 0; + int avgGain = 0; + int avgCount = 0; + for (int i = 0; i < FIVEBAND_NUMBANDS; i++) { + if (pContext->pBundledContext->bandGaindB[i] >= maxGain) { + int tmpMaxGain = pContext->pBundledContext->bandGaindB[i]; + int tmpAvgGain = 0; + int tmpAvgCount = 0; + for (int j = 0; j < FIVEBAND_NUMBANDS; j++) { + int gain = pContext->pBundledContext->bandGaindB[j]; + // skip current band and gains < 0 dB + if (j == i || gain < 0) + continue; + // no need to continue if one band not processed yet has a higher gain than current + // max + if (gain > tmpMaxGain) { + // force skipping "if (tmpAvgGain >= avgGain)" below as tmpAvgGain is not + // meaningful in this case + tmpAvgGain = -1; + break; + } + + int weight = 1; + if (j < (i + 2) && j > (i - 2)) + weight = 4; + tmpAvgGain += weight * gain; + tmpAvgCount += weight; + } + if (tmpAvgGain >= avgGain) { + maxGain = tmpMaxGain; + avgGain = tmpAvgGain; + avgCount = tmpAvgCount; + } + } + ActiveParams.pEQNB_BandDefinition[i].Frequency = EQNB_5BandPresetsFrequencies[i]; + ActiveParams.pEQNB_BandDefinition[i].QFactor = EQNB_5BandPresetsQFactors[i]; + ActiveParams.pEQNB_BandDefinition[i].Gain = pContext->pBundledContext->bandGaindB[i]; + } + + int gainCorrection = 0; + if (maxGain + pContext->pBundledContext->volume > 0) { + gainCorrection = maxGain + pContext->pBundledContext->volume; + } + if (avgCount) { + gainCorrection += avgGain/avgCount; + } - LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerGetBandLevel") + ALOGV("EqualizerLimitBandLevels() gainCorrection %d maxGain %d avgGain %d avgCount %d", + gainCorrection, maxGain, avgGain, avgCount); - BandDef = ActiveParams.pEQNB_BandDefinition; - Gain = (int32_t)BandDef[band].Gain*100; // Convert to millibels + ActiveParams.VC_EffectLevel = pContext->pBundledContext->volume - gainCorrection; + if (ActiveParams.VC_EffectLevel < -96) { + ActiveParams.VC_EffectLevel = -96; + } + + /* 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; + //ALOGV("\tEqualizerLimitBandLevels just set (-96dB -> 0dB) -> %d\n",ActiveParams.VC_EffectLevel ); + if(pContext->pBundledContext->firstVolume == LVM_TRUE){ + LvmStatus = LVM_SetVolumeNoSmoothing(pContext->pBundledContext->hInstance, &ActiveParams); + LVM_ERROR_CHECK(LvmStatus, "LVM_SetVolumeNoSmoothing", "LvmBundle_process") + ALOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks"); + pContext->pBundledContext->firstVolume = LVM_FALSE; + } +} + + +//---------------------------------------------------------------------------- +// 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; } //---------------------------------------------------------------------------- @@ -1246,30 +1336,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() //---------------------------------------------------------------------------- @@ -1395,25 +1467,14 @@ void EqualizerSetPreset(EffectContext *pContext, int preset){ //ALOGV("\tEqualizerSetPreset(%d)", preset); pContext->pBundledContext->CurPreset = preset; - LVM_ControlParams_t ActiveParams; /* Current control Parameters */ - LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ - - /* Get the current settings */ - LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); - LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "EqualizerSetPreset") - //ALOGV("\tEqualizerSetPreset Succesfully returned from LVM_GetControlParameters\n"); - //ActiveParams.pEQNB_BandDefinition = &BandDefs[0]; for (int i=0; i<FIVEBAND_NUMBANDS; i++) { - 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; @@ -1458,40 +1519,18 @@ const char * EqualizerGetPresetName(int32_t preset){ int VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){ - LVM_ControlParams_t ActiveParams; /* Current control Parameters */ - LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ - - //ALOGV("\tVolumeSetVolumeLevel Level to be set is %d %d\n", level, (LVM_INT16)(level/100)); - /* Get the current settings */ - LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); - LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel") - if(LvmStatus != LVM_SUCCESS) return -EINVAL; - //ALOGV("\tVolumeSetVolumeLevel Succesfully returned from LVM_GetControlParameters got: %d\n", - //ActiveParams.VC_EffectLevel); - - /* Volume parameters */ - ActiveParams.VC_EffectLevel = (LVM_INT16)(level/100); - //ALOGV("\tVolumeSetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel ); + if (level > 0 || level < -9600) { + return -EINVAL; + } - /* Activate the initial settings */ - LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); - LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetVolumeLevel") - if(LvmStatus != LVM_SUCCESS) return -EINVAL; + if (pContext->pBundledContext->bMuteEnabled == LVM_TRUE) { + pContext->pBundledContext->levelSaved = level / 100; + } else { + pContext->pBundledContext->volume = level / 100; + } - //ALOGV("\tVolumeSetVolumeLevel Succesfully called LVM_SetControlParameters\n"); + EqualizerLimitBandLevels(pContext); - /* Get the current settings */ - LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); - LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetVolumeLevel") - if(LvmStatus != LVM_SUCCESS) return -EINVAL; - - //ALOGV("\tVolumeSetVolumeLevel just set (-96dB -> 0dB) -> %d\n",ActiveParams.VC_EffectLevel ); - if(pContext->pBundledContext->firstVolume == LVM_TRUE){ - LvmStatus = LVM_SetVolumeNoSmoothing(pContext->pBundledContext->hInstance, &ActiveParams); - LVM_ERROR_CHECK(LvmStatus, "LVM_SetVolumeNoSmoothing", "LvmBundle_process") - ALOGV("\tLVM_VOLUME: Disabling Smoothing for first volume change to remove spikes/clicks"); - pContext->pBundledContext->firstVolume = LVM_FALSE; - } return 0; } /* end VolumeSetVolumeLevel */ @@ -1507,20 +1546,11 @@ int VolumeSetVolumeLevel(EffectContext *pContext, int16_t level){ int VolumeGetVolumeLevel(EffectContext *pContext, int16_t *level){ - //ALOGV("\tVolumeGetVolumeLevel start"); - - LVM_ControlParams_t ActiveParams; /* Current control Parameters */ - LVM_ReturnStatus_en LvmStatus = LVM_SUCCESS; /* Function call status */ - - LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); - LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeGetVolumeLevel") - if(LvmStatus != LVM_SUCCESS) return -EINVAL; - - //ALOGV("\tVolumeGetVolumeLevel() (-96dB -> 0dB) -> %d\n", ActiveParams.VC_EffectLevel ); - //ALOGV("\tVolumeGetVolumeLevel Succesfully returned from LVM_GetControlParameters\n"); - - *level = ActiveParams.VC_EffectLevel*100; // Convert dB to millibels - //ALOGV("\tVolumeGetVolumeLevel end"); + if (pContext->pBundledContext->bMuteEnabled == LVM_TRUE) { + *level = pContext->pBundledContext->levelSaved * 100; + } else { + *level = pContext->pBundledContext->volume * 100; + } return 0; } /* end VolumeGetVolumeLevel */ @@ -1540,32 +1570,16 @@ int32_t VolumeSetMute(EffectContext *pContext, uint32_t mute){ pContext->pBundledContext->bMuteEnabled = mute; - LVM_ControlParams_t ActiveParams; /* Current control Parameters */ - LVM_ReturnStatus_en LvmStatus=LVM_SUCCESS; /* Function call status */ - - /* Get the current settings */ - LvmStatus = LVM_GetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); - LVM_ERROR_CHECK(LvmStatus, "LVM_GetControlParameters", "VolumeSetMute") - if(LvmStatus != LVM_SUCCESS) return -EINVAL; - - //ALOGV("\tVolumeSetMute Succesfully returned from LVM_GetControlParameters\n"); - //ALOGV("\tVolumeSetMute to %d, level was %d\n", mute, ActiveParams.VC_EffectLevel ); - /* Set appropriate volume level */ if(pContext->pBundledContext->bMuteEnabled == LVM_TRUE){ - pContext->pBundledContext->levelSaved = ActiveParams.VC_EffectLevel; - ActiveParams.VC_EffectLevel = -96; + pContext->pBundledContext->levelSaved = pContext->pBundledContext->volume; + pContext->pBundledContext->volume = -96; }else{ - ActiveParams.VC_EffectLevel = pContext->pBundledContext->levelSaved; + pContext->pBundledContext->volume = pContext->pBundledContext->levelSaved; } - /* Activate the initial settings */ - LvmStatus = LVM_SetControlParameters(pContext->pBundledContext->hInstance, &ActiveParams); - LVM_ERROR_CHECK(LvmStatus, "LVM_SetControlParameters", "VolumeSetMute") - if(LvmStatus != LVM_SUCCESS) return -EINVAL; + EqualizerLimitBandLevels(pContext); - //ALOGV("\tVolumeSetMute Succesfully called LVM_SetControlParameters\n"); - //ALOGV("\tVolumeSetMute end"); return 0; } /* end setMute */ @@ -2723,7 +2737,7 @@ int Effect_process(effect_handle_t self, outBuffer->s16[i] = clamp16((LVM_INT32)outBuffer->s16[i] + (LVM_INT32)inBuffer->s16[i]); } - } else { + } else if (outBuffer->raw != inBuffer->raw) { memcpy(outBuffer->raw, inBuffer->raw, outBuffer->frameCount*sizeof(LVM_INT16)*2); } } @@ -3272,7 +3286,7 @@ int Effect_getDescriptor(effect_handle_t self, return -EINVAL; } - memcpy(pDescriptor, desc, sizeof(effect_descriptor_t)); + *pDescriptor = *desc; return 0; } /* end Effect_getDescriptor */ diff --git a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h index 5634ca1..330bb32 100644 --- a/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h +++ b/media/libeffects/lvm/wrapper/Bundle/EffectBundle.h @@ -95,6 +95,8 @@ struct BundledEffectContext{ int SamplesToExitCountVirt; LVM_INT16 *workBuffer; int frameCount; + int32_t bandGaindB[FIVEBAND_NUMBANDS]; + int volume; #ifdef LVM_PCM FILE *PcmInPtr; FILE *PcmOutPtr; diff --git a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp index 9599dcc..941d651 100755 --- a/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp +++ b/media/libeffects/lvm/wrapper/Reverb/EffectReverb.cpp @@ -206,7 +206,7 @@ extern "C" int EffectQueryEffect(uint32_t index, ALOGV("\tLVM_ERROR : EffectQueryEffect index out of range %d", index); return -ENOENT; } - memcpy(pDescriptor, gDescriptors[index], sizeof(effect_descriptor_t)); + *pDescriptor = *gDescriptors[index]; ALOGV("\tEffectQueryEffect end\n"); return 0; } /* end EffectQueryEffect */ @@ -330,7 +330,7 @@ extern "C" int EffectGetDescriptor(const effect_uuid_t *uuid, for (i = 0; i < length; i++) { if (memcmp(uuid, &gDescriptors[i]->uuid, sizeof(effect_uuid_t)) == 0) { - memcpy(pDescriptor, gDescriptors[i], sizeof(effect_descriptor_t)); + *pDescriptor = *gDescriptors[i]; ALOGV("EffectGetDescriptor - UUID matched Reverb type %d, UUID = %x", i, gDescriptors[i]->uuid.timeLow); return 0; @@ -645,7 +645,7 @@ int Reverb_setConfig(ReverbContext *pContext, effect_config_t *pConfig){ } //ALOGV("\tReverb_setConfig calling memcpy"); - memcpy(&pContext->config, pConfig, sizeof(effect_config_t)); + pContext->config = *pConfig; switch (pConfig->inputCfg.samplingRate) { @@ -715,7 +715,7 @@ int Reverb_setConfig(ReverbContext *pContext, effect_config_t *pConfig){ void Reverb_getConfig(ReverbContext *pContext, effect_config_t *pConfig) { - memcpy(pConfig, &pContext->config, sizeof(effect_config_t)); + *pConfig = pContext->config; } /* end Reverb_getConfig */ //---------------------------------------------------------------------------- @@ -2157,7 +2157,7 @@ int Reverb_getDescriptor(effect_handle_t self, } } - memcpy(pDescriptor, desc, sizeof(effect_descriptor_t)); + *pDescriptor = *desc; return 0; } /* end Reverb_getDescriptor */ diff --git a/media/libeffects/preprocessing/PreProcessing.cpp b/media/libeffects/preprocessing/PreProcessing.cpp index cfa7f51..597866a 100755 --- a/media/libeffects/preprocessing/PreProcessing.cpp +++ b/media/libeffects/preprocessing/PreProcessing.cpp @@ -517,6 +517,10 @@ int AecSetDevice(preproc_effect_t *effect, uint32_t device) webrtc::EchoControlMobile *aec = static_cast<webrtc::EchoControlMobile *>(effect->engine); webrtc::EchoControlMobile::RoutingMode mode = webrtc::EchoControlMobile::kQuietEarpieceOrHeadset; + if (audio_is_input_device(device)) { + return 0; + } + switch(device) { case AUDIO_DEVICE_OUT_EARPIECE: mode = webrtc::EchoControlMobile::kEarpiece; @@ -1700,7 +1704,7 @@ int PreProcessingFx_GetDescriptor(effect_handle_t self, return -EINVAL; } - memcpy(pDescriptor, sDescriptors[effect->procId], sizeof(effect_descriptor_t)); + *pDescriptor = *sDescriptors[effect->procId]; return 0; } @@ -1834,7 +1838,7 @@ int PreProcessingLib_QueryEffect(uint32_t index, effect_descriptor_t *pDescripto if (index >= PREPROC_NUM_EFFECTS) { return -EINVAL; } - memcpy(pDescriptor, sDescriptors[index], sizeof(effect_descriptor_t)); + *pDescriptor = *sDescriptors[index]; return 0; } @@ -1905,7 +1909,7 @@ int PreProcessingLib_GetDescriptor(const effect_uuid_t *uuid, ALOGV("PreProcessingLib_GetDescriptor() got fx %s", desc->name); - memcpy(pDescriptor, desc, sizeof(effect_descriptor_t)); + *pDescriptor = *desc; return 0; } diff --git a/media/libeffects/testlibs/EffectEqualizer.cpp b/media/libeffects/testlibs/EffectEqualizer.cpp index 35a4a61..90ebe1f 100644 --- a/media/libeffects/testlibs/EffectEqualizer.cpp +++ b/media/libeffects/testlibs/EffectEqualizer.cpp @@ -136,7 +136,7 @@ extern "C" int EffectQueryEffect(uint32_t index, if (index > 0) { return -EINVAL; } - memcpy(pDescriptor, &gEqualizerDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = gEqualizerDescriptor; return 0; } /* end EffectQueryNext */ @@ -204,7 +204,7 @@ extern "C" int EffectGetDescriptor(const effect_uuid_t *uuid, } if (memcmp(uuid, &gEqualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) { - memcpy(pDescriptor, &gEqualizerDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = gEqualizerDescriptor; return 0; } @@ -262,7 +262,7 @@ int Equalizer_setConfig(EqualizerContext *pContext, effect_config_t *pConfig) } CHECK_ARG(channelCount <= AudioBiquadFilter::MAX_CHANNELS); - memcpy(&pContext->config, pConfig, sizeof(effect_config_t)); + pContext->config = *pConfig; pContext->pEqualizer->configure(channelCount, pConfig->inputCfg.samplingRate); @@ -290,7 +290,7 @@ int Equalizer_setConfig(EqualizerContext *pContext, effect_config_t *pConfig) void Equalizer_getConfig(EqualizerContext *pContext, effect_config_t *pConfig) { - memcpy(pConfig, &pContext->config, sizeof(effect_config_t)); + *pConfig = pContext->config; } // end Equalizer_getConfig @@ -752,7 +752,7 @@ extern "C" int Equalizer_getDescriptor(effect_handle_t self, return -EINVAL; } - memcpy(pDescriptor, &android::gEqualizerDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = android::gEqualizerDescriptor; return 0; } diff --git a/media/libeffects/testlibs/EffectReverb.c b/media/libeffects/testlibs/EffectReverb.c index 8351712..a87a834 100644 --- a/media/libeffects/testlibs/EffectReverb.c +++ b/media/libeffects/testlibs/EffectReverb.c @@ -194,7 +194,7 @@ int EffectGetDescriptor(const effect_uuid_t *uuid, for (i = 0; i < length; i++) { if (memcmp(uuid, &gDescriptors[i]->uuid, sizeof(effect_uuid_t)) == 0) { - memcpy(pDescriptor, gDescriptors[i], sizeof(effect_descriptor_t)); + *pDescriptor = *gDescriptors[i]; ALOGV("EffectGetDescriptor - UUID matched Reverb type %d, UUID = %x", i, gDescriptors[i]->uuid.timeLow); return 0; @@ -440,7 +440,7 @@ int Reverb_GetDescriptor(effect_handle_t self, } } - memcpy(pDescriptor, desc, sizeof(effect_descriptor_t)); + *pDescriptor = *desc; return 0; } /* end Reverb_getDescriptor */ @@ -546,7 +546,7 @@ int Reverb_setConfig(reverb_module_t *pRvbModule, effect_config_t *pConfig, return -EINVAL; } - memcpy(&pRvbModule->config, pConfig, sizeof(effect_config_t)); + pRvbModule->config = *pConfig; pReverb->m_nSamplingRate = pRvbModule->config.outputCfg.samplingRate; @@ -644,7 +644,7 @@ int Reverb_setConfig(reverb_module_t *pRvbModule, effect_config_t *pConfig, void Reverb_getConfig(reverb_module_t *pRvbModule, effect_config_t *pConfig) { - memcpy(pConfig, &pRvbModule->config, sizeof(effect_config_t)); + *pConfig = pRvbModule->config; } /*---------------------------------------------------------------------------- diff --git a/media/libeffects/visualizer/EffectVisualizer.cpp b/media/libeffects/visualizer/EffectVisualizer.cpp index d3c69f4..44baf93 100644 --- a/media/libeffects/visualizer/EffectVisualizer.cpp +++ b/media/libeffects/visualizer/EffectVisualizer.cpp @@ -106,7 +106,7 @@ int Visualizer_setConfig(VisualizerContext *pContext, effect_config_t *pConfig) pConfig->outputCfg.accessMode != EFFECT_BUFFER_ACCESS_ACCUMULATE) return -EINVAL; if (pConfig->inputCfg.format != AUDIO_FORMAT_PCM_16_BIT) return -EINVAL; - memcpy(&pContext->mConfig, pConfig, sizeof(effect_config_t)); + pContext->mConfig = *pConfig; Visualizer_reset(pContext); @@ -130,7 +130,7 @@ int Visualizer_setConfig(VisualizerContext *pContext, effect_config_t *pConfig) void Visualizer_getConfig(VisualizerContext *pContext, effect_config_t *pConfig) { - memcpy(pConfig, &pContext->mConfig, sizeof(effect_config_t)); + *pConfig = pContext->mConfig; } @@ -190,7 +190,7 @@ int VisualizerLib_QueryEffect(uint32_t index, if (index > 0) { return -EINVAL; } - memcpy(pDescriptor, &gVisualizerDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = gVisualizerDescriptor; return 0; } @@ -253,7 +253,7 @@ int VisualizerLib_GetDescriptor(const effect_uuid_t *uuid, } if (memcmp(uuid, &gVisualizerDescriptor.uuid, sizeof(effect_uuid_t)) == 0) { - memcpy(pDescriptor, &gVisualizerDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = gVisualizerDescriptor; return 0; } @@ -561,7 +561,7 @@ int Visualizer_getDescriptor(effect_handle_t self, return -EINVAL; } - memcpy(pDescriptor, &gVisualizerDescriptor, sizeof(effect_descriptor_t)); + *pDescriptor = gVisualizerDescriptor; return 0; } /* end Visualizer_getDescriptor */ |