2
2
* Audio.cpp
3
3
*
4
4
* Created on: Oct 26,2018
5
- * Updated on: Apr 03 ,2019
5
+ * Updated on: Apr 04 ,2019
6
6
* Author: Wolle
7
7
*
8
8
* This library plays mp3 files from SD card or icy-webstream via I2S
@@ -71,7 +71,7 @@ bool Audio::connecttohost(String host){
71
71
if (audio_info) audio_info (chbuf);
72
72
73
73
// initializationsequence
74
-
74
+ m_f_podcast= false ;
75
75
m_f_ctseen=false ; // Contents type not seen yet
76
76
m_f_mp3=false ; // Set if stream is mp3
77
77
m_f_aac=false ; // Set if stream is aac
@@ -181,6 +181,7 @@ bool Audio::connecttoSD(String sdfile){
181
181
m_f_webstream=false ;
182
182
m_f_stream=false ;
183
183
m_f_mp3=true ;
184
+ m_f_podcast=false ;
184
185
memset (m_outBuff, 0 , sizeof (m_outBuff)); // Clear OutputBuffer
185
186
if (!sdfile.startsWith (" /" )) sdfile=" /" +sdfile;
186
187
while (sdfile[i] != 0 ){ // convert UTF8 to ASCII
@@ -428,7 +429,7 @@ void Audio::readID3Metadata(){
428
429
char frameid[5 ];
429
430
int framesize=0 ;
430
431
bool compressed;
431
- char value[256 ];
432
+ char value[256 + 65 ]; // tag (max65) + value (max 256)
432
433
bool bitorder=false ;
433
434
uint8_t uni_h=0 ;
434
435
uint8_t uni_l=0 ;
@@ -796,8 +797,15 @@ void Audio::loop() {
796
797
}
797
798
}
798
799
if (m_f_firststream_ready==true ){
799
- if (m_av==0 ){ // empty buffer, broken stream or bad bitrate?
800
+ if (m_av==0 ){ // empty buffer, broken stream or bad bitrate?
800
801
i++;
802
+ if (m_f_podcast==true && i>3000 ){ // or end of podcast
803
+ m_f_podcast=false ;
804
+ m_f_webstream=false ;
805
+ if (audio_info) audio_info (" end of stream" );
806
+ if (audio_eof_mp3) audio_eof_mp3 (" Podcast" );
807
+ return ;
808
+ }
801
809
if (i>200000 ){ // wait several seconds
802
810
i=0 ;
803
811
if (audio_info) audio_info (" Stream lost -> try new connection" );
@@ -1284,11 +1292,12 @@ bool Audio::chkhdrline(const char* str){
1284
1292
// ---------------------------------------------------------------------------------------------------------------------
1285
1293
int Audio::sendBytes (uint8_t *data, size_t len) {
1286
1294
if (m_validSamples>0 ) {playChunk (); return 0 ;} // outputbuffer full or not ready, try again?
1287
- static int lastret=0 , count=0 ;
1295
+ static int lastret=0 , count=0 , ehsz= 0 ;
1288
1296
if (!m_f_playing){
1289
1297
1290
1298
if ((data[0 ] == ' I' ) && (data[1 ] == ' D' ) && (data[2 ] == ' 3' )){
1291
1299
// it is not a usual radio stream, it is a podcast
1300
+ m_f_podcast=true ;
1292
1301
log_i (" Podcast found!" );
1293
1302
m_id3Size = data[6 ]; m_id3Size = m_id3Size << 7 ;
1294
1303
m_id3Size |= data[7 ]; m_id3Size = m_id3Size << 7 ;
@@ -1311,8 +1320,23 @@ int Audio::sendBytes(uint8_t *data, size_t len) {
1311
1320
if (audio_info) audio_info (chbuf);
1312
1321
sprintf (chbuf," ID3 framesSize=%i" , m_id3Size);
1313
1322
if (audio_info) audio_info (chbuf);
1323
+ if (m_f_exthdr) {
1324
+ if (audio_info) audio_info (" ID3 extended header" );
1325
+ ehsz = (data[10 ] << 24 ) | (data[11 ] << 16 )
1326
+ | (data[12 ] << 8 ) | (data[13 ]);
1327
+ m_id3Size-=4 ;
1328
+ return 14 ;
1329
+ }
1330
+ else {
1331
+ if (audio_info) audio_info (" ID3 normal frames" );
1332
+ return 10 ;
1333
+ }
1314
1334
}
1315
- // skip ID3
1335
+ if (ehsz>1024 ){ehsz-=1024 ; m_id3Size-=1024 ; return 1024 ;} // Throw exthdr away
1336
+ if (ehsz> 0 ){int tmp=ehsz; m_id3Size-=ehsz; ehsz=0 ; return tmp;}
1337
+ // TODO analyze ID3tags, not skip them
1338
+
1339
+ // skip ID3tags
1316
1340
if (m_id3Size>1000 ){
1317
1341
m_id3Size-=1000 ;
1318
1342
return 1000 ;
0 commit comments