Example #1
0
/****************************************************************************
NAME
    ChangeHearingProfile
DESCRIPTION
    changes Hearing profiles. This function is called by user events to help the user change the current Hearing profile
	while DSP is running. When user event occures, this function sends a MESSAGE_HEARING_CHANGE_PARAMS to the plugin but only if the Audio is free.
	If Audio is busy the functin will just cancell all the pending MESSAGE_HEARING_CHANGE_PARAMS.

RETURNS
    void
*/
void ChangeHearingProfile(profile_direction dir)
{
    TaskData *plugin = NULL;

#ifdef HEP_1MIC
    plugin = (TaskData *)&alango_1mic_hearing_plugin;
#elif defined(HEP_2MIC)
    plugin = (TaskData *)&alango_2mic_hearing_plugin;
#endif
    if (theSink.HearPhones_conf->Hearing.ActiveHearing)
    {
        if ( dir == next_profile )
            theSink.HearPhones_conf->Hearing.profile = (theSink.HearPhones_conf->Hearing.profile == theSink.HearPhones_conf->Hearing.Num_Of_Profiles-1) ? 0 : theSink.HearPhones_conf->Hearing.profile + 1;
        else
            theSink.HearPhones_conf->Hearing.profile = (theSink.HearPhones_conf->Hearing.profile == 0) ? theSink.HearPhones_conf->Hearing.Num_Of_Profiles-1 : theSink.HearPhones_conf->Hearing.profile - 1;
        MessageCancelAll ( plugin, MESSAGE_HEARING_CHANGE_PARAMS);
        /* AlangoPluginChangeParamsHearing() uses SetAudioBusy() and only after receiving from Kalimba HEP_PARAMS_LOADED_MSG VM will will set SetAudioBusy() to false.
        	if kalimba stops repond with HEP_PARAMS_LOADED_MSG for any reason VM will NOT ask Kalimba to MESSAGE_HEARING_CHANGE_PARAMS again as long Audio is busy*/
        if ( IsAudioBusy() == FALSE )
            MessageSendLater ( plugin, MESSAGE_HEARING_CHANGE_PARAMS , NULL , D_SEC(0.15) );/* The message is sent with 150ms delay in order to prevent the user hiting
																								the profile change button to fast. any push fastr than 150ms will be cancelled
																								by MessageCancelAll() above and reschedualed to 150ms later*/
    }
}
/****************************************************************************
DESCRIPTION

    messages from the audio library are received here. 
    and converted into function calls to be implemented in the 
    plugin module
*/ 
static void handleAudioMessage ( Task task , MessageId id, Message message )     
{
    switch (id)
    {
        case (AUDIO_PLUGIN_VOICE_PROMPTS_INIT_MSG ):
        {
            AUDIO_PLUGIN_VOICE_PROMPTS_INIT_MSG_T * init_message = (AUDIO_PLUGIN_VOICE_PROMPTS_INIT_MSG_T *)message;
            CsrVoicePromptsPluginInit(init_message->no_prompts, init_message->no_languages);
        }
        break;
        
        case (AUDIO_PLUGIN_PLAY_AUDIO_PROMPT_MSG ):
        {
            AUDIO_PLUGIN_PLAY_AUDIO_PROMPT_MSG_T * prompt_message = (AUDIO_PLUGIN_PLAY_AUDIO_PROMPT_MSG_T *)message ;
                           
            /* if the audio is currently busy then queue this audio prompt request, or if the audio plugin is in an 'about to be loaded state', queue until it is
                                     loaded and running */
            if ((IsAudioBusy())||(GetCurrentDspStatus() && (GetCurrentDspStatus() != DSP_RUNNING)))
            {    
                if ( prompt_message->can_queue) 
                {                
                    MAKE_AUDIO_MESSAGE( AUDIO_PLUGIN_PLAY_AUDIO_PROMPT_MSG) ; 
                    memmove(message, prompt_message, sizeof(AUDIO_PLUGIN_PLAY_AUDIO_PROMPT_MSG_T));
                    MessageSendConditionally ( task , AUDIO_PLUGIN_PLAY_AUDIO_PROMPT_MSG, message ,(const uint16 *)AudioBusyPtr() ) ;
                    PRINT(("VP:Queue\n")); 
                }
            }
            else
            {
                CsrVoicePromptsPluginPlayPhrase (prompt_message->id,
                    prompt_message->language, prompt_message->codec_task,
                    prompt_message->ap_volume, prompt_message->features);
                PRINT(("VP:start\n"));
            } 
        }
        break ;
        
        case (AUDIO_PLUGIN_STOP_AUDIO_PROMPT_MSG ):
            CsrVoicePromptsPluginStopPhrase() ;
        break;
        
		case (AUDIO_PLUGIN_PLAY_TONE_MSG ):
		{
			AUDIO_PLUGIN_PLAY_TONE_MSG_T * tone_message = (AUDIO_PLUGIN_PLAY_TONE_MSG_T *)message ;
			
			if (IsAudioBusy()) 
			{	
				if ( tone_message->can_queue) /*then re-queue the tone*/
				{				
					MAKE_AUDIO_MESSAGE( AUDIO_PLUGIN_PLAY_TONE_MSG ) ; 
					
					message->tone        = tone_message->tone       ;
					message->can_queue   = tone_message->can_queue  ;
					message->codec_task  = tone_message->codec_task ;
					message->tone_volume = tone_message->tone_volume;
					message->features    = tone_message->features   ;
	
					PRINT(("VP: tone Q\n"));
					
					MessageSendConditionally ( task , AUDIO_PLUGIN_PLAY_TONE_MSG, message ,(const uint16 *)AudioBusyPtr() ) ;			
				}
			}
			else
			{			
				PRINT(("VP:tone start\n"));

        		CsrVoicePromptsPluginPlayTone (task, tone_message->tone,
                                tone_message->codec_task,
                                tone_message->tone_volume,
                                tone_message->features) ;
			}
							     
		}
		break ;        
        
		case (AUDIO_PLUGIN_STOP_TONE_MSG ):
            CsrVoicePromptsPluginStopPhrase() ;
		break ;		        
        
        default:
            /*other messages do not need to be handled by the voice prompts plugin*/
        break ;
    }
}