@@ -2462,6 +2462,9 @@ int Effect_setEnabled(EffectContext *pContext, bool enabled)
24622462 LOGV (" \t Effect_setEnabled() type %d, enabled %d" , pContext->EffectType , enabled);
24632463
24642464 if (enabled) {
2465+ // Bass boost or Virtualizer can be temporarily disabled if playing over device speaker due
2466+ // to their nature.
2467+ bool tempDisabled = false ;
24652468 switch (pContext->EffectType ) {
24662469 case LVM_BASS_BOOST:
24672470 if (pContext->pBundledContext ->bBassEnabled == LVM_TRUE) {
@@ -2474,6 +2477,7 @@ int Effect_setEnabled(EffectContext *pContext, bool enabled)
24742477 pContext->pBundledContext ->SamplesToExitCountBb =
24752478 (LVM_INT32)(pContext->pBundledContext ->SamplesPerSecond *0.1 );
24762479 pContext->pBundledContext ->bBassEnabled = LVM_TRUE;
2480+ tempDisabled = pContext->pBundledContext ->bBassTempDisabled ;
24772481 break ;
24782482 case LVM_EQUALIZER:
24792483 if (pContext->pBundledContext ->bEqualizerEnabled == LVM_TRUE) {
@@ -2498,6 +2502,7 @@ int Effect_setEnabled(EffectContext *pContext, bool enabled)
24982502 pContext->pBundledContext ->SamplesToExitCountVirt =
24992503 (LVM_INT32)(pContext->pBundledContext ->SamplesPerSecond *0.1 );
25002504 pContext->pBundledContext ->bVirtualizerEnabled = LVM_TRUE;
2505+ tempDisabled = pContext->pBundledContext ->bVirtualizerTempDisabled ;
25012506 break ;
25022507 case LVM_VOLUME:
25032508 if (pContext->pBundledContext ->bVolumeEnabled == LVM_TRUE) {
@@ -2511,7 +2516,9 @@ int Effect_setEnabled(EffectContext *pContext, bool enabled)
25112516 LOGV (" \t Effect_setEnabled() invalid effect type" );
25122517 return -EINVAL;
25132518 }
2514- LvmEffect_enable (pContext);
2519+ if (!tempDisabled) {
2520+ LvmEffect_enable (pContext);
2521+ }
25152522 } else {
25162523 switch (pContext->EffectType ) {
25172524 case LVM_BASS_BOOST:
@@ -3057,9 +3064,10 @@ int Effect_command(effect_handle_t self,
30573064 LOGV (" \t Effect_command cmdCode Case: EFFECT_CMD_SET_DEVICE start" );
30583065 uint32_t device = *(uint32_t *)pCmdData;
30593066
3060- if (pContext->EffectType == LVM_BASS_BOOST){
3061- if ((device == AUDIO_DEVICE_OUT_SPEAKER)||(device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT)||
3062- (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
3067+ if (pContext->EffectType == LVM_BASS_BOOST) {
3068+ if ((device == AUDIO_DEVICE_OUT_SPEAKER) ||
3069+ (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT) ||
3070+ (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
30633071 LOGV (" \t EFFECT_CMD_SET_DEVICE device is invalid for LVM_BASS_BOOST %d" ,
30643072 *(int32_t *)pCmdData);
30653073 LOGV (" \t EFFECT_CMD_SET_DEVICE temporary disable LVM_BAS_BOOST" );
@@ -3068,30 +3076,31 @@ int Effect_command(effect_handle_t self,
30683076 // the effect must still report its original state as this can only be changed
30693077 // by the ENABLE/DISABLE command
30703078
3071- if (pContext->pBundledContext ->bBassEnabled == LVM_TRUE){
3079+ if (pContext->pBundledContext ->bBassEnabled == LVM_TRUE) {
30723080 LOGV (" \t EFFECT_CMD_SET_DEVICE disable LVM_BASS_BOOST %d" ,
30733081 *(int32_t *)pCmdData);
30743082 android::LvmEffect_disable (pContext);
3075- pContext->pBundledContext ->bBassTempDisabled = LVM_TRUE;
30763083 }
3077- }else {
3084+ pContext->pBundledContext ->bBassTempDisabled = LVM_TRUE;
3085+ } else {
30783086 LOGV (" \t EFFECT_CMD_SET_DEVICE device is valid for LVM_BASS_BOOST %d" ,
30793087 *(int32_t *)pCmdData);
30803088
30813089 // If a device supports bassboost and the effect has been temporarily disabled
30823090 // previously then re-enable it
30833091
3084- if (pContext->pBundledContext ->bBassTempDisabled == LVM_TRUE){
3092+ if (pContext->pBundledContext ->bBassEnabled == LVM_TRUE) {
30853093 LOGV (" \t EFFECT_CMD_SET_DEVICE re-enable LVM_BASS_BOOST %d" ,
30863094 *(int32_t *)pCmdData);
30873095 android::LvmEffect_enable (pContext);
3088- pContext->pBundledContext ->bBassTempDisabled = LVM_FALSE;
30893096 }
3097+ pContext->pBundledContext ->bBassTempDisabled = LVM_FALSE;
30903098 }
30913099 }
3092- if (pContext->EffectType == LVM_VIRTUALIZER){
3093- if ((device == AUDIO_DEVICE_OUT_SPEAKER)||(device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT)||
3094- (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
3100+ if (pContext->EffectType == LVM_VIRTUALIZER) {
3101+ if ((device == AUDIO_DEVICE_OUT_SPEAKER)||
3102+ (device == AUDIO_DEVICE_OUT_BLUETOOTH_SCO_CARKIT)||
3103+ (device == AUDIO_DEVICE_OUT_BLUETOOTH_A2DP_SPEAKER)){
30953104 LOGV (" \t EFFECT_CMD_SET_DEVICE device is invalid for LVM_VIRTUALIZER %d" ,
30963105 *(int32_t *)pCmdData);
30973106 LOGV (" \t EFFECT_CMD_SET_DEVICE temporary disable LVM_VIRTUALIZER" );
@@ -3100,25 +3109,25 @@ int Effect_command(effect_handle_t self,
31003109 // the effect must still report its original state as this can only be changed
31013110 // by the ENABLE/DISABLE command
31023111
3103- if (pContext->pBundledContext ->bVirtualizerEnabled == LVM_TRUE){
3112+ if (pContext->pBundledContext ->bVirtualizerEnabled == LVM_TRUE) {
31043113 LOGV (" \t EFFECT_CMD_SET_DEVICE disable LVM_VIRTUALIZER %d" ,
31053114 *(int32_t *)pCmdData);
31063115 android::LvmEffect_disable (pContext);
3107- pContext->pBundledContext ->bVirtualizerTempDisabled = LVM_TRUE;
31083116 }
3109- }else {
3117+ pContext->pBundledContext ->bVirtualizerTempDisabled = LVM_TRUE;
3118+ } else {
31103119 LOGV (" \t EFFECT_CMD_SET_DEVICE device is valid for LVM_VIRTUALIZER %d" ,
31113120 *(int32_t *)pCmdData);
31123121
31133122 // If a device supports virtualizer and the effect has been temporarily disabled
31143123 // previously then re-enable it
31153124
3116- if (pContext->pBundledContext ->bVirtualizerTempDisabled == LVM_TRUE){
3125+ if (pContext->pBundledContext ->bVirtualizerEnabled == LVM_TRUE){
31173126 LOGV (" \t EFFECT_CMD_SET_DEVICE re-enable LVM_VIRTUALIZER %d" ,
31183127 *(int32_t *)pCmdData);
31193128 android::LvmEffect_enable (pContext);
3120- pContext->pBundledContext ->bVirtualizerTempDisabled = LVM_FALSE;
31213129 }
3130+ pContext->pBundledContext ->bVirtualizerTempDisabled = LVM_FALSE;
31223131 }
31233132 }
31243133 LOGV (" \t Effect_command cmdCode Case: EFFECT_CMD_SET_DEVICE end" );
0 commit comments