esp-adf音频框架

ESP-ADF 在 ESP-IDF(乐鑫物联网开发框架,广泛运用于 ESP32 的 SDK)的基础上开发而成的一套音频开发框架。

Audio Element

audio_element对象是esp-adf开发套件的基本对象。每个解码器、编码器、滤波器、输入流、输出流均可以当成一个audio_element音频元素。
元素的一般功能是获取输入的一些数据,对其进行处理,然后输出到下一个。每个元素都可以当作一个独立的任务运行,为了能够控制从输入到输出的整个生命周期的特定阶段,audio_element对象提供了回调函数,可以在每个阶段进行触发。回调函数的类型主要有7种:open(打开), seek(查找)、 process(处理)、 close(关闭)、 destroy(销毁)、 read(读取)、 write(写入);它们被定义在在audio_element_cfg_t。

/**
 * @brief Audio Element configurations.
 *        Each Element at startup will be a self-running task.
 *        These tasks will execute the callback open -> [loop: read -> process -> write] -> close.
 *        These callback functions are provided by the user corresponding to this configuration.
 *
 */
typedef struct {
    
    
    el_io_func          open;             /*!< Open callback function */
    ctrl_func           seek;             /*!< Seek callback function */
    process_func        process;          /*!< Process callback function */
    el_io_func          close;            /*!< Close callback function */
    el_io_func          destroy;          /*!< Destroy callback function */
    stream_func         read;             /*!< Read callback function */
    stream_func         write;            /*!< Write callback function */
    int                 buffer_len;       /*!< Buffer length use for an Element */
    int                 task_stack;       /*!< Element task stack */
    int                 task_prio;        /*!< Element task priority (based on freeRTOS priority) */
    int                 task_core;        /*!< Element task running in core (0 or 1) */
    int                 out_rb_size;      /*!< Output ringbuffer size */
    void                *data;            /*!< User context */
    const char          *tag;             /*!< Element tag */
    bool                stack_in_ext;     /*!< Try to allocate stack in external memory */
    int                 multi_in_rb_num;  /*!< The number of multiple input ringbuffer */
    int                 multi_out_rb_num; /*!< The number of multiple output ringbuffer */
} audio_element_cfg_t;

文件位置
esp-adf\components\audio_pipeline\include\audio_element.h
esp-adf\components\audio_pipeline\audio_element.c

Audio Pipeline

audio_pipeline是实现一系列audio_element音频元素对象的动态组合。开发者不需要对每个audio_element音频元素对象进行单独处理,只需处理一个audio_pipeline。每个audio_element音频元素对象都由一个ringbuffer连接。audio_pipeline还负责将消息从元素任务转发到应用程序。一个典型的处理流程如图所示。
在这里插入图片描述将文件读取流、解码器、I2S流添加进audio_pipeline音频管道,解码器的输入是MP3文件数据流,I2S流将解码后的音频数据输出到片外,各应用程序之间通过事件接口通信。

文件位置
esp-adf\components\audio_pipeline\include\audio_pipeline.h
esp-adf\components\audio_pipeline\audio_pipeline.c

Audio Event Interface

ADF提供事件接口API来建立audio_pipeline管道中audio_element音频元素之间的通信。事件接口API是围绕FreeRTOS队列构建的,通过“监听器”来监视传入的消息并通过回调函数通知它们。

文件位置
esp-adf\components\audio_pipeline\include\audio_event_iface.h
esp-adf\components\audio_pipeline\audio_event_iface.c

猜你喜欢

转载自blog.csdn.net/liang_zhaocong/article/details/127401893