@@ -2459,6 +2459,9 @@ int Effect_setEnabled(EffectContext *pContext, bool enabled)
24592459 LOGV (" \t Effect_setEnabled() type %d, enabled %d" , pContext->EffectType , enabled);
24602460
24612461 if (enabled) {
2462+ // Bass boost or Virtualizer can be temporarily disabled if playing over device speaker due
2463+ // to their nature.
2464+ bool tempDisabled = false ;
24622465 switch (pContext->EffectType ) {
24632466 case LVM_BASS_BOOST:
24642467 if (pContext->pBundledContext ->bBassEnabled == LVM_TRUE) {
@@ -2471,6 +2474,7 @@ int Effect_setEnabled(EffectContext *pContext, bool enabled)
24712474 pContext->pBundledContext ->SamplesToExitCountBb =
24722475 (LVM_INT32)(pContext->pBundledContext ->SamplesPerSecond *0.1 );
24732476 pContext->pBundledContext ->bBassEnabled = LVM_TRUE;
2477+ tempDisabled = pContext->pBundledContext ->bBassTempDisabled ;
24742478 break ;
24752479 case LVM_EQUALIZER:
24762480 if (pContext->pBundledContext ->bEqualizerEnabled == LVM_TRUE) {
@@ -2495,6 +2499,7 @@ int Effect_setEnabled(EffectContext *pContext, bool enabled)
24952499 pContext->pBundledContext ->SamplesToExitCountVirt =
24962500 (LVM_INT32)(pContext->pBundledContext ->SamplesPerSecond *0.1 );
24972501 pContext->pBundledContext ->bVirtualizerEnabled = LVM_TRUE;
2502+ tempDisabled = pContext->pBundledContext ->bVirtualizerTempDisabled ;
24982503 break ;
24992504 case LVM_VOLUME:
25002505 if (pContext->pBundledContext ->bVolumeEnabled == LVM_TRUE) {
@@ -2508,7 +2513,9 @@ int Effect_setEnabled(EffectContext *pContext, bool enabled)
25082513 LOGV (" \t Effect_setEnabled() invalid effect type" );
25092514 return -EINVAL;
25102515 }
2511- LvmEffect_enable (pContext);
2516+ if (!tempDisabled) {
2517+ LvmEffect_enable (pContext);
2518+ }
25122519 } else {
25132520 switch (pContext->EffectType ) {
25142521 case LVM_BASS_BOOST:
@@ -3047,9 +3054,10 @@ int Effect_command(effect_handle_t self,
30473054 LOGV (" \t Effect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start" );
30483055 uint32_t device = *(uint32_t *)pCmdData;
30493056
3050- if (pContext->EffectType == LVM_BASS_BOOST){
3051- if ((device == AUDIO_DEVICE_OUT_SPEAKER)||(device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT)||
3052- (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
3057+ if (pContext->EffectType == LVM_BASS_BOOST) {
3058+ if ((device == AUDIO_DEVICE_OUT_SPEAKER) ||
3059+ (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) ||
3060+ (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
30533061 LOGV (" \t EFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d" ,
30543062 *(int32_t *)pCmdData);
30553063 LOGV (" \t EFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST" );
@@ -3058,30 +3066,31 @@ int Effect_command(effect_handle_t self,
30583066 // the effect must still report its original state as this can only be changed
30593067 // by the ENABLE/DISABLE command
30603068
3061- if (pContext->pBundledContext ->bBassEnabled == LVM_TRUE){
3069+ if (pContext->pBundledContext ->bBassEnabled == LVM_TRUE) {
30623070 LOGV (" \t EFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d" ,
30633071 *(int32_t *)pCmdData);
30643072 android::LvmEffect_disable (pContext);
3065- pContext->pBundledContext ->bBassTempDisabled = LVM_TRUE;
30663073 }
3067- }else {
3074+ pContext->pBundledContext ->bBassTempDisabled = LVM_TRUE;
3075+ } else {
30683076 LOGV (" \t EFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d" ,
30693077 *(int32_t *)pCmdData);
30703078
30713079 // If a device supports bassboost and the effect has been temporarily disabled
30723080 // previously then re-enable it
30733081
3074- if (pContext->pBundledContext ->bBassTempDisabled == LVM_TRUE){
3082+ if (pContext->pBundledContext ->bBassEnabled == LVM_TRUE) {
30753083 LOGV (" \t EFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d" ,
30763084 *(int32_t *)pCmdData);
30773085 android::LvmEffect_enable (pContext);
3078- pContext->pBundledContext ->bBassTempDisabled = LVM_FALSE;
30793086 }
3087+ pContext->pBundledContext ->bBassTempDisabled = LVM_FALSE;
30803088 }
30813089 }
3082- if (pContext->EffectType == LVM_VIRTUALIZER){
3083- if ((device == AUDIO_DEVICE_OUT_SPEAKER)||(device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT)||
3084- (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
3090+ if (pContext->EffectType == LVM_VIRTUALIZER) {
3091+ if ((device == AUDIO_DEVICE_OUT_SPEAKER)||
3092+ (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT)||
3093+ (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
30853094 LOGV (" \t EFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d" ,
30863095 *(int32_t *)pCmdData);
30873096 LOGV (" \t EFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER" );
@@ -3090,25 +3099,25 @@ int Effect_command(effect_handle_t self,
30903099 // the effect must still report its original state as this can only be changed
30913100 // by the ENABLE/DISABLE command
30923101
3093- if (pContext->pBundledContext ->bVirtualizerEnabled == LVM_TRUE){
3102+ if (pContext->pBundledContext ->bVirtualizerEnabled == LVM_TRUE) {
30943103 LOGV (" \t EFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d" ,
30953104 *(int32_t *)pCmdData);
30963105 android::LvmEffect_disable (pContext);
3097- pContext->pBundledContext ->bVirtualizerTempDisabled = LVM_TRUE;
30983106 }
3099- }else {
3107+ pContext->pBundledContext ->bVirtualizerTempDisabled = LVM_TRUE;
3108+ } else {
31003109 LOGV (" \t EFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d" ,
31013110 *(int32_t *)pCmdData);
31023111
31033112 // If a device supports virtualizer and the effect has been temporarily disabled
31043113 // previously then re-enable it
31053114
3106- if (pContext->pBundledContext ->bVirtualizerTempDisabled == LVM_TRUE){
3115+ if (pContext->pBundledContext ->bVirtualizerEnabled == LVM_TRUE){
31073116 LOGV (" \t EFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d" ,
31083117 *(int32_t *)pCmdData);
31093118 android::LvmEffect_enable (pContext);
3110- pContext->pBundledContext ->bVirtualizerTempDisabled = LVM_FALSE;
31113119 }
3120+ pContext->pBundledContext ->bVirtualizerTempDisabled = LVM_FALSE;
31123121 }
31133122 }
31143123 LOGV (" \t Effect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end" );
0 commit comments