uint32 EXT_BGSND_Start(void (*offHdr)(void),
                       void (*DLHisr)(void),       //move data from src -> ext
                       void (*ULHisr)(void),       //move data from src -> ext 
                       kal_int8 DLSNDGain,
                       kal_int8 ULSNDGain /*,                           
                       void (*EventHandler)(void)*/)
{
   int i, j;
   
   kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] Enter");
   
   ASSERT(!(NULL==DLHisr && NULL==ULHisr));
   ASSERT(NULL!=offHdr); //without this, we cannot stop DSP BGSND
     
   for(i=0; i<MAX_SIZE_EXT_BGSND_SRC; i++){
      kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug1 i=%d", i);
      if(!Ext_BGSnd.is_used[i]){
         kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug2 i=%d", i);
         EXT_BGSND_SRC_T *pSrc = &Ext_BGSnd.src[i];

         pSrc->Hdr[BGSND_DL_PROCESS]   = DLHisr;
         pSrc->Hdr[BGSND_UL_PROCESS]   = ULHisr;        
         pSrc->offHdr = offHdr;
         for(j=0; j<MAX_NUM_BGSND_PROCESS; j++){//TODO temp solution
            
            pSrc->state[j]  = EXT_SRC_STATE_RUN;      
            //pSrc->fSph[j]   = true; //TODO
            //pSrc->gain[j]   = 7;    //TODO     
            
         	// buffer reset
         	memset(pSrc->buffer[j], 0, sizeof(kal_uint16)*EXT_BGSND_SRC_BUF_SIZE);
         	pSrc->bufSize[j]  = EXT_BGSND_SRC_BUF_SIZE;
         	pSrc->bufRead[j]  = 0;
         	pSrc->bufWrite[j] = EXT_BGSND_BUF_PTR_DIFF;
         }   
         if(AM_IsSpeechOn() || AM_IsVoIPOn()){
            EXT_BGSND_ConfigMixer(i, true, DLSNDGain, BGSND_DL_PROCESS); 
            EXT_BGSND_ConfigMixer(i, true, ULSNDGain, BGSND_UL_PROCESS);
         }else{
            EXT_BGSND_ConfigMixer(i, false, DLSNDGain, BGSND_DL_PROCESS); 
            EXT_BGSND_ConfigMixer(i, false, ULSNDGain, BGSND_UL_PROCESS);            
         }         	
      	Ext_BGSnd.is_used[i] = true;     
         if( 0 == Ext_BGSnd.num_src_used++){
            kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] selected_src_id=%d num_src_used=%d", i,  Ext_BGSnd.num_src_used);
      	   // lock DSP for sherif writing.	
      	   L1Audio_SetFlag( Ext_BGSnd.aud_id ); // REIMIND: Before Locking SleepMode, to access DSP sherrif tasks much time. So access DSP must be after SetFlag1       
            DSP_BGSND_Start(EXT_BGSND_DLHisr, EXT_BGSND_ULHisr);
         }      	 	
         kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug3 i=%d", i);
      	break;
      }
      kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug4 i=%d", i);
   }   
   kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] debug5 i=%d", i);
   ASSERT(i < MAX_SIZE_EXT_BGSND_SRC);  
   kal_prompt_trace(MOD_L1SP, "[EXT_BGSND_Start] Leave");         
   return i;
}
static void DSP_BGSND_UpdateMixer() // private
{
   kal_prompt_trace(MOD_L1SP, "[DSP_BGSND_UpdateMixer] Enter");	   
   if ( AM_IsSpeechOn() || AM_IsVoIPOn()) {
   	SAL_Bgsnd_Config(DSP_BGSnd.gain[BGSND_UL_PROCESS], DSP_BGSnd.gain[BGSND_DL_PROCESS], DSP_BGSnd.fSph[BGSND_UL_PROCESS], DSP_BGSnd.fSph[BGSND_DL_PROCESS]);
   } else {
      //When enable BT, spe_setSpeechMode() will do Speech Off and Speech On. This function may run between Off and ON, so do not use ASSERT().
      //ASSERT(false);
      SAL_Bgsnd_Config(DSP_BGSnd.gain[BGSND_UL_PROCESS], DSP_BGSnd.gain[BGSND_DL_PROCESS], 0, 0);
   }
   kal_prompt_trace(MOD_L1SP, "[DSP_BGSND_UpdateMixer] Leave");	   
}
static void DSP_BGSND_Start(void (*Ext_DLHisr)(void), 
                            void (*Ext_ULHisr)(void))
{
   kal_prompt_trace(MOD_L1SP, "[DSP_BGSND_Start] Enter");
   ASSERT(AM_IsSpeechOn() || AM_IsVoIPOn());	
	
   DSP_BGSnd.Ext_Hisr[BGSND_DL_PROCESS]      = Ext_DLHisr;
   DSP_BGSnd.Ext_Hisr[BGSND_UL_PROCESS]      = Ext_ULHisr; 
	
#ifdef DSP_BGS_UP_DOWN_INT_SEPERATE
	L1Audio_HookHisrHandler(D2C_SOUND_EFFECT_INT_ID_DL, DSP_BGSND_Hisr, BGSND_DL_PROCESS);  
	L1Audio_HookHisrHandler(D2C_SOUND_EFFECT_INT_ID_UL, DSP_BGSND_Hisr, BGSND_UL_PROCESS);  
#else
	L1Audio_HookHisrHandler(D2C_SOUND_EFFECT_INT_ID_DL, DSP_BGSND_Shared_Hisr_DL_UL, 0);  	
#endif

	// gain setting and update 
	// Although these settings are allowed to modify during run time,
	// extended bgsnd should be fixed because the changes of volume from 
	// each sources are calculated in MCU side.
   DSP_BGSND_ConfigMixer(KAL_TRUE, 7, BGSND_UL_PROCESS);
	DSP_BGSND_ConfigMixer(KAL_TRUE, 7, BGSND_DL_PROCESS);

	DSP_BGSND_UpdateMixer();
	{  //turn on DSP BGSND
		uint32 I;
   	AM_SND_PlaybackOn();
   	SAL_Bgsnd_SetInit();		
		for( I = 0; ; I++ ) {
			if(SAL_Bgsnd_IsRunning())
				break;
			ASSERT_REBOOT( I < 20 );
			kal_sleep_task( 2 );
		}
	}	
	
	DSP_BGSnd.state = DSP_BGSND_STATE_RUN;
	kal_prompt_trace(MOD_L1SP, "[DSP_BGSND_Start] Leave");
}
Exemple #4
0
/*****************************************************************************
 * FUNCTION
 *  aud_rec_start_record
 * DESCRIPTION
 *  This function is to handle a record request. For normal record, the record
 *  process starts here. For video-call, the record process will be started
 *  when speech is on.
 * PARAMETERS
 *  ilm_ptr     [IN]
 * RETURNS
 *  void
 *****************************************************************************/
kal_int32 aud_rec_start_record(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    l4aud_media_record_req_struct *msg_p = NULL;
    kal_bool is_low_priority;
    kal_int32 result = MED_RES_OK;
    kal_uint8 resource = AUD_RESOURCE_SND_RECORD;
    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    msg_p = (l4aud_media_record_req_struct*) ilm_ptr->local_para_ptr;

    /* Check resource */
    if (!msg_p->default_input) /* FMR record */
    {
        resource = AUD_RESOURCE_FMR_RECORD;
    }


    if (! aud_media_is_resource_available(resource))
    {
        return MED_RES_BUSY;
    }

    /* if keytone is playing, stop it */
    aud_keytone_stop();

    /* if tone is playing, stop it */
    if (aud_context_p->tone_playing)
    {
        aud_tone_stop();
    }

#ifdef __MED_MMA_MOD__
    /* close all mma tasks */
    aud_mma_close_all();
#endif /* __MED_MMA_MOD__ */

    if (!(aud_context_p->state == AUD_MEDIA_RECORD ||
          aud_context_p->state == AUD_MEDIA_RECORD_PAUSED ||
          aud_context_p->state == AUD_MEDIA_WAIT_RECORD ||
          aud_context_p->state == AUD_VM_RECORD))
    {
        aud_stop_unfinished_process();
    }

    switch (aud_context_p->state)
    {
        case AUD_MEDIA_IDLE:
        {
            /* Check if there is enough space margin for recording */
            if ((result = aud_check_disc_space(msg_p->file_name, AUD_RECORD_MEM_MARGIN)) != MED_RES_OK)
            {
                return result;
            }
            
            /* Determine if we should use low priority record. If low priority record 
             * is applied, we will use MED-V thread to write data to file system - this 
             * could prevent MED thread from being blocked when writing data to file 
             * system. This also implies that if the MED thread doesn't have expected 
             * performance during record, we have to change the conditions for low 
             * priority record.
             */
        #if !defined(MED_V_NOT_PRESENT) && defined(__VOIP__)
            if ((msg_p->format == MEDIA_VOIPEVL) || AM_IsVoIPOn())
            {
                is_low_priority = KAL_TRUE;
            }
            else
        #endif /* #ifndef MED_V_NOT_PRESENT */
            {
                is_low_priority = KAL_FALSE;
            }

            /* Open a recorder handle */
            result = _aud_rec_recorder_open(msg_p->file_name,
                                            msg_p->format,
                                            msg_p->quality,
                                            is_low_priority,
                                            (kal_bool)(! msg_p->default_input),
                                            &aud_context_p->recorder_p);
            _AUD_MODULE_RECORD_TRACE(result);

            if ((result == MED_RES_OK) && (aud_context_p->recorder_p != NULL))
            {
                /* Set maximum record size and time */
                aud_context_p->recorder_p->set(aud_context_p->recorder_p, AUD_RECORDER_SET_SIZE_LIMIT, (void*)msg_p->size_limit, sizeof(kal_uint32));
                aud_context_p->recorder_p->set(aud_context_p->recorder_p, AUD_RECORDER_SET_TIME_LIMIT, (void*)msg_p->time_limit, sizeof(kal_uint32));

                /* Set input device of record. If the default input is not applied, it is FM record.
                 * Note that we have to restore input source when record is stopped.
                 */
                if (! msg_p->default_input)
                {
                    L1SP_SetInputSource(custom_cfg_hw_aud_input_path(msg_p->input_source));
                }

                /* If it is 3G324M, the recording will be started when speech is on. */
            #ifdef __MED_VCALL_MOD__
                if ((aud_context_p->rat_mode == RAT_3G324M_MODE) && !aud_context_p->speech_on)
                {
                    /* Enter wait-record state first. The recording will be started when speech is on. */
                    aud_enter_state(AUD_MEDIA_WAIT_RECORD);
                }
                else
            #endif /*__MED_VCALL_MOD__*/
                {
                    /* Start record */
                    result = _aud_rec_recorder_start();
                }
            }

            break;
        }
        default:
            result = MED_RES_BUSY;
            break;
    }

    return result;
}