diff options
| author | jacqueline <me@jacqueline.id.au> | 2023-09-26 17:23:34 +1000 |
|---|---|---|
| committer | jacqueline <me@jacqueline.id.au> | 2023-09-26 17:23:34 +1000 |
| commit | 8608f9367fc29e498f42f5249aa248dd2044d567 (patch) | |
| tree | c8564bfe6bbc6c5a9413bbd29b4e52f2cf3bd35c /src/drivers | |
| parent | 4d99d22e10a3cb2a421da1618c127128816613c9 (diff) | |
| download | tangara-fw-8608f9367fc29e498f42f5249aa248dd2044d567.tar.gz | |
Tune buffer sizes and locations for I2S
Diffstat (limited to 'src/drivers')
| -rw-r--r-- | src/drivers/i2s_dac.cpp | 9 | ||||
| -rw-r--r-- | src/drivers/include/i2s_dac.hpp | 8 |
2 files changed, 14 insertions, 3 deletions
diff --git a/src/drivers/i2s_dac.cpp b/src/drivers/i2s_dac.cpp index 2fdd826f..b28a8ee1 100644 --- a/src/drivers/i2s_dac.cpp +++ b/src/drivers/i2s_dac.cpp @@ -41,8 +41,13 @@ static const i2s_port_t kI2SPort = I2S_NUM_0; auto I2SDac::create(IGpios& expander) -> std::optional<I2SDac*> { i2s_chan_handle_t i2s_handle; - i2s_chan_config_t channel_config = - I2S_CHANNEL_DEFAULT_CONFIG(kI2SPort, I2S_ROLE_MASTER); + i2s_chan_config_t channel_config{ + .id = kI2SPort, + .role = I2S_ROLE_MASTER, + .dma_desc_num = 2, + .dma_frame_num = kI2SBufferLengthFrames, + .auto_clear = false, + }; ESP_ERROR_CHECK(i2s_new_channel(&channel_config, &i2s_handle, NULL)); // diff --git a/src/drivers/include/i2s_dac.hpp b/src/drivers/include/i2s_dac.hpp index 6bc5b6a4..b61f7989 100644 --- a/src/drivers/include/i2s_dac.hpp +++ b/src/drivers/include/i2s_dac.hpp @@ -18,7 +18,6 @@ #include "esp_err.h" #include "freertos/FreeRTOS.h" #include "freertos/portmacro.h" -#include "freertos/ringbuf.h" #include "freertos/stream_buffer.h" #include "result.hpp" #include "span.hpp" @@ -28,6 +27,13 @@ namespace drivers { +// DMA max buffer size for I2S is 4092. We normalise to 2-channel, 16 bit +// audio, which gives us a max of 4092 / 2 / 2 (16 bits) frames. This in turn +// means that at 48kHz, we have about 21ms of budget to fill each buffer. +// We base this off of the maximum DMA size in order to minimise the amount of +// work the CPU has to do to service the DMA callbacks. +constexpr size_t kI2SBufferLengthFrames = 1023; + /** * Interface for a DAC that receives PCM samples over I2S. */ |
