当前位置: 首页 > news >正文

【ESP32 在线语音】音频接收的缓存机制

首先是初始化 I2S 设备中,可能用到了缓存

//初始化 I2S 设备 INMP441Serial.println("Setup I2S ...");i2s_install();i2s_setpin();esp_err_t err = i2s_start(I2S_PORT_0);

 其中的  i2s_install() 配置了 i2s 的相关设置,函数具体内容如下:

/*** @brief 配置 i2s 参数* */
void i2s_install()
{const i2s_config_t i2s_config = {.mode = (i2s_mode_t)(I2S_MODE_MASTER | I2S_MODE_RX),.sample_rate = SAMPLE_RATE,.bits_per_sample = i2s_bits_per_sample_t(16),.channel_format = I2S_CHANNEL_FMT_ONLY_LEFT,.communication_format = i2s_comm_format_t(I2S_COMM_FORMAT_STAND_I2S),.intr_alloc_flags = 0, // default interrupt priority.dma_buf_count = 8,.dma_buf_len = 1024,.use_apll = false};esp_err_t err = i2s_driver_install(I2S_PORT_0, &i2s_config, 0, NULL);if (err != ESP_OK){Serial.printf("I2S driver install failed (I2S_PORT_0): %d\n", err);while (true);}else{Serial.printf("I2S driver install OK\r\n");}
}

其中,与缓存有关的包括下面的结构体成员和 i2s_driver_install() 函数:

     .dma_buf_count = 8,.dma_buf_len = 1024,int                     dma_buf_count;              /**< The total number of DMA buffers to receive/transmit data.* A descriptor includes some information such as buffer address,* the address of the next descriptor, and the buffer length.* Since one descriptor points to one buffer, therefore, 'dma_desc_num' can be interpreted as the total number of DMA buffers used to store data from DMA interrupt.* Notice that these buffers are internal to'i2s_read' and descriptors are created automatically inside of the I2S driver.* Users only need to set the buffer number while the length is derived from the parameter described below.*/int                     dma_buf_len;                /**< Number of frames in a DMA buffer.*  A frame means the data of all channels in a WS cycle.*  The real_dma_buf_size = dma_buf_len * chan_num * bits_per_chan / 8.*  For example, if two channels in stereo mode (i.e., 'channel_format' is set to 'I2S_CHANNEL_FMT_RIGHT_LEFT') are active,*  and each channel transfers 32 bits (i.e., 'bits_per_sample' is set to 'I2S_BITS_PER_CHAN_32BIT'),*  then the total number of bytes of a frame is 'channel_format' * 'bits_per_sample' = 2 * 32 / 8 = 8 bytes.*  We assume that the current 'dma_buf_len' is 100, then the real length of the DMA buffer is 8 * 100 = 800 bytes.*  Note that the length of an internal real DMA buffer shouldn't be greater than 4092.*/

 从注释(Notice that these buffers are internal to'i2s_read)可以得到 , DMA功能的使用,指定即可,而不需要自己实现——内部会自动完成相关的配置。

 

i2s_driver_install() 函数定义如下

/*** @brief Install and start I2S driver.** @param i2s_num         I2S port number** @param i2s_config      I2S configurations - see i2s_config_t struct** @param queue_size      I2S event queue size/depth.*i2s 队列尺寸           I2S事件队列尺寸* @param i2s_queue       I2S event queue handle, if set NULL, driver will not use an event queue.* /*i2s 队列            I2S事件队列句柄* This function must be called before any I2S driver read/write operations.** @return*     - ESP_OK              Success*     - ESP_ERR_INVALID_ARG Parameter error*     - ESP_ERR_NO_MEM      Out of memory*     - ESP_ERR_INVALID_STATE  Current I2S port is in use*/
esp_err_t i2s_driver_install(i2s_port_t i2s_num, const i2s_config_t *i2s_config, int queue_size, void *i2s_queue);

 实际代码中没有使用,暂时也不知道所谓的 I2S 时间是什么?(莫非可能自动检测VAD端点检测?)

 

http://www.jsqmd.com/news/25054/

相关文章:

  • 我在iOS/Swift工程中成功编译了HarfBuzz!
  • Python access mysql and insert data batch by batch
  • CodeForces-2153D Not Alone
  • Codeforces Round 1062 (Div. 4)
  • 一文吃透银行账务打通体系闭环 - 智慧园区
  • uups 逻辑合约也增加了升级函数,那总体不是也费gas吗?
  • 【URP】Unity[纹理压缩]算法多平台对比
  • AI元人文构想:三值纠缠模型
  • EDK2环境搭建以及HelloWorld编译实现
  • 谁生?谁死?从引用计数到可达性分析,洞悉GC的决策逻辑
  • P1561 [USACO12JAN] Mountain Climbing S
  • 六、阅读笔记六:保障软件可靠性的防线
  • 五、阅读笔记五 应对复杂系统的挑战
  • P3988 [SHOI2013] 发牌
  • 映射
  • 文件夹显示绿色成功图标方法
  • 正点原子--手把手教你轻松入门C语言及STM32
  • 【RabbitMQ】与ASP.NET Core集成
  • IMO2025 Problem 1
  • Day6综合案例2-注册信息
  • 2014吉林省赛题解 | CCUT应用OJ——Sign in
  • 访答知识库-可以本地使用的知识库
  • 代码大全2 第三四章
  • https代理服务器(六)再次java动态签发【成功】
  • node
  • [AGC032D] Rotation Sort 题解
  • [AGC024E] Sequence Growing Hard 题解
  • 实验2 现代C++编程初体验
  • P7154 [USACO20DEC] Sleeping Cows P 题解
  • Java流程控制——switch多选择结构