I'm confused about something, the DMA buffer that the i2s creates is not the size I expect.
According to the documentation:
This equation does not hold up for a slot width of 8bits. As an example if I have slot_bit_width=8 with slot_num=9 and dma_frame_num=32 I would expect to get a dma_buffer_size of 288bytes but the function i2s_get_buf_size() will actually return a buffer size of 576bytes. So when using a slot_bit_width of 8, I will always get a buffer size that is double the dma_frame_num which is certainly not what I want. This is because of the bytes_per_sample calculation.dma_buffer_size = dma_frame_num * slot_num * slot_bit_width / 8
uint32_t bytes_per_sample = ((data_bit_width + 15) / 16) * 2;
Code: Select all
uint32_t i2s_get_buf_size(i2s_chan_handle_t handle, uint32_t data_bit_width, uint32_t dma_frame_num)
{
uint32_t active_chan = handle->active_slot;
uint32_t bytes_per_sample = ((data_bit_width + 15) / 16) * 2;
uint32_t bytes_per_frame = bytes_per_sample * active_chan;
uint32_t bufsize = dma_frame_num * bytes_per_frame;
/* Limit DMA buffer size if it is out of range (DMA buffer limitation is 4092 bytes) */
if (bufsize > I2S_DMA_BUFFER_MAX_SIZE) {
uint32_t frame_num = I2S_DMA_BUFFER_MAX_SIZE / bytes_per_frame;
bufsize = frame_num * bytes_per_frame;
ESP_LOGW(TAG, "dma frame num is out of dma buffer size, limited to %"PRIu32, frame_num);
}
return bufsize;
}
Am I doing something wrong? Or is this a bug in the driver code? Thank you for your help.