一 概述
bes2700凭借着超高的性能,超低的功耗,在可穿戴领域有着广泛的应用。笔者使用该芯片做了一些产品解决方案,发现该芯片的性能十分强大。这里做个系列的源码解析。
二 源码解析
1.音频的参数初始化mic方向,主要是信道,采样率,音量大小,使用的麦克风等:
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
stream_cfg.vol = TGT_VOLUME_LEVEL_15;
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
stream_cfg.handler = app_factorymode_data_come;
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_capture);
stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE;
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_CAPTURE, &stream_cfg);
2.音频参数的初始化,spk方向:
stream_cfg.channel_num = AUD_CHANNEL_NUM_1;
stream_cfg.sample_rate = AUD_SAMPRATE_48000;
stream_cfg.device = AUD_STREAM_USE_INT_CODEC;
stream_cfg.vol = TGT_VOLUME_LEVEL_15;
stream_cfg.io_path = AUD_INPUT_PATH_MAINMIC;
stream_cfg.channel_num = AUD_CHANNEL_NUM_2;
stream_cfg.io_path = AUD_OUTPUT_PATH_SPEAKER;
stream_cfg.handler = app_factorymode_more_data;
stream_cfg.data_ptr = BT_AUDIO_CACHE_2_UNCACHE(buff_play);
stream_cfg.data_size = BT_AUDIO_FACTORMODE_BUFF_SIZE*2;
af_stream_open(AUD_STREAM_ID_0, AUD_STREAM_PLAYBACK, &stream_cfg);
三 总结
1.在函数:app_factorymode_data_come里面,这个就是mic的原始数据,可以在里面做音频算法处理。
static uint32_t app_factorymode_data_come(uint8_t *buf, uint32_t len)
{
DUMP16("%5d,",(short*)buf,30);
short POSSIBLY_UNUSED *pcm_buff = (short*)buf;
//DUMP16("%5d, ",pcm_buff,30);
int32_t POSSIBLY_UNUSED stime = 0;
static int32_t nsx_cnt = 0;
static int32_t dump_cnt = 0;
uint32_t POSSIBLY_UNUSED pcm_len = len>>1;
nsx_cnt++;
dump_cnt++;
// DUMP16("%d,",(short*)buf,30);
if(false == (nsx_cnt & 0xFF))
{
stime = hal_sys_timer_get();
//TRACE("aecm echo time: lens:%d g_time_cnt:%d ",len, g_time_cnt);
}
if(false == (nsx_cnt & 0xFF))
{
TRACE(1,"audio loopback 48k freq is:%d and pcm_lens:%d ", hal_sysfreq_get(), pcm_len);
}
app_audio_pcmbuff_put(buf, len);
if (a2dp_cache_status == APP_AUDIO_CACHE_QTY){
a2dp_cache_status = APP_AUDIO_CACHE_OK;
}
return len;
}
2.在函数:app_factorymode_more_data里面,这个就是输出到dac的原始数据,可以在里面做音频算法处理。
static uint32_t app_factorymode_more_data(uint8_t *buf, uint32_t len)
{
if (a2dp_cache_status != APP_AUDIO_CACHE_QTY){
app_audio_pcmbuff_get((uint8_t *)app_audioloop_play_cache, len/2);
app_bt_stream_copy_track_one_to_two_16bits((int16_t *)buf, app_audioloop_play_cache, len/2/2);
}
return len;
}