i2s_read_header

This commit is contained in:
e2002
2022-12-27 12:00:32 +03:00
parent 314d86e1ee
commit fa2d1a33c9
6 changed files with 28 additions and 9 deletions

View File

@@ -1132,6 +1132,7 @@ size_t Audio::readAudioHeader(uint32_t bytes){
if(res >= 0) bytesReaded = res; if(res >= 0) bytesReaded = res;
else{ // error, skip header else{ // error, skip header
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
} }
if(m_codec == CODEC_MP3){ if(m_codec == CODEC_MP3){
@@ -1139,6 +1140,7 @@ size_t Audio::readAudioHeader(uint32_t bytes){
if(res >= 0) bytesReaded = res; if(res >= 0) bytesReaded = res;
else{ // error, skip header else{ // error, skip header
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
} }
if(m_codec == CODEC_M4A){ if(m_codec == CODEC_M4A){
@@ -1146,12 +1148,14 @@ size_t Audio::readAudioHeader(uint32_t bytes){
if(res >= 0) bytesReaded = res; if(res >= 0) bytesReaded = res;
else{ // error, skip header else{ // error, skip header
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
} }
if(m_codec == CODEC_AAC){ if(m_codec == CODEC_AAC){
// stream only, no header // stream only, no header
m_audioDataSize = getFileSize(); m_audioDataSize = getFileSize();
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
if(m_codec == CODEC_FLAC){ if(m_codec == CODEC_FLAC){
int res = read_FLAC_Header(InBuff.getReadPtr(), bytes); int res = read_FLAC_Header(InBuff.getReadPtr(), bytes);
@@ -1159,6 +1163,7 @@ size_t Audio::readAudioHeader(uint32_t bytes){
else{ // error, skip header else{ // error, skip header
stopSong(); stopSong();
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
} }
if(!isRunning()){ if(!isRunning()){
@@ -1304,6 +1309,7 @@ int Audio::read_WAV_Header(uint8_t* data, size_t len) {
return 4; return 4;
} }
m_controlCounter = 100; // header succesfully read m_controlCounter = 100; // header succesfully read
eofHeader = true;
m_audioDataStart = headerSize; m_audioDataStart = headerSize;
return 0; return 0;
} }
@@ -1369,6 +1375,7 @@ int Audio::read_FLAC_Header(uint8_t *data, size_t len) {
return 0; return 0;
} }
m_controlCounter = FLAC_OKAY; m_controlCounter = FLAC_OKAY;
eofHeader = true;
m_audioDataStart = headerSize; m_audioDataStart = headerSize;
m_audioDataSize = m_contentlength - m_audioDataStart; m_audioDataSize = m_contentlength - m_audioDataStart;
AUDIO_INFO("Audio-Length: %u", m_audioDataSize); AUDIO_INFO("Audio-Length: %u", m_audioDataSize);
@@ -1734,6 +1741,7 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
} }
else { else {
m_controlCounter = 100; // ok m_controlCounter = 100; // ok
eofHeader = true;
m_audioDataSize = m_contentlength - m_audioDataStart; m_audioDataSize = m_contentlength - m_audioDataStart;
AUDIO_INFO("Audio-Length: %u", m_audioDataSize); AUDIO_INFO("Audio-Length: %u", m_audioDataSize);
if(audio_progress) audio_progress(m_audioDataStart, m_audioDataSize); if(audio_progress) audio_progress(m_audioDataStart, m_audioDataSize);
@@ -1998,6 +2006,7 @@ int Audio::read_M4A_Header(uint8_t *data, size_t len) {
if(audio_progress) audio_progress(m_audioDataStart, m_audioDataSize); if(audio_progress) audio_progress(m_audioDataStart, m_audioDataSize);
} }
m_controlCounter = M4A_OKAY; // that's all m_controlCounter = M4A_OKAY; // that's all
eofHeader = true;
return 0; return 0;
} }
// this section should never be reached // this section should never be reached
@@ -2203,6 +2212,7 @@ int Audio::read_OGG_Header(uint8_t *data, size_t len){
AUDIO_INFO("FLACDecoder has been initialized, free Heap: %u bytes", ESP.getFreeHeap()); AUDIO_INFO("FLACDecoder has been initialized, free Heap: %u bytes", ESP.getFreeHeap());
m_controlCounter = OGG_OKAY; // 100 m_controlCounter = OGG_OKAY; // 100
eofHeader = true;
retvalue = 0; retvalue = 0;
return 0; return 0;
} }

View File

@@ -210,7 +210,7 @@ public:
void getVUlevel() {}; void getVUlevel() {};
uint8_t vuLeft, vuRight; uint8_t vuLeft, vuRight;
SemaphoreHandle_t mutex_pl=NULL; SemaphoreHandle_t mutex_pl=NULL;
bool eofHeader;
esp_err_t i2s_mclk_pin_select(const uint8_t pin); esp_err_t i2s_mclk_pin_select(const uint8_t pin);
uint32_t inBufferFilled(); // returns the number of stored bytes in the inputbuffer uint32_t inBufferFilled(); // returns the number of stored bytes in the inputbuffer
uint32_t inBufferFree(); // returns the number of free bytes in the inputbuffer uint32_t inBufferFree(); // returns the number of free bytes in the inputbuffer

View File

@@ -661,12 +661,14 @@ void Audio::processLocalFile() {
if(m_codec == CODEC_WAV){ if(m_codec == CODEC_WAV){
// int res = read_WAV_Header(InBuff.getReadPtr(), bytesCanBeRead); // int res = read_WAV_Header(InBuff.getReadPtr(), bytesCanBeRead);
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
if(m_codec == CODEC_MP3){ if(m_codec == CODEC_MP3){
int res = read_MP3_Header(InBuff.getReadPtr(), bytesCanBeRead); int res = read_MP3_Header(InBuff.getReadPtr(), bytesCanBeRead);
if(res >= 0) bytesDecoded = res; if(res >= 0) bytesDecoded = res;
else{ // error, skip header else{ // error, skip header
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
} }
if(m_codec == CODEC_M4A){ if(m_codec == CODEC_M4A){
@@ -674,12 +676,14 @@ void Audio::processLocalFile() {
// if(res >= 0) bytesDecoded = res; // if(res >= 0) bytesDecoded = res;
// else{ // error, skip header // else{ // error, skip header
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
// } // }
} }
if(m_codec == CODEC_AAC){ if(m_codec == CODEC_AAC){
// stream only, no header // stream only, no header
m_audioDataSize = getFileSize(); m_audioDataSize = getFileSize();
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
if(m_codec == CODEC_FLAC){ if(m_codec == CODEC_FLAC){
@@ -688,11 +692,13 @@ void Audio::processLocalFile() {
// else{ // error, skip header // else{ // error, skip header
// stopSong(); // stopSong();
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
// } // }
} }
if(m_codec == CODEC_OGG){ if(m_codec == CODEC_OGG){
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
} }
else { else {
@@ -872,17 +878,20 @@ void Audio::processWebStream(){
if(InBuff.bufferFilled() < maxFrameSize) return; if(InBuff.bufferFilled() < maxFrameSize) return;
if(m_codec == CODEC_WAV){ if(m_codec == CODEC_WAV){
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
if(m_codec == CODEC_MP3){ if(m_codec == CODEC_MP3){
int res = read_MP3_Header(InBuff.getReadPtr(), InBuff.bufferFilled()); int res = read_MP3_Header(InBuff.getReadPtr(), InBuff.bufferFilled());
if(res >= 0) bytesDecoded = res; if(res >= 0) bytesDecoded = res;
else{m_controlCounter = 100;} // error, skip header else{m_controlCounter = 100;eofHeader = true;} // error, skip header
} }
if(m_codec == CODEC_M4A){ if(m_codec == CODEC_M4A){
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
if(m_codec == CODEC_FLAC){ if(m_codec == CODEC_FLAC){
m_controlCounter = 100; m_controlCounter = 100;
eofHeader = true;
} }
InBuff.bytesWasRead(bytesDecoded); InBuff.bytesWasRead(bytesDecoded);
return; return;
@@ -2333,6 +2342,7 @@ int Audio::read_MP3_Header(uint8_t *data, size_t len) {
} }
else { else {
m_controlCounter = 100; // ok m_controlCounter = 100; // ok
eofHeader = true;
m_audioDataSize = m_contentlength - m_audioDataStart; m_audioDataSize = m_contentlength - m_audioDataStart;
sprintf(chbuf, "Audio-Length: %u", m_audioDataSize); sprintf(chbuf, "Audio-Length: %u", m_audioDataSize);
if(audio_info) audio_info(chbuf); if(audio_info) audio_info(chbuf);

View File

@@ -319,6 +319,7 @@ public:
void getVUlevel(); void getVUlevel();
uint8_t vuLeft, vuRight; uint8_t vuLeft, vuRight;
void cardLock(bool lock); void cardLock(bool lock);
bool eofHeader;
// implement several function with respect to the index of string // implement several function with respect to the index of string
bool startsWith (const char* base, const char* str) { return (strstr(base, str) - base) == 0;} bool startsWith (const char* base, const char* str) { return (strstr(base, str) - base) == 0;}
bool endsWith (const char* base, const char* str) { bool endsWith (const char* base, const char* str) {

View File

@@ -53,6 +53,7 @@ void Player::init() {
volTimer=false; volTimer=false;
zeroRequest(); zeroRequest();
playmutex = xSemaphoreCreateMutex(); playmutex = xSemaphoreCreateMutex();
randomSeed(analogRead(0));
Serial.println("done"); Serial.println("done");
} }
@@ -85,15 +86,13 @@ void Player::stop(const char *nttl){
void Player::initHeaders(const char *file) { void Player::initHeaders(const char *file) {
if(strlen(file)==0) return; if(strlen(file)==0) return;
connecttoFS(SD,file); connecttoFS(SD,file);
for(int c=0;c<20;c++) player.loopreader(); eofHeader = false;
//for(int c=0;c<20;c++) player.loopreader();
while(!eofHeader) Audio::loop();
//netserver.requestOnChange(SDPOS, 0); //netserver.requestOnChange(SDPOS, 0);
setDefaults(); setDefaults();
} }
void Player::loopreader() {
Audio::loop();
}
void Player::loop() { void Player::loop() {
if (mode == PLAYING) { if (mode == PLAYING) {
xSemaphoreTake(playmutex, portMAX_DELAY); xSemaphoreTake(playmutex, portMAX_DELAY);
@@ -161,7 +160,7 @@ void Player::play(uint16_t stationId, uint32_t filePos) {
display.putRequest(PSTART); display.putRequest(PSTART);
if (player_on_start_play) player_on_start_play(); if (player_on_start_play) player_on_start_play();
}else{ }else{
Serial.println("some unknown bug..."); telnet.printf("##ERROR#:\tError connecting to %s\n", config.station.url);
}; };
} }

View File

@@ -33,7 +33,6 @@ class Player: public Audio {
void init(); void init();
void loop(); void loop();
void initHeaders(const char *file); void initHeaders(const char *file);
void loopreader();
void play(uint16_t stationId, uint32_t filePos=0); void play(uint16_t stationId, uint32_t filePos=0);
void stop(const char *nttl = NULL); void stop(const char *nttl = NULL);
void prev(); void prev();