33 audio.cpp
44
55 Created on: Oct 28.2018 */ char audioI2SVers[] =" \
6- Version 3.4.2h " ;
7- /* Updated on: Sep 05 .2025
6+ Version 3.4.2i " ;
7+ /* Updated on: Sep 07 .2025
88
99 Author: Wolle (schreibfaul1)
1010 Audio library for ESP32, ESP32-S3 or ESP32-P4
@@ -136,7 +136,7 @@ void AudioBuffer::bytesWritten(size_t bw) {
136136 if (!bw) return ;
137137 m_writePtr += bw;
138138 if (m_writePtr == m_endPtr) { m_writePtr = m_buffer.get (); }
139- if (m_writePtr > m_endPtr) log_e (" AudioBuffer: m_writePtr %i > m_endPtr %i " , m_writePtr, m_endPtr);
139+ if (m_writePtr > m_endPtr) log_e (" AudioBuffer: m_writePtr %p > m_endPtr %p " , m_writePtr, m_endPtr);
140140 m_f_isEmpty = false ;
141141}
142142
@@ -183,13 +183,16 @@ Audio::Audio(uint8_t i2sPort) {
183183 m_i2s_num = i2sPort; // i2s port number
184184
185185 // -------- I2S configuration -------------------------------------------------------------------------------------------
186+ memset (&m_i2s_chan_cfg, 0 , sizeof (i2s_chan_config_t ));
186187 m_i2s_chan_cfg.id = (i2s_port_t )m_i2s_num; // I2S_NUM_AUTO, I2S_NUM_0, I2S_NUM_1
187188 m_i2s_chan_cfg.role = I2S_ROLE_MASTER; // I2S controller master role, bclk and lrc signal will be set to output
188189 m_i2s_chan_cfg.dma_desc_num = 16 ; // number of DMA buffer
189190 m_i2s_chan_cfg.dma_frame_num = 512 ; // I2S frame number in one DMA buffer.
190191 m_i2s_chan_cfg.auto_clear = true ; // i2s will always send zero automatically if no data to send
192+ m_i2s_chan_cfg.allow_pd = false ;
191193 i2s_new_channel (&m_i2s_chan_cfg, &m_i2s_tx_handle, NULL );
192194
195+ memset (&m_i2s_std_cfg, 0 , sizeof (i2s_std_config_t ));
193196 m_i2s_std_cfg.slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG (I2S_DATA_BIT_WIDTH_16BIT, I2S_SLOT_MODE_STEREO); // Set to enable bit shift in Philips mode
194197 m_i2s_std_cfg.gpio_cfg .bclk = I2S_GPIO_UNUSED; // BCLK, Assignment in setPinout()
195198 m_i2s_std_cfg.gpio_cfg .din = I2S_GPIO_UNUSED; // not used
@@ -2274,7 +2277,7 @@ int Audio::read_M4A_Header(uint8_t* data, size_t len) {
22742277 atom_name.copy_from ((const char *)data + 4 , 4 );
22752278
22762279 if (atom_name.equals (" ftyp" )){
2277- AUDIO_LOG_DEBUG (" atom %s @ %i , size: %i , ends @ %i " , atom_name.c_get (), m_m4aHdr.headerSize , atom_size.to_uint32 (16 ), m_m4aHdr.headerSize + atom_size.to_uint32 (16 ));
2280+ AUDIO_LOG_DEBUG (" atom %s @ %zu , size: %u , ends @ %zu " , atom_name.c_get (), m_m4aHdr.headerSize , ( uint32_t ) atom_size.to_uint32 (16 ), m_m4aHdr.headerSize + ( size_t ) atom_size.to_uint32 (16 ));
22782281 m_m4aHdr.sizeof_ftyp = atom_size.to_uint32 (16 );
22792282 m_controlCounter = M4A_FTYP;
22802283 }
@@ -2631,7 +2634,7 @@ int Audio::read_M4A_Header(uint8_t* data, size_t len) {
26312634 // esds_buffer.hex_dump(m_m4aHdr.sizeof_esds);
26322635
26332636 // search for decoderConfigDescriptor (tag 0x04)
2634- int32_t dec_config_descriptor_offset = esds_buffer.special_index_of (" \x04\x80\x80\x80 " , 4 , m_m4aHdr.sizeof_esds );
2637+ int32_t dec_config_descriptor_offset = esds_buffer.special_index_of (" \x04\x80\x80\x80 " , 4 , ( uint32_t ) m_m4aHdr.sizeof_esds );
26352638 if (dec_config_descriptor_offset > 0 ){ // decoderConfigDescriptor found
26362639 uint8_t dec_config_descriptor_length = ((uint8_t *)esds_buffer.get ())[dec_config_descriptor_offset + 4 ]; // Length after Tag + 3 Extended Length Bytes
26372640 m_m4aHdr.objectTypeIndicator = ((uint8_t *)esds_buffer.get ())[dec_config_descriptor_offset + 5 ]; // 0x40 (AAC)
@@ -3741,7 +3744,7 @@ void Audio::processLocalFile() {
37413744 else {stopSong (); return ;}
37423745 m_lastGranulePosition = getLastGranulePosition ();
37433746 m_controlCounter = 100 ;
3744- log_w (" %lu , lastGranulePosition %llu" , __LINE__, m_lastGranulePosition);
3747+ log_w (" %i , lastGranulePosition %llu" , __LINE__, m_lastGranulePosition);
37453748 return ;
37463749 }
37473750 if (m_controlCounter != 100 ) {
@@ -3913,7 +3916,7 @@ void Audio::processWebFile() {
39133916 else {stopSong (); return ;}
39143917 m_lastGranulePosition = getLastGranulePosition (); // to calculate the duration
39153918 m_controlCounter = 100 ;
3916- log_w (" %lu , lastGranulePosition %llu" , __LINE__, m_lastGranulePosition);
3919+ log_w (" %i , lastGranulePosition %llu" , __LINE__, m_lastGranulePosition);
39173920 return ;
39183921 }
39193922 if (m_controlCounter != 100 ) {
@@ -5231,7 +5234,7 @@ int Audio::sendBytes(uint8_t* data, size_t len) {
52315234 if (res < 0 ){ return decodeError (res, data, bytesDecoded);} // Error, skip the frame...
52325235 if (res > 99 ){ return decodeContinue (res, data, bytesDecoded);} // decoder needs more data...
52335236
5234- if (bytesDecoded == 0 && ! m_codec == CODEC_VORBIS) { // unlikely framesize, exept VORBIS decodes lastSegmentTable
5237+ if (( bytesDecoded == 0 ) && ( m_codec != CODEC_VORBIS) ) { // unlikely framesize, exept VORBIS decodes lastSegmentTable
52355238 info (evt_info, " framesize is 0, start decoding again" );
52365239 m_f_playing = false ; // seek for new syncword
52375240 // we're here because there was a wrong sync word so skip one byte and seek for the next
@@ -6514,7 +6517,6 @@ bool Audio::readID3V1Tag() {
65146517// -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
65156518int32_t Audio::newInBuffStart (int32_t m_resumeFilePos){
65166519 int32_t offset = 0 , buffFillValue = 0 , res = 0 ;
6517- uint32_t timeOut = 0 ;
65186520
65196521 if (m_controlCounter != 100 ){AUDIO_LOG_WARN (" timeOffset not possible" ); m_resumeFilePos = -1 ; offset = -1 ; goto exit;}
65206522 if (m_resumeFilePos >= (int32_t )m_audioDataStart + m_audioDataSize) { m_resumeFilePos = -1 ; offset = -1 ; goto exit;}
@@ -6538,17 +6540,7 @@ int32_t Audio::newInBuffStart(int32_t m_resumeFilePos){
65386540 res = audioFileSeek (m_resumeFilePos);
65396541 InBuff.resetBuffer ();
65406542 offset = 0 ;
6541- timeOut = millis ();
65426543 audioFileRead (InBuff.getReadPtr () + offset, buffFillValue);
6543- // while (remaining > 0) {
6544- // int bytesRead = audioFileRead(InBuff.getReadPtr() + offset, remaining);
6545- // if (bytesRead <= 0) {
6546- // if(millis() > timeOut + 2000){AUDIO_LOG_ERROR("timeout, not enough data from host"); buffFillSize = offset; break;}
6547- // continue; // ggf. Sleep oder Timeout prüfen, um Endlosschleife zu vermeiden
6548- // }
6549- // remaining -= bytesRead;
6550- // offset += bytesRead;
6551- // }
65526544 InBuff.bytesWritten (buffFillValue);
65536545
65546546/* process after */
0 commit comments