Commit e2e4df30 authored by schreibfaul1's avatar schreibfaul1

prevent maindata underflow at start

and remove some unnecessary code
parent 59784c56
......@@ -3,7 +3,7 @@
*
* Created on: Oct 26.2018
*
* Version 3.0.9h
* Version 3.0.9i
* Updated on: Apr 22.2024
* Author: Wolle (schreibfaul1)
*
......@@ -4426,25 +4426,21 @@ int Audio::sendBytes(uint8_t* data, size_t len) {
// < 0: there has been an error
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
printDecodeError(m_decodeError);
m_f_playing = false; // seek for new syncword
if(m_codec == CODEC_FLAC) {
// if(m_decodeError == ERR_FLAC_BITS_PER_SAMPLE_TOO_BIG) stopSong();
// if(m_decodeError == ERR_FLAC_RESERVED_CHANNEL_ASSIGNMENT) stopSong();
}
else {
printDecodeError(m_decodeError);
m_f_playing = false; // seek for new syncword
if(m_codec == CODEC_FLAC) {
// if(m_decodeError == ERR_FLAC_BITS_PER_SAMPLE_TOO_BIG) stopSong();
// if(m_decodeError == ERR_FLAC_RESERVED_CHANNEL_ASSIGNMENT) stopSong();
}
if(m_codec == CODEC_OPUS) {
if(m_decodeError == ERR_OPUS_HYBRID_MODE_UNSUPPORTED) stopSong();
if(m_decodeError == ERR_OPUS_SILK_MODE_UNSUPPORTED) stopSong();
if(m_decodeError == ERR_OPUS_NARROW_BAND_UNSUPPORTED) stopSong();
if(m_decodeError == ERR_OPUS_WIDE_BAND_UNSUPPORTED) stopSong();
if(m_decodeError == ERR_OPUS_SUPER_WIDE_BAND_UNSUPPORTED) stopSong();
}
if(m_codec == CODEC_OPUS) {
if(m_decodeError == ERR_OPUS_HYBRID_MODE_UNSUPPORTED) stopSong();
if(m_decodeError == ERR_OPUS_SILK_MODE_UNSUPPORTED) stopSong();
if(m_decodeError == ERR_OPUS_NARROW_BAND_UNSUPPORTED) stopSong();
if(m_decodeError == ERR_OPUS_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
}
bytesDecoded = len - bytesLeft;
......
......@@ -3,7 +3,7 @@
* libhelix_HMP3DECODER
*
* Created on: 26.10.2018
* Updated on: 29.03.2023
* Updated on: 22.04.2023
*/
#include "mp3_decoder.h"
/* clip to range [-2^n, 2^n - 1] */
......@@ -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 prevBitOffset, sfBlockBits, huffBlockBits;
unsigned char *mainPtr;
static uint8_t underflowCounter = 0; // http://macslons-irish-pub-radio.stream.laut.fm/macslons-irish-pub-radio
/* unpack frame header */
fhBytes = UnpackFrameHeader(inbuf);
......@@ -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 */
if (m_MP3DecInfo->mainDataBytes >= m_MP3DecInfo->mainDataBegin) {
/* adequate "old" main data available (i.e. bit reservoir) */
underflowCounter = 0;
memmove(m_MP3DecInfo->mainBuf,
m_MP3DecInfo->mainBuf + m_MP3DecInfo->mainDataBytes - m_MP3DecInfo->mainDataBegin,
m_MP3DecInfo->mainDataBegin);
......@@ -1456,10 +1458,14 @@ int MP3Decode( unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize)
mainPtr = m_MP3DecInfo->mainBuf;
} else {
/* 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);
m_MP3DecInfo->mainDataBytes += m_MP3DecInfo->nSlots;
inbuf += m_MP3DecInfo->nSlots;
*bytesLeft -= (m_MP3DecInfo->nSlots);
if(underflowCounter < 4){
return ERR_MP3_NONE;
}
MP3ClearBadFrame( outbuf);
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