Commit e2e4df30 authored by schreibfaul1's avatar schreibfaul1

prevent maindata underflow at start

and remove some unnecessary code
parent 59784c56
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* *
* Created on: Oct 26.2018 * Created on: Oct 26.2018
* *
* Version 3.0.9h * Version 3.0.9i
* Updated on: Apr 22.2024 * Updated on: Apr 22.2024
* Author: Wolle (schreibfaul1) * Author: Wolle (schreibfaul1)
* *
...@@ -4426,11 +4426,7 @@ int Audio::sendBytes(uint8_t* data, size_t len) { ...@@ -4426,11 +4426,7 @@ int Audio::sendBytes(uint8_t* data, size_t len) {
// < 0: there has been an error // < 0: there has been an error
if(m_decodeError < 0) { // Error, skip the frame... if(m_decodeError < 0) { // Error, skip the frame...
// i2s_zero_dma_buffer((i2s_port_t)m_i2s_num);
if(m_codec == CODEC_MP3 && (m_decodeError == -2)) {
; // at the beginning this doesn't have to be a mistake, suppress errorcode MAINDATA_UNDERFLOW
}
else {
printDecodeError(m_decodeError); printDecodeError(m_decodeError);
m_f_playing = false; // seek for new syncword m_f_playing = false; // seek for new syncword
if(m_codec == CODEC_FLAC) { if(m_codec == CODEC_FLAC) {
...@@ -4444,7 +4440,7 @@ int Audio::sendBytes(uint8_t* data, size_t len) { ...@@ -4444,7 +4440,7 @@ int Audio::sendBytes(uint8_t* data, size_t len) {
if(m_decodeError == ERR_OPUS_WIDE_BAND_UNSUPPORTED) stopSong(); if(m_decodeError == ERR_OPUS_WIDE_BAND_UNSUPPORTED) stopSong();
if(m_decodeError == ERR_OPUS_SUPER_WIDE_BAND_UNSUPPORTED) stopSong(); if(m_decodeError == ERR_OPUS_SUPER_WIDE_BAND_UNSUPPORTED) stopSong();
} }
}
return 1; // skip one byte and seek for the next sync word return 1; // skip one byte and seek for the next sync word
} }
bytesDecoded = len - bytesLeft; bytesDecoded = len - bytesLeft;
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
* libhelix_HMP3DECODER * libhelix_HMP3DECODER
* *
* Created on: 26.10.2018 * Created on: 26.10.2018
* Updated on: 29.03.2023 * Updated on: 22.04.2023
*/ */
#include "mp3_decoder.h" #include "mp3_decoder.h"
/* clip to range [-2^n, 2^n - 1] */ /* clip to range [-2^n, 2^n - 1] */
...@@ -1382,6 +1382,7 @@ int MP3Decode( unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize) ...@@ -1382,6 +1382,7 @@ int MP3Decode( unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize)
int offset, bitOffset, mainBits, gr, ch, fhBytes, siBytes, freeFrameBytes; int offset, bitOffset, mainBits, gr, ch, fhBytes, siBytes, freeFrameBytes;
int prevBitOffset, sfBlockBits, huffBlockBits; int prevBitOffset, sfBlockBits, huffBlockBits;
unsigned char *mainPtr; unsigned char *mainPtr;
static uint8_t underflowCounter = 0; // http://macslons-irish-pub-radio.stream.laut.fm/macslons-irish-pub-radio
/* unpack frame header */ /* unpack frame header */
fhBytes = UnpackFrameHeader(inbuf); fhBytes = UnpackFrameHeader(inbuf);
...@@ -1444,6 +1445,7 @@ int MP3Decode( unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize) ...@@ -1444,6 +1445,7 @@ int MP3Decode( unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize)
/* fill main data buffer with enough new data for this frame */ /* fill main data buffer with enough new data for this frame */
if (m_MP3DecInfo->mainDataBytes >= m_MP3DecInfo->mainDataBegin) { if (m_MP3DecInfo->mainDataBytes >= m_MP3DecInfo->mainDataBegin) {
/* adequate "old" main data available (i.e. bit reservoir) */ /* adequate "old" main data available (i.e. bit reservoir) */
underflowCounter = 0;
memmove(m_MP3DecInfo->mainBuf, memmove(m_MP3DecInfo->mainBuf,
m_MP3DecInfo->mainBuf + m_MP3DecInfo->mainDataBytes - m_MP3DecInfo->mainDataBegin, m_MP3DecInfo->mainBuf + m_MP3DecInfo->mainDataBytes - m_MP3DecInfo->mainDataBegin,
m_MP3DecInfo->mainDataBegin); m_MP3DecInfo->mainDataBegin);
...@@ -1456,10 +1458,14 @@ int MP3Decode( unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize) ...@@ -1456,10 +1458,14 @@ int MP3Decode( unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize)
mainPtr = m_MP3DecInfo->mainBuf; mainPtr = m_MP3DecInfo->mainBuf;
} else { } else {
/* not enough data in bit reservoir from previous frames (perhaps starting in middle of file) */ /* not enough data in bit reservoir from previous frames (perhaps starting in middle of file) */
underflowCounter ++;
memcpy(m_MP3DecInfo->mainBuf + m_MP3DecInfo->mainDataBytes, inbuf, m_MP3DecInfo->nSlots); memcpy(m_MP3DecInfo->mainBuf + m_MP3DecInfo->mainDataBytes, inbuf, m_MP3DecInfo->nSlots);
m_MP3DecInfo->mainDataBytes += m_MP3DecInfo->nSlots; m_MP3DecInfo->mainDataBytes += m_MP3DecInfo->nSlots;
inbuf += m_MP3DecInfo->nSlots; inbuf += m_MP3DecInfo->nSlots;
*bytesLeft -= (m_MP3DecInfo->nSlots); *bytesLeft -= (m_MP3DecInfo->nSlots);
if(underflowCounter < 4){
return ERR_MP3_NONE;
}
MP3ClearBadFrame( outbuf); MP3ClearBadFrame( outbuf);
return ERR_MP3_MAINDATA_UNDERFLOW; return ERR_MP3_MAINDATA_UNDERFLOW;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment