Skip to content

Commit 1a48874

Browse files
authored
Merge pull request #1123 from schreibfaul1/http-range
http range request activated
2 parents 5404e0a + 7388f5a commit 1a48874

File tree

15 files changed

+1540
-1180
lines changed

15 files changed

+1540
-1180
lines changed

library.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ESP32-audioI2S",
3-
"version": "3.4.0",
3+
"version": "3.4.1",
44
"description": "With this library You can easily build a WebRadio with a ESP32 board and a I2S-module",
55
"keywords": "audio, i2s, esp32, esp32-s3, esp32-p4",
66
"repository": {

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=ESP32-audioI2S-master
2-
version=3.4.0
2+
version=3.4.1
33
author=schreibfaul1
44
maintainer=schreibfaul1
55
sentence=With this library You can easily build a audio app with a ESP32, ESP32-S3, ESP32-P4 board with PSRAM and a external DAC or I2S-BT-module.

src/Audio.cpp

Lines changed: 1077 additions & 884 deletions
Large diffs are not rendered by default.

src/Audio.h

Lines changed: 165 additions & 139 deletions
Large diffs are not rendered by default.

src/aac_decoder/aac_decoder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ void AAC_LOG_IMPL(uint8_t level, const char* path, int line, const char* fmt, Ar
7272
ps_ptr<char> final;
7373
int total_len = std::snprintf(nullptr, 0, "%s:%d:" ANSI_ESC_RED " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
7474
if (total_len <= 0) return;
75-
final.alloc(total_len + 1, "final");
75+
final.calloc(total_len + 1, "final");
7676
final.clear();
7777
char* dest = final.get();
7878
if (!dest) return; // Or error treatment
@@ -82,7 +82,7 @@ void AAC_LOG_IMPL(uint8_t level, const char* path, int line, const char* fmt, Ar
8282
else if(level == 3 && CORE_DEBUG_LEVEL >= 3) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_GREEN " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
8383
else if(level == 4 && CORE_DEBUG_LEVEL >= 4) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_CYAN " %s" ANSI_ESC_RESET, file.c_get(), line, dst); // debug
8484
else if( CORE_DEBUG_LEVEL >= 5) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_WHITE " %s" ANSI_ESC_RESET, file.c_get(), line, dst); // verbose
85-
if(final.strlen() > 0) audio_info(final.get());
85+
if(final.strlen()) audio_info(final.get());
8686
}
8787
else{
8888
std::snprintf(dest, total_len + 1, "%s:%d: %s", file.c_get(), line, dst);

src/flac_decoder/flac_decoder.cpp

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ uint32_t readUint(uint8_t nBits, int32_t *bytesLeft){
144144
uint8_t temp = *(s_flacInptr + s_rIndex);
145145
s_rIndex++;
146146
(*bytesLeft)--;
147-
if(*bytesLeft < 0) { log_e("error in bitreader"); s_f_bitReaderError = true; break;}
147+
if(*bytesLeft < 0) { FLAC_LOG_ERROR("error in bitreader"); s_f_bitReaderError = true; break;}
148148
s_flac_bitBuffer = (s_flac_bitBuffer << 8) | temp;
149149
s_flacBitBufferLen += 8;
150150
}
@@ -219,9 +219,9 @@ boolean FLACFindMagicWord(unsigned char* buf, int32_t nBytes){
219219
uint32_t lomd = (buf[idx + 2] << 16) + (buf[idx + 3] << 8) + buf[idx + 4]; // Length of metadata to follow
220220

221221
(void)lmdbf; (void)bt; (void)lomd;
222-
// log_i("Last-metadata-block flag: %d", lmdbf);
223-
// log_i("block type: %d", bt);
224-
// log_i("Length (in bytes) of metadata to follow: %d", lomd);
222+
// FLAC_LOG_INFO("Last-metadata-block flag: %d", lmdbf);
223+
// FLAC_LOG_INFO("block type: %d", bt);
224+
// FLAC_LOG_INFO("Length (in bytes) of metadata to follow: %d", lomd);
225225
return true;
226226
}
227227
return false;
@@ -278,15 +278,15 @@ int32_t FLACparseOGG(uint8_t *inbuf, int32_t *bytesLeft){ // reference https://
278278
}
279279
s_flacSegmTableVec.insert(s_flacSegmTableVec.begin(), n);
280280
}
281-
// for(int32_t i = 0; i< s_flacSegmTableVec.size(); i++){log_w("%i", s_flacSegmTableVec[i]);}
281+
// for(int32_t i = 0; i< s_flacSegmTableVec.size(); i++){FLAC_LOG_INFO("%i", s_flacSegmTableVec[i]);}
282282

283283
bool continuedPage = headerType & 0x01; // set: page contains data of a packet continued from the previous page
284284
bool firstPage = headerType & 0x02; // set: this is the first page of a logical bitstream (bos)
285285
bool lastPage = headerType & 0x04; // set: this is the last page of a logical bitstream (eos)
286286

287287
(void)continuedPage; (void)lastPage;
288288

289-
// log_w("firstPage %i, continuedPage %i, lastPage %i", firstPage, continuedPage, lastPage);
289+
// FLAC_LOG_INFO("firstPage %i, continuedPage %i, lastPage %i", firstPage, continuedPage, lastPage);
290290

291291
if(firstPage) s_flacPageNr = 0;
292292

@@ -314,7 +314,7 @@ int32_t parseFlacFirstPacket(uint8_t *inbuf, int16_t nBytes){ // 4.2.2. Identifi
314314

315315
int32_t ret = 0;
316316
int32_t idx = FLAC_specialIndexOf(inbuf, "fLaC", nBytes);
317-
//log_i("idx %i, nBytes %i", idx, nBytes);
317+
//FLAC_LOG_INFO("idx %i, nBytes %i", idx, nBytes);
318318
if(idx >= 0){ // FLAC signature found
319319
ret = idx + 4;
320320
}
@@ -350,12 +350,12 @@ int32_t parseMetaDataBlockHeader(uint8_t *inbuf, int16_t nBytes){
350350

351351
while(true){
352352
mdBlockHeader = *(inbuf + pos);
353-
s_f_lastMetaDataBlock = mdBlockHeader & 0b10000000; //log_w("lastMdBlockFlag %i", s_f_lastMetaDataBlock);
354-
blockType = mdBlockHeader & 0b01111111; //log_w("blockType %i", blockType);
353+
s_f_lastMetaDataBlock = mdBlockHeader & 0b10000000; // FLAC_LOG_INFO("lastMdBlockFlag %i", s_f_lastMetaDataBlock);
354+
blockType = mdBlockHeader & 0b01111111; // FLAC_LOG_INFO("blockType %i", blockType);
355355

356356
blockLength = *(inbuf + pos + 1) << 16;
357357
blockLength += *(inbuf + pos + 2) << 8;
358-
blockLength += *(inbuf + pos + 3); //log_w("blockLength %i", blockLength);
358+
blockLength += *(inbuf + pos + 3); // FLAC_LOG_INFO("blockLength %i", blockLength);
359359

360360
nBytes -= 4;
361361
pos += 4;
@@ -366,7 +366,7 @@ int32_t parseMetaDataBlockHeader(uint8_t *inbuf, int16_t nBytes){
366366
break;
367367
case 1:
368368
bt = padding;
369-
// log_e("padding");
369+
// FLAC_LOG_ERROR("padding");
370370
return FLAC_NONE;
371371
break;
372372
case 2:
@@ -402,8 +402,8 @@ int32_t parseMetaDataBlockHeader(uint8_t *inbuf, int16_t nBytes){
402402
minBlocksize += *(inbuf + pos + 1);
403403
maxBlocksize += *(inbuf + pos + 2) << 8;
404404
maxBlocksize += *(inbuf + pos + 3);
405-
//log_i("minBlocksize %i", minBlocksize);
406-
//log_i("maxBlocksize %i", maxBlocksize);
405+
//FLAC_LOG_INFO("minBlocksize %i", minBlocksize);
406+
//FLAC_LOG_INFO("maxBlocksize %i", maxBlocksize);
407407
FLACMetadataBlock->minblocksize = minBlocksize;
408408
FLACMetadataBlock->maxblocksize = maxBlocksize;
409409

@@ -415,35 +415,35 @@ int32_t parseMetaDataBlockHeader(uint8_t *inbuf, int16_t nBytes){
415415
maxFrameSize = *(inbuf + pos + 7) << 16;
416416
maxFrameSize += *(inbuf + pos + 8) << 8;
417417
maxFrameSize += *(inbuf + pos + 9);
418-
//log_i("minFrameSize %i", minFrameSize);
419-
//log_i("maxFrameSize %i", maxFrameSize);
418+
//FLAC_LOG_INFO("minFrameSize %i", minFrameSize);
419+
//FLAC_LOG_INFO("maxFrameSize %i", maxFrameSize);
420420
FLACMetadataBlock->minframesize = minFrameSize;
421421
FLACMetadataBlock->maxframesize = maxFrameSize;
422422

423423
sampleRate = *(inbuf + pos + 10) << 12;
424424
sampleRate += *(inbuf + pos + 11) << 4;
425425
sampleRate += (*(inbuf + pos + 12) & 0xF0) >> 4;
426-
//log_i("sampleRate %i", sampleRate);
426+
//FLAC_LOG_INFO("sampleRate %i", sampleRate);
427427
FLACMetadataBlock->sampleRate = sampleRate;
428428

429429
nrOfChannels = ((*(inbuf + pos + 12) & 0x0E) >> 1) + 1;
430-
//log_i("nrOfChannels %i", nrOfChannels);
430+
//FLAC_LOG_INFO("nrOfChannels %i", nrOfChannels);
431431
FLACMetadataBlock->numChannels = nrOfChannels;
432432

433433
bitsPerSample = (*(inbuf + pos + 12) & 0x01) << 5;
434434
bitsPerSample += ((*(inbuf + pos + 13) & 0xF0) >> 4) + 1;
435435
FLACMetadataBlock->bitsPerSample = bitsPerSample;
436-
//log_i("bitsPerSample %i", bitsPerSample);
436+
//FLAC_LOG_INFO("bitsPerSample %i", bitsPerSample);
437437

438438
totalSamplesInStream = (uint64_t)(*(inbuf + pos + 17) & 0x0F) << 32;
439439
totalSamplesInStream += (*(inbuf + pos + 14)) << 24;
440440
totalSamplesInStream += (*(inbuf + pos + 14)) << 16;
441441
totalSamplesInStream += (*(inbuf + pos + 15)) << 8;
442442
totalSamplesInStream += (*(inbuf + pos + 16));
443-
//log_i("totalSamplesInStream %lli", totalSamplesInStream);
443+
//FLAC_LOG_INFO("totalSamplesInStream %lli", totalSamplesInStream);
444444
FLACMetadataBlock->totalSamples = totalSamplesInStream;
445445

446-
//log_i("nBytes %i, blockLength %i", nBytes, blockLength);
446+
//FLAC_LOG_INFO("nBytes %i, blockLength %i", nBytes, blockLength);
447447
pos += blockLength;
448448
nBytes -= blockLength;
449449
if(ret == FLAC_PARSE_OGG_DONE) return ret;
@@ -510,8 +510,8 @@ int32_t parseMetaDataBlockHeader(uint8_t *inbuf, int16_t nBytes){
510510
s_flacBlockPicLenUntilFrameEnd = nBytes - (pos + 23);
511511
if(s_flacBlockPicLen < s_flacBlockPicLenUntilFrameEnd) s_flacBlockPicLenUntilFrameEnd = s_flacBlockPicLen;
512512
s_flacRemainBlockPicLen = s_flacBlockPicLen - s_flacBlockPicLenUntilFrameEnd;
513-
//log_i("s_flacBlockPicPos %i, s_flacBlockPicLen %i", s_flacBlockPicPos, s_flacBlockPicLen);
514-
//log_i("s_flacBlockPicLenUntilFrameEnd %i, s_flacRemainBlockPicLen %i", s_flacBlockPicLenUntilFrameEnd, s_flacRemainBlockPicLen);
513+
//FLAC_LOG_INFO("s_flacBlockPicPos %i, s_flacBlockPicLen %i", s_flacBlockPicPos, s_flacBlockPicLen);
514+
//FLAC_LOG_INFO("s_flacBlockPicLenUntilFrameEnd %i, s_flacRemainBlockPicLen %i", s_flacBlockPicLenUntilFrameEnd, s_flacRemainBlockPicLen);
515515
if(s_flacRemainBlockPicLen <= 0) s_f_lastMetaDataBlock = true; // exeption:: goto audiopage after commemt if lastMetaDataFlag is not set
516516
if(s_flacBlockPicLen){
517517
s_flacBlockPicItem.clear();
@@ -605,18 +605,18 @@ int8_t FLACDecode(uint8_t *inbuf, int32_t *bytesLeft, int16_t *outbuf){ // MAIN
605605
else return ret; // error
606606
}
607607
//-------------------------------------------------------
608-
if(!s_flacSegmTableVec.size()) log_e("size is 0");
608+
if(!s_flacSegmTableVec.size()) FLAC_LOG_ERROR("size is 0");
609609
segmLen = s_flacSegmTableVec.back();
610610
s_flacSegmTableVec.pop_back();
611611
if(!s_flacSegmTableVec.size()) s_f_flacParseOgg = true;
612612
//-------------------------------------------------------
613613

614614
if(s_flacRemainBlockPicLen <= 0 && !s_f_flacNewMetadataBlockPicture) {
615615
if(s_flacBlockPicItem.size() > 0) { // get blockpic data
616-
// log_i("---------------------------------------------------------------------------");
617-
// log_i("metadata blockpic found at pos %i, size %i bytes", s_flacBlockPicPos, s_flacBlockPicLen);
618-
// for(int32_t i = 0; i < s_flacBlockPicItem.size(); i += 2) { log_i("segment %02i, pos %07i, len %05i", i / 2, s_flacBlockPicItem[i], s_flacBlockPicItem[i + 1]); }
619-
// log_i("---------------------------------------------------------------------------");
616+
// FLAC_LOG_INFO("---------------------------------------------------------------------------");
617+
// FLAC_LOG_INFO("metadata blockpic found at pos %i, size %i bytes", s_flacBlockPicPos, s_flacBlockPicLen);
618+
// for(int32_t i = 0; i < s_flacBlockPicItem.size(); i += 2) { FLAC_LOG_INFO("segment %02i, pos %07i, len %05i", i / 2, s_flacBlockPicItem[i], s_flacBlockPicItem[i + 1]); }
619+
// FLAC_LOG_INFO("---------------------------------------------------------------------------");
620620
s_f_flacNewMetadataBlockPicture = true;
621621
}
622622
}
@@ -642,7 +642,7 @@ int8_t FLACDecode(uint8_t *inbuf, int32_t *bytesLeft, int16_t *outbuf){ // MAIN
642642
case 1:
643643
if(s_flacRemainBlockPicLen > 0){
644644
s_flacRemainBlockPicLen -= segmLen;
645-
//log_i("s_flacCurrentFilePos %i, len %i, s_flacRemainBlockPicLen %i", s_flacCurrentFilePos, segmLen, s_flacRemainBlockPicLen);
645+
//FLAC_LOG_INFO("s_flacCurrentFilePos %i, len %i, s_flacRemainBlockPicLen %i", s_flacCurrentFilePos, segmLen, s_flacRemainBlockPicLen);
646646
s_flacBlockPicItem.push_back(s_flacCurrentFilePos);
647647
s_flacBlockPicItem.push_back(segmLen);
648648
if(s_flacRemainBlockPicLen <= 0){s_flacPageNr = 2;}
@@ -716,18 +716,18 @@ int8_t FLACDecodeNative(uint8_t *inbuf, int32_t *bytesLeft, int16_t *outbuf){
716716
sbl = 0;
717717
s_flacBitrate = FLACMetadataBlock->sampleRate * FLACMetadataBlock->bitsPerSample * FLACMetadataBlock->numChannels;
718718
s_flacBitrate /= s_flacCompressionRatio;
719-
// log_e("s_flacBitrate %i, s_flacCompressionRatio %f, FLACMetadataBlock->sampleRate %i ", s_flacBitrate, s_flacCompressionRatio, FLACMetadataBlock->sampleRate);
719+
// FLAC_LOG_INFO("s_flacBitrate %i, s_flacCompressionRatio %f, FLACMetadataBlock->sampleRate %i ", s_flacBitrate, s_flacCompressionRatio, FLACMetadataBlock->sampleRate);
720720
}
721721
if(s_offset != s_numOfOutSamples) return GIVE_NEXT_LOOP;
722-
if(s_offset > s_numOfOutSamples) { log_e("offset has a wrong value"); }
722+
if(s_offset > s_numOfOutSamples) { FLAC_LOG_ERROR("offset has a wrong value"); }
723723
s_offset = 0;
724724
}
725725

726726
alignToByte();
727727
readUint(16, bytesLeft);
728728

729729
// s_flacCompressionRatio = (float)m_bytesDecoded / (float)s_numOfOutSamples * FLACMetadataBlock->numChannels * (16/8);
730-
// log_i("s_flacCompressionRatio % f", s_flacCompressionRatio);
730+
// FLAC_LOG_INFO("s_flacCompressionRatio % f", s_flacCompressionRatio);
731731
s_flacStatus = DECODE_FRAME;
732732
return FLAC_NONE;
733733
}

src/flac_decoder/flac_decoder.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -210,17 +210,17 @@ void FLAC_LOG_IMPL(uint8_t level, const char* path, int line, const char* fmt, A
210210
ps_ptr<char> final;
211211
int total_len = std::snprintf(nullptr, 0, "%s:%d:" ANSI_ESC_RED " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
212212
if (total_len <= 0) return;
213-
final.alloc(total_len + 1, "final");
213+
final.calloc(total_len + 1, "final");
214214
final.clear();
215215
char* dest = final.get();
216216
if (!dest) return; // Or error treatment
217217
if(audio_info){
218-
if (level == 1) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_RED " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
219-
else if(level == 2) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_YELLOW " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
220-
else if(level == 3) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_GREEN " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
221-
else if(level == 4) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_CYAN " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
222-
else snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_WHITE" %s" ANSI_ESC_RESET, file.c_get(), line, dst);
223-
audio_info(final.get());
218+
if (level == 1 && CORE_DEBUG_LEVEL >= 1) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_RED " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
219+
else if(level == 2 && CORE_DEBUG_LEVEL >= 2) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_YELLOW " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
220+
else if(level == 3 && CORE_DEBUG_LEVEL >= 3) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_GREEN " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
221+
else if(level == 4 && CORE_DEBUG_LEVEL >= 4) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_CYAN " %s" ANSI_ESC_RESET, file.c_get(), line, dst);
222+
else if( CORE_DEBUG_LEVEL >= 5) snprintf(dest, total_len + 1, "%s:%d:" ANSI_ESC_WHITE" %s" ANSI_ESC_RESET, file.c_get(), line, dst);
223+
if(final.strlen()) audio_info(final.get());
224224
}
225225
else{
226226
std::snprintf(dest, total_len + 1, "%s:%d: %s", file.c_get(), line, dst);

0 commit comments

Comments
 (0)