i2s_read_header
This commit is contained in:
@@ -1132,6 +1132,7 @@ size_t Audio::readAudioHeader(uint32_t bytes){
|
||||
if(res >= 0) bytesReaded = res;
|
||||
else{ // error, skip header
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
}
|
||||
if(m_codec == CODEC_MP3){
|
||||
@@ -1139,6 +1140,7 @@ size_t Audio::readAudioHeader(uint32_t bytes){
|
||||
if(res >= 0) bytesReaded = res;
|
||||
else{ // error, skip header
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
}
|
||||
if(m_codec == CODEC_M4A){
|
||||
@@ -1146,12 +1148,14 @@ size_t Audio::readAudioHeader(uint32_t bytes){
|
||||
if(res >= 0) bytesReaded = res;
|
||||
else{ // error, skip header
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
}
|
||||
if(m_codec == CODEC_AAC){
|
||||
// stream only, no header
|
||||
m_audioDataSize = getFileSize();
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
if(m_codec == CODEC_FLAC){
|
||||
int res = read_FLAC_Header(InBuff.getReadPtr(), bytes);
|
||||
@@ -1159,6 +1163,7 @@ size_t Audio::readAudioHeader(uint32_t bytes){
|
||||
else{ // error, skip header
|
||||
stopSong();
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
}
|
||||
if(!isRunning()){
|
||||
@@ -1304,6 +1309,7 @@ int Audio::read_WAV_Header(uint8_t* data, size_t len) {
|
||||
return 4;
|
||||
}
|
||||
m_controlCounter = 100; // header succesfully read
|
||||
eofHeader = true;
|
||||
m_audioDataStart = headerSize;
|
||||
return 0;
|
||||
}
|
||||
@@ -1369,6 +1375,7 @@ int Audio::read_FLAC_Header(uint8_t *data, size_t len) {
|
||||
return 0;
|
||||
}
|
||||
m_controlCounter = FLAC_OKAY;
|
||||
eofHeader = true;
|
||||
m_audioDataStart = headerSize;
|
||||
m_audioDataSize = m_contentlength - m_audioDataStart;
|
||||
AUDIO_INFO("Audio-Length: %u", m_audioDataSize);
|
||||
@@ -1734,6 +1741,7 @@ int Audio::read_ID3_Header(uint8_t *data, size_t len) {
|
||||
}
|
||||
else {
|
||||
m_controlCounter = 100; // ok
|
||||
eofHeader = true;
|
||||
m_audioDataSize = m_contentlength - m_audioDataStart;
|
||||
AUDIO_INFO("Audio-Length: %u", 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);
|
||||
}
|
||||
m_controlCounter = M4A_OKAY; // that's all
|
||||
eofHeader = true;
|
||||
return 0;
|
||||
}
|
||||
// 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());
|
||||
|
||||
m_controlCounter = OGG_OKAY; // 100
|
||||
eofHeader = true;
|
||||
retvalue = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ public:
|
||||
void getVUlevel() {};
|
||||
uint8_t vuLeft, vuRight;
|
||||
SemaphoreHandle_t mutex_pl=NULL;
|
||||
|
||||
bool eofHeader;
|
||||
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 inBufferFree(); // returns the number of free bytes in the inputbuffer
|
||||
|
||||
@@ -661,12 +661,14 @@ void Audio::processLocalFile() {
|
||||
if(m_codec == CODEC_WAV){
|
||||
// int res = read_WAV_Header(InBuff.getReadPtr(), bytesCanBeRead);
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
if(m_codec == CODEC_MP3){
|
||||
int res = read_MP3_Header(InBuff.getReadPtr(), bytesCanBeRead);
|
||||
if(res >= 0) bytesDecoded = res;
|
||||
else{ // error, skip header
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
}
|
||||
if(m_codec == CODEC_M4A){
|
||||
@@ -674,12 +676,14 @@ void Audio::processLocalFile() {
|
||||
// if(res >= 0) bytesDecoded = res;
|
||||
// else{ // error, skip header
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
// }
|
||||
}
|
||||
if(m_codec == CODEC_AAC){
|
||||
// stream only, no header
|
||||
m_audioDataSize = getFileSize();
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
|
||||
if(m_codec == CODEC_FLAC){
|
||||
@@ -688,11 +692,13 @@ void Audio::processLocalFile() {
|
||||
// else{ // error, skip header
|
||||
// stopSong();
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
// }
|
||||
}
|
||||
|
||||
if(m_codec == CODEC_OGG){
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -872,17 +878,20 @@ void Audio::processWebStream(){
|
||||
if(InBuff.bufferFilled() < maxFrameSize) return;
|
||||
if(m_codec == CODEC_WAV){
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
if(m_codec == CODEC_MP3){
|
||||
int res = read_MP3_Header(InBuff.getReadPtr(), InBuff.bufferFilled());
|
||||
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){
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
if(m_codec == CODEC_FLAC){
|
||||
m_controlCounter = 100;
|
||||
eofHeader = true;
|
||||
}
|
||||
InBuff.bytesWasRead(bytesDecoded);
|
||||
return;
|
||||
@@ -2333,6 +2342,7 @@ int Audio::read_MP3_Header(uint8_t *data, size_t len) {
|
||||
}
|
||||
else {
|
||||
m_controlCounter = 100; // ok
|
||||
eofHeader = true;
|
||||
m_audioDataSize = m_contentlength - m_audioDataStart;
|
||||
sprintf(chbuf, "Audio-Length: %u", m_audioDataSize);
|
||||
if(audio_info) audio_info(chbuf);
|
||||
|
||||
@@ -319,6 +319,7 @@ public:
|
||||
void getVUlevel();
|
||||
uint8_t vuLeft, vuRight;
|
||||
void cardLock(bool lock);
|
||||
bool eofHeader;
|
||||
// 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 endsWith (const char* base, const char* str) {
|
||||
|
||||
@@ -53,6 +53,7 @@ void Player::init() {
|
||||
volTimer=false;
|
||||
zeroRequest();
|
||||
playmutex = xSemaphoreCreateMutex();
|
||||
randomSeed(analogRead(0));
|
||||
Serial.println("done");
|
||||
}
|
||||
|
||||
@@ -85,15 +86,13 @@ void Player::stop(const char *nttl){
|
||||
void Player::initHeaders(const char *file) {
|
||||
if(strlen(file)==0) return;
|
||||
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);
|
||||
setDefaults();
|
||||
}
|
||||
|
||||
void Player::loopreader() {
|
||||
Audio::loop();
|
||||
}
|
||||
|
||||
void Player::loop() {
|
||||
if (mode == PLAYING) {
|
||||
xSemaphoreTake(playmutex, portMAX_DELAY);
|
||||
@@ -161,7 +160,7 @@ void Player::play(uint16_t stationId, uint32_t filePos) {
|
||||
display.putRequest(PSTART);
|
||||
if (player_on_start_play) player_on_start_play();
|
||||
}else{
|
||||
Serial.println("some unknown bug...");
|
||||
telnet.printf("##ERROR#:\tError connecting to %s\n", config.station.url);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,6 @@ class Player: public Audio {
|
||||
void init();
|
||||
void loop();
|
||||
void initHeaders(const char *file);
|
||||
void loopreader();
|
||||
void play(uint16_t stationId, uint32_t filePos=0);
|
||||
void stop(const char *nttl = NULL);
|
||||
void prev();
|
||||
|
||||
Reference in New Issue
Block a user