int ZyxAudioOpen(PU8 audio_buf,int size,ZYX_MEDIA_TYPE format, ZyxAudioHandler cb) { if (audio_buf == NULL) return -1; ZyxTrace("ZyxAudioOpen 1\n"); mdi_audio_stop_all(); ZyxTrace("ZyxAudioOpen 2\n"); //mute bug??? DM_SetAudioVolume(zma.volume); MusicStartAudioMode(); ZyxTrace("ZyxAudioOpen 3\n"); ZyxTrace("zyx audio buf=%x,size=%d",audio_buf, size); if (pzma) { ZyxTrace("zyx stop audio first"); return -1; } if (NULL == pzma) { ZyxAudioHandlerCallback = cb; switch (format) { case ZYX_AUDIO_FORMAT_AAC: pzma = &zma; pzma->format = ZYX_AUDIO_FORMAT_AAC; break; case ZYX_AUDIO_FORMAT_AMR: pzma = &zma; pzma->format = ZYX_AUDIO_FORMAT_AMR; break; default: return -1; break; } ZyxTrace("zyx pzma = 0x%x", pzma); if (pzma) { pzma->current_time = 0; pzma->start_time = 0; pzma->stat = AAC_STATE_STOP; Media_SetBuffer((U16*)audio_buf, (U32)size/2); } } return 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; }