/**************************************************************************** DESCRIPTION sets the current A2dp volume */ void VolumeSetA2dp(uint16 index, uint16 oldVolume) { 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) { TonesPlayTone(theHeadset.audioData.gVolMaps[theHeadset.a2dp_link_data->gAvVolumeLevel[index]].Tone ,theHeadset.features.QueueVolumeTones, FALSE); } } #endif }
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 } }
/**************************************************************************** NAME audioHfpConnectAudio DESCRIPTION attempt to reconnect an audio connection from the sink value associcated with the passed hfp instance RETURNS */ void audioHfpConnectAudio (hfp_link_priority priority, Sink sink) { uint8 index = PROFILE_INDEX(priority); /* ensure sink is valid before trying to route audio */ TaskData *plugin = NULL; /* ensure a valid codec is negotiated, should be at least cvsd */ if(theSink.profile_data[index].audio.codec_selected) { AudioPluginFeatures features; /* determine additional features applicable for this audio plugin */ features.stereo = (AUDIO_PLUGIN_FORCE_STEREO || theSink.features.stereo); features.use_i2s_output = theSink.features.UseI2SOutputCapability; theSink.routed_audio = sink; plugin = audioHfpGetPlugin(theSink.profile_data[index].audio.codec_selected, theSink.features.audio_plugin); AUD_DEBUG(("AUD: plugin [%d] [%d], sink [%x]\n" , theSink.features.audio_plugin , theSink.profile_data[index].audio.codec_selected , (uint16)theSink.routed_audio)) ; /* connect audio using the audio plugin selected above */ AudioConnect ( plugin, theSink.routed_audio , theSink.profile_data[index].audio.link_type , theSink.codec_task , theSink.conf1->gVolMaps[ theSink.profile_data[index].audio.gSMVolumeLevel ].VolGain , theSink.profile_data[index].audio.tx_bandwidth , features , AUDIO_MODE_CONNECTED, AUDIO_ROUTE_INTERNAL, powerManagerGetLBIPM(), AUDIO_CONNECT_PARAMS, NULL ) ; audioControlLowPowerCodecs (TRUE) ; AUD_DEBUG(("AUD: Route SCO\n")); AUD_DEBUG(("Audio Connect[%d][%x]\n", theSink.features.audio_plugin , theSink.profile_data[index].audio.gSMVolumeLevel )) ; AudioSetVolume ( theSink.conf1->gVolMaps[ theSink.profile_data[index].audio.gSMVolumeLevel ].VolGain , TonesGetToneVolume(FALSE), theSink.codec_task ) ; /* mute control */ VolumeSetMicrophoneGain(priority, (theSink.profile_data[index].audio.gMuted ? VOLUME_MUTE_ON : VOLUME_MUTE_OFF)); } }
/**************************************************************************** NAME audioHfpConnectAudio DESCRIPTION attempt to reconnect an audio connection from the sink value associcated with the passed hfp instance RETURNS */ void audioHfpConnectAudio (hfp_link_priority priority, Sink sink) { uint8 index = PROFILE_INDEX(priority); /* ensure sink is valid before trying to route audio */ TaskData *plugin = NULL; /* ensure a valid codec is negotiated, should be at least cvsd */ if(theSink.profile_data[index].audio.codec_selected) { /* determine additional features applicable for this audio plugin */ theSink.routed_audio = sink; plugin = audioHfpGetPlugin(theSink.profile_data[index].audio.codec_selected, theSink.features.audio_plugin); AUD_DEBUG(("AUD: plugin [%d] [%d], sink [%x]\n" , theSink.features.audio_plugin , theSink.profile_data[index].audio.codec_selected , (uint16)theSink.routed_audio)) ; /* connect audio using the audio plugin selected above */ AudioConnect ( plugin, theSink.routed_audio , theSink.profile_data[index].audio.link_type , theSink.codec_task , theSink.conf1->volume_config.gVolMaps[ theSink.profile_data[index].audio.gSMVolumeLevel ].VolGain , theSink.profile_data[index].audio.tx_bandwidth , theSink.conf2->audio_routing_data.PluginFeatures , AUDIO_MODE_CONNECTED, AUDIO_ROUTE_INTERNAL, powerManagerGetLBIPM(), AUDIO_CONNECT_PARAMS, koovox.presentEnable, &theSink.task) ; DEBUG(("===presentEnable=%d\n", koovox.presentEnable)); audioControlLowPowerCodecs (TRUE) ; AUD_DEBUG(("AUD: Route SCO\n")); AUD_DEBUG(("Audio Connect[%d][%x]\n", theSink.features.audio_plugin , theSink.profile_data[index].audio.gSMVolumeLevel )) ; AudioSetVolume ( theSink.conf1->volume_config.gVolMaps[ theSink.profile_data[index].audio.gSMVolumeLevel ].VolGain , TonesGetToneVolume(FALSE), theSink.codec_task ) ; /* mute control */ VolumeSetMicrophoneGain(priority, (theSink.profile_data[index].audio.gMuted ? VOLUME_MUTE_ON : VOLUME_MUTE_OFF)); } }
/**************************************************************************** NAME usbAudioSetVolume DESCRIPTION Set USB audio volume RETURNS void */ void usbAudioSetVolume(void) { if(usbAudioSinkMatch(theSink.routed_audio) && USB_CLASS_ENABLED(USB_DEVICE_CLASS_AUDIO)) { Task plugin; AUDIO_MODE_T mode; uint16 volume = usbGetVolume(&mode); /* get usb plugin being used */ usbAudioGetPluginInfo(&plugin, theSink.usb.config.plugin_type, theSink.usb.config.plugin_index); /* Set volume if USB audio connected */ AudioSetVolume(volume, TonesGetToneVolume(FALSE), plugin); /* use a2dp connect parameters */ AudioSetMode(mode, &theSink.a2dp_link_data->a2dp_audio_mode_params); } }
/**************************************************************************** NAME connectAudio DESCRIPTION Connects the specified SCO/eSCO channel to the DSP. */ static void connectAudio(Sink audio_sink) { DEBUG_AGHFP((" connectAudio(0x%X)\n", (uint16)audio_sink)); if (audio_sink) { audio_codec_type codec = audio_codec_none; SendEvent(EVT_AUDIO_CONNECT_CFM,0); if(!the_app->bidirect_faststream) { /* Decide the plugin */ the_app->aghfp_audio_plugin = initScoPlugin(); ledSetProfile(LedTypeSCO,TRUE); /* Connect the audio plugin */ AudioConnect(the_app->aghfp_audio_plugin, audio_sink, the_app->sink_type, the_app->codecTask, 0x0a, 0, TRUE, AUDIO_MODE_CONNECTED, (void*)codec ); #ifdef KAL_MSG /* Switch the DSP to SCO mode */ PanicFalse(KalimbaSendMessage(KALIMBA_ENCODER_SELECT, EncoderSco, 0, 0, 0)); #endif AudioSetVolume(the_app->vgs,the_app->codecTask); CodecSetInputGainNow(the_app->codecTask,the_app->vgm,left_and_right_ch); the_app->active_encoder = EncoderSco; } } }
/**************************************************************************** NAME StartHearingDSP DESCRIPTION starts Hearing plugin and DSP with all the desired features, configurations and DAC gain RETURNS void */ void StartHearingDSP(void) { /* ensure sink is valid before trying to route audio */ TaskData *plugin = NULL; /* Configuring Audio features */ AudioPluginFeatures features; features.audio_output_type = OUTPUT_INTERFACE_TYPE_DAC; features.audio_input_routing = AUDIO_ROUTE_INTERNAL; features.use_one_mic_back_channel = 0; features.use_two_mic_back_channel = 0; features.stereo = (theSink.conf2->audio_routing_data.PluginFeatures.stereo) ? TRUE : FALSE; #ifdef HEP_1MIC plugin = (TaskData *)&alango_1mic_hearing_plugin; #elif defined(HEP_2MIC) plugin = (TaskData *)&alango_2mic_hearing_plugin; #endif AUD_DEBUG(("AUD: Start Hearing Mode\n")) ; /*Send works params*/ theSink.HearPhones_conf->Hearing.ActiveHearing = 1; /* connect audio using the audio plugin selected above */ AudioConnect ( plugin, 0 , theSink.profile_data[0].audio.link_type , theSink.codec_task , 10, 16000 , features , AUDIO_MODE_CONNECTED, AUDIO_ROUTE_INTERNAL, powerManagerGetLBIPM(), AUDIO_CONNECT_PARAMS, &theSink.task ); /* setting the desired volume */ AudioSetVolume ( theSink.HearPhones_conf->Hearing.volume , TonesGetToneVolume(FALSE), theSink.codec_task ) ; }