示例#1
0
int ZyxAudioStop(void)
{
    int ret = -1;

    if (pzma)
    {
        ZyxTrace("ZyxAudioStop");
        if (ZyxGetAudioState() == AAC_STATE_STOP)
        {
            pzma = NULL;
            return ret;
        }

        Media_Stop();
        //ret = mdi_audio_stop_all();
        MCI_AudioStopBuffer();
        ZyxTrace("zyx close ret=%d",ret);
        //if (ret == MEDIA_SUCCESS)	ret = 0;

        pzma->stat = AAC_STATE_STOP;

        pzma = NULL;
    }

    return ret;
}
示例#2
0
kal_bool BT_PcmLoopbackTest(void)
{
   kal_int16 i, count = 0;
   kal_uint16 *buf;
   kal_uint32 len = 0, acmLen = 0;
   kal_int32 magDB = 0;
   TD_Handle hdl;
   kal_uint16 *rb_base;
   
   AM_BluetoothOn(2);//2:open earphone mode, 1: open cordless mode
   AM_FlushQFunction();
   
   kal_prompt_trace(MOD_L1SP, "after set,DP_VOL_OUT_PCM= %d",*DP_VOL_OUT_PCM);
   
   /*initialize*/
   rb_base = (kal_uint16 *)get_ctrl_buffer(BTLB_BUF_LEN << 1);
   Media_SetBuffer( rb_base, BTLB_BUF_LEN );
   TD_Init( &hdl, TARGET_TONE, BLOCK_SIZE);

#ifdef BTLB_DEBUG
   pcmDebugCnt = 0;
   pcmDebugPtr = btlbPcmDebugBuf;
#endif
   /*start tone_play and record*/
   
   KT_Play(TARGET_TONE, 0, 0); /*play single tone , continuous play*/
   Media_Record(MEDIA_FORMAT_PCM_8K, BTLB_Handler, (void *)0);

   for (i = 0 ; i < 100 ; i++)/*if delay is large, we should enlarge this waiting*/
   {
      Media_GetReadBuffer(&buf ,&len);
      if ( len==0 )
         kal_sleep_task(1);
      else{
         if ( (len + acmLen) >= BLOCK_SIZE ){/*acumulated length >= BLOCK_SIZE*/
            len = BLOCK_SIZE - acmLen;/*recount samples to fit block*/
         }
         TD_ProcessBlock(&hdl, (kal_int16 *)buf, len);
#ifdef BTLB_DEBUG
{
         int j;
         for(j = 0 ; j < len ; j++ )
            if( pcmDebugCnt < 80000 )
            {
               *pcmDebugPtr++ = buf[j];
               pcmDebugCnt ++;
            }
}
#endif
         Media_ReadDataDone( len );
         acmLen += len;
         if ( acmLen >= BLOCK_SIZE){
            magDB = TD_GetMagnitudeDB( &hdl );
            kal_prompt_trace( MOD_L1SP, "magDB = %d", magDB);
            if( magDB > BTLB_TONE_MAG_DB_THRESHOLD )
              count ++;
            TD_Reset( &hdl );
            acmLen=0;//reset
         
            if ( count > 2)
               break;
         }
      }
   }

#ifdef BTLB_DEBUG
{
      int file_handle;
      kal_prompt_trace(MOD_L1SP, "prepare to dump pcm file");
      kal_wsprintf(debugFile, "d:\\BTLBdebug.pcm");
      file_handle = FS_Open(debugFile, FS_CREATE);
      if(file_handle > 0) 
      { 
         FS_Write( file_handle, (void *)btlbPcmDebugBuf, pcmDebugCnt << 1, NULL );
         FS_Close(file_handle);
         kal_prompt_trace(MOD_L1SP, "finish dump pcm file BTLBdebug.pcm");
      }
      else{
      	kal_prompt_trace(MOD_L1SP, "unable to dump file");
      }
      
}
#endif
   KT_StopAndWait();
   Media_Stop();
   AM_BluetoothOff();//close earphone mode
   /*close loopback path, should be removed in the future*/
   //*AFE_VAC_CON1 &= ~0x02;
   
   free_ctrl_buffer( rb_base );
   
   if ( count > 2){
      return true;
   }else
      return false;
}