void VolumeSetHeadsetVolume( uint16 pNewVolume , bool pPlayTone, hfp_link_priority priority, bool set_gain, volume_direction dir ) { bool lPlayTone = FALSE ; bool lOverideMute = theHeadset.features.OverideMute ; bool lMuteLocalVolAction = theHeadset.features.MuteLocalVolAction ; VOL_DEBUG(("SetVol [%x] [%d][%d][%d]\n " ,pNewVolume, theHeadset.gMuted , lOverideMute , lMuteLocalVolAction)) ; /* this should only occur if we are not muted or if we are muted but wish to overide */ if ( (!theHeadset.gMuted ) || ( lOverideMute ) || (lMuteLocalVolAction)) { /*set the local volume only*/ if ((theHeadset.gMuted) && (!lMuteLocalVolAction)) MessageSend( &theHeadset.task , EventMuteOff , 0 ) ; /* the tone needs to be played so set flag */ lPlayTone = TRUE ; /* set new volume */ theHeadset.profile_data[PROFILE_INDEX(priority)].audio.gSMVolumeLevel = pNewVolume ; if(set_gain) AudioSetVolume ( theHeadset.audioData.gVolMaps[ pNewVolume ].VolGain , theHeadset.codec_task ) ; } /* ensure there is a valid tone (non zero) to be played */ if( pPlayTone && lPlayTone && theHeadset.audioData.gVolMaps[pNewVolume].Tone ) { /*only attempt to play the tone if it has not yet been played*/ /*VOL_DEBUG(("VOL: VolTone[%x]\n" , (int)theHeadset.audioData.gVolMaps[pNewVolume].Tone)) ;*/ #if 1 if(theHeadset.TTS_ASR_Playing == false) { VOL_DEBUG(("VOL: VolTone[%x]\n" , (int)theHeadset.audioData.gVolMaps[pNewVolume].Tone)) ; #ifdef DifferentToneForVolumeButton if((stateManagerGetState() == headsetActiveCallSCO || stateManagerGetState() == headsetActiveCallNoSCO) && (theHeadset.sco_sink != 0)) { if(dir) { TonesPlayTone(0x42 ,theHeadset.features.QueueVolumeTones, FALSE); } else { TonesPlayTone(theHeadset.audioData.gVolMaps[pNewVolume].Tone ,theHeadset.features.QueueVolumeTones, FALSE); } } #else /*TonesPlayTone(theHeadset.audioData.gVolMaps[pNewVolume].Tone ,theHeadset.features.QueueVolumeTones, FALSE);*/ #endif } #endif } }
/**************************************************************************** DESCRIPTION sets the current A2dp volume */ void VolumeSetA2dp(uint16 index, uint16 oldVolume, volume_direction dir) { if(theHeadset.audioData.gVolMaps[ theHeadset.a2dp_link_data->gAvVolumeLevel[index] ].A2dpGain == VOLUME_A2DP_MUTE_GAIN) { /* if actual mute enabled, activate it now */ if(theHeadset.audioData.gVolMaps[ oldVolume ].A2dpGain != VOLUME_A2DP_MUTE_GAIN) { VOL_DEBUG(("VOL: A2dp mute\n")); AudioSetMode(AUDIO_MODE_MUTE_SPEAKER, NULL); } } else { VOL_DEBUG(("VOL: A2dp set vol [%d][%d]\n", theHeadset.a2dp_link_data->gAvVolumeLevel[index], theHeadset.audioData.gVolMaps[ theHeadset.a2dp_link_data->gAvVolumeLevel[index] ].A2dpGain - 1)); AudioSetVolume ( theHeadset.audioData.gVolMaps[ theHeadset.a2dp_link_data->gAvVolumeLevel[index] ].A2dpGain - 1 , theHeadset.codec_task ) ; } /* set volume level in audio plugin */ if ((theHeadset.audioData.gVolMaps[ theHeadset.a2dp_link_data->gAvVolumeLevel[index] ].A2dpGain != VOLUME_A2DP_MUTE_GAIN) && (theHeadset.audioData.gVolMaps[ oldVolume ].A2dpGain == VOLUME_A2DP_MUTE_GAIN)) { /* the audio was muted but now should be un-muted as above minimum volume */ VOL_DEBUG(("VOL: A2dp unmute\n")); AudioSetMode(AUDIO_MODE_CONNECTED, NULL); } /* play tone if applicable */ #if 1 if(theHeadset.audioData.gVolMaps[theHeadset.a2dp_link_data->gAvVolumeLevel[index]].Tone) { if(stateManagerGetState() == headsetA2DPStreaming) { #ifdef DifferentToneForVolumeButton if(dir) { VOL_DEBUG(("**Vol down tone = 0x42\n")); TonesPlayTone(0x42 ,theHeadset.features.QueueVolumeTones, FALSE); } else { VOL_DEBUG(("**Vol up tone = %d\n",theHeadset.audioData.gVolMaps[theHeadset.a2dp_link_data->gAvVolumeLevel[index]].Tone)); TonesPlayTone(theHeadset.audioData.gVolMaps[theHeadset.a2dp_link_data->gAvVolumeLevel[index]].Tone , theHeadset.features.QueueVolumeTones, FALSE); } #else /*TonesPlayTone(theHeadset.audioData.gVolMaps[theHeadset.a2dp_link_data->gAvVolumeLevel[index]].Tone ,theHeadset.features.QueueVolumeTones, FALSE);*/ #endif } } #endif }
/**************************************************************************** NAME StopHearingDSP DESCRIPTION stops Hearing plugin and DSP and disconnects all relevant audio. RETURNS void */ void StopHearingDSP(void) { LMEndMessage_t * lLMEndMessage = PanicUnlessMalloc(sizeof(LMEndMessage_t)); lLMEndMessage->Event = EventUsrSubwooferDisconnect; lLMEndMessage->PatternCompleted = TRUE; if (theSink.HearPhones_conf->Hearing.ActiveHearing) { AUD_DEBUG(("AUD: stop Hearing Mode\n")) ; SetAudioBusy(NULL); AudioDisconnect(); theSink.HearPhones_conf->Hearing.ActiveHearing = 0; MessageSend(&theSink.task, EventSysCancelLedIndication, 0);/*EventSysCancelLedIndication*/ MessageSend(&theSink.task, EventSysLEDEventComplete, lLMEndMessage);/*EventSysCancelLedIndication*/ #ifndef DSP_MY_FIRST_KALIMBA TonesPlayTone ( 50, TRUE , TRUE); #endif } }
/**************************************************************************** NAME TonesPlayEvent DESCRIPTION function to indaicate an event by playing its associated tone uses underlying tones playback RETURNS void */ void TonesPlayEvent ( sinkEvents_t pEvent ) { uint16 lEvent = pEvent; int i = 0 ; /* Don't play tone for Mute Toggle, this event is auto-converted to either EventUsrMuteOn or EventUsrMuteOff */ if (pEvent == EventUsrMuteToggle) return; #ifdef ENABLE_SOUNDBAR /* In Limbo for sound bar build, playing tones may cause panic if I2S amplifier is powered down by PIO */ if(stateManagerGetState() == deviceLimbo) { /* If sound bar I2S amplifier shut down is managed by PIO, first check the logic state of amplifier power pin */ if((theSink.conf2->audio_routing_data.PluginFeatures.audio_output_type == OUTPUT_INTERFACE_TYPE_I2S) &&(theSink.features.AmplifierShutDownByPIO)) { /* Check configuration for AMP pio drive */ if(theSink.conf1->PIOIO.pio_outputs.PowerOnPIO != NO_PIO) { /* Do not attempt to play tones through I2S if amplifier is shut down already, otherwise, I2C comms will fail and cause panic */ if(theSink.audioAmpPowerPin != TRUE) return; } } } #endif /* ensure sink is not in muted state or trying to play the mute reminder */ if((theSink.sink_enable_present != TRUE)||(pEvent == EventSysMuteReminder)||(pEvent == EventUsrMuteOn)) { /* If Audio Prompts are disabled go straight to tones. Otherwise if Audio Prompt is assigned to this event tone playback would be skipped.*/ if(theSink.audio_prompts_enabled) { /* If there's a valid Audio Prompt event to play don't play any tones */ if(AudioPromptPlayEvent( pEvent )) return; } /* scan available tones list, list end is signified by NOT_DEFINED */ while ( theSink.conf2->gEventTones [i].tone != TONE_NOT_DEFINED ) { /* if an event matche is found then play tone */ if (theSink.conf2->gEventTones [i].event == lEvent ) { /* turn on audio amp */ PioSetPio ( theSink.conf1->PIOIO.pio_outputs.DeviceAudioActivePIO , pio_drive, TRUE) ; /* start check to turn amp off again if required */ MessageSendLater(&theSink.task , EventSysCheckAudioAmpDrive, 0, 1000); /* check event as tone queueing not allowed on mute and ring tones */ switch(pEvent) { case EventSysMuteReminder: case EventSysRingtone1: case EventSysRingtone2: /* check whether to play mute reminder tone at default volume level, never queue mute reminders to protect against the case that the tone is longer than the mute reminder timer */ TonesPlayTone (theSink.conf2->gEventTones [ i ].tone ,FALSE, (theSink.features.MuteToneFixedVolume)) ; break; /* for all other events use the QueueEventTones feature bit setting */ default: /* play tone */ TonesPlayTone (theSink.conf2->gEventTones [ i ].tone ,theSink.features.QueueEventTones, FALSE ) ; break; } } i++ ; } } }