|
3 | 3 | audio.cpp |
4 | 4 |
|
5 | 5 | Created on: Oct 28.2018 */char audioI2SVers[] ="\ |
6 | | - Version 3.1.0z "; |
7 | | -/* Updated on: May 07.2025 |
| 6 | + Version 3.2.0 "; |
| 7 | +/* Updated on: May 15.2025 |
8 | 8 |
|
9 | 9 | Author: Wolle (schreibfaul1) |
10 | | - Audio library for ESP32 or ESP32-S3 |
| 10 | + Audio library for ESP32, ESP32-S3 or ESP32-P4 |
11 | 11 | Arduino Vers. V3 is mandatory |
12 | 12 | external DAC is mandatory |
13 | 13 |
|
@@ -186,7 +186,7 @@ Audio::Audio(uint8_t i2sPort) { |
186 | 186 | // -------- I2S configuration ------------------------------------------------------------------------------------------- |
187 | 187 | m_i2s_chan_cfg.id = (i2s_port_t)m_i2s_num; // I2S_NUM_AUTO, I2S_NUM_0, I2S_NUM_1 |
188 | 188 | m_i2s_chan_cfg.role = I2S_ROLE_MASTER; // I2S controller master role, bclk and lrc signal will be set to output |
189 | | - m_i2s_chan_cfg.dma_desc_num = 4; // number of DMA buffer |
| 189 | + m_i2s_chan_cfg.dma_desc_num = 8; // number of DMA buffer |
190 | 190 | m_i2s_chan_cfg.dma_frame_num = 1024; // I2S frame number in one DMA buffer. |
191 | 191 | m_i2s_chan_cfg.auto_clear = true; // i2s will always send zero automatically if no data to send |
192 | 192 | i2s_new_channel(&m_i2s_chan_cfg, &m_i2s_tx_handle, NULL); |
@@ -250,13 +250,22 @@ void Audio::initInBuff() { |
250 | 250 |
|
251 | 251 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
252 | 252 | esp_err_t Audio::I2Sstart() { |
| 253 | + zeroI2Sbuff(); |
253 | 254 | return i2s_channel_enable(m_i2s_tx_handle); |
254 | 255 | } |
255 | 256 |
|
256 | 257 | esp_err_t Audio::I2Sstop() { |
| 258 | + memset(m_outBuff, 0, m_outbuffSize * sizeof(int16_t)); // Clear OutputBuffer |
257 | 259 | return i2s_channel_disable(m_i2s_tx_handle); |
258 | 260 | } |
259 | 261 | //------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 262 | +void Audio::zeroI2Sbuff(){ |
| 263 | + uint8_t *buff = (uint8_t*)calloc(128, sizeof(uint8_t)); // From IDF V5 there is no longer the zero_dma_buff() function. |
| 264 | + size_t bytes_loaded = 0; // As a replacement, we write a small amount of zeros in the buffer and thus reset the entire buffer. |
| 265 | + i2s_channel_preload_data(m_i2s_tx_handle, buff, 128, &bytes_loaded); |
| 266 | +} |
| 267 | +//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| 268 | + |
260 | 269 | void Audio::setDefaults() { |
261 | 270 | stopSong(); |
262 | 271 | initInBuff(); // initialize InputBuffer if not already done |
|
0 commit comments