BES2700源码解析之音频的采集和播放

一 概述

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;
}
相关推荐
中微极客2 小时前
Seedance 2.5深度解析:30秒4K视频生成与50路多模态参考的工程实践
人工智能·音视频
sweetone2 小时前
一台磁带随身听的摩机(查出LAG668芯片低音差的原因)
经验分享·音视频
潜创微科技3 小时前
HDMI1.3无线投屏简介
音视频
西安老张(AIGC&ComfyUI)3 小时前
第027章:ComfyUI视频制作LTX-2.3模型(文生视频)
aigc·音视频·数字人·comfyui
USB_ABC4 小时前
郑州建业地产:高清音视频矩阵构筑智慧社区全域物联管控体系
矩阵·音视频
USB_ABC5 小时前
济南航天五院:高清数字矩阵赋能卫星研发数据可视化精准管控
矩阵·音视频
CoderYanger5 小时前
视频裁剪+缩放+自动添加水印脚本(Python版)
开发语言·后端·python·程序人生·职场和发展·音视频·学习方法
梦帮科技6 小时前
Rust+Tauri+EVM:构建下一代内存安全级数字版权(DRM)主权音频网络与跨链金融系统的技术实践与全景架构
网络·安全·架构·rust·区块链·音视频·web3.py
hz5678918 小时前
内网视频会议系统建设方案:适合政企单位的安全会议选择
安全·云计算·音视频·实时音视频·信息与通信
2601_9568657720 小时前
怎么用AI生成带货视频?电商内容创作工具推荐与选择思路
人工智能·aigc·音视频