Skip to content

Commit bb7e813

Browse files
committed
allow OPUS 44.1KHz
and don't blocking stopSong() in case of an error
1 parent 12ab303 commit bb7e813

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/Audio.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2262,7 +2262,9 @@ size_t Audio::process_m3u8_ID3_Header(uint8_t* packet) {
22622262
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
22632263
uint32_t Audio::stopSong() {
22642264
m_f_lockInBuffer = true; // wait for the decoding to finish
2265-
while(m_f_audioTaskIsDecoding) vTaskDelay(1);
2265+
static uint8_t maxWait = 0;
2266+
while(m_f_audioTaskIsDecoding) {vTaskDelay(1); maxWait++; if(maxWait > 100) break;} // in case of error wait max 100ms
2267+
maxWait = 0;
22662268
uint32_t pos = 0;
22672269
if(m_f_running) {
22682270
m_f_running = false;
@@ -2283,7 +2285,7 @@ uint32_t Audio::stopSong() {
22832285
m_audioFileDuration = 0;
22842286
m_codec = CODEC_NONE;
22852287
m_dataMode = AUDIO_NONE;
2286-
m_f_lockInBuffer = false;
2288+
m_f_lockInBuffer = false;
22872289
return pos;
22882290
}
22892291
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
@@ -4483,6 +4485,8 @@ int Audio::sendBytes(uint8_t* data, size_t len) {
44834485
if(m_decodeError == ERR_OPUS_NARROW_BAND_UNSUPPORTED) stopSong();
44844486
if(m_decodeError == ERR_OPUS_WIDE_BAND_UNSUPPORTED) stopSong();
44854487
if(m_decodeError == ERR_OPUS_SUPER_WIDE_BAND_UNSUPPORTED) stopSong();
4488+
if(m_decodeError == ERR_OPUS_INVALID_SAMPLERATE) stopSong();
4489+
return 0;
44864490
}
44874491

44884492
return 1; // skip one byte and seek for the next sync word

src/opus_decoder/opus_decoder.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* based on Xiph.Org Foundation celt decoder
44
*
55
* Created on: 26.01.2023
6-
* Updated on: 09.09.2024
6+
* Updated on: 03.11.2024
77
*/
88
//----------------------------------------------------------------------------------------------------------------------
99
// O G G / O P U S I M P L.
@@ -211,6 +211,7 @@ int32_t opusDecodePage0(uint8_t* inbuf, int32_t* bytesLeft, uint32_t segmentLeng
211211
s_opusCurrentFilePos += segmentLength;
212212
if(ret == 1){ s_opusPageNr++;}
213213
if(ret == 0){ log_e("OpusHead not found"); }
214+
if(ret < 0) return ret;
214215
return OPUS_PARSE_OGG_DONE;
215216
}
216217
//----------------------------------------------------------------------------------------------------------------------------------------------------
@@ -276,7 +277,7 @@ int32_t opusDecodePage3(uint8_t* inbuf, int32_t* bytesLeft, uint32_t segmentLeng
276277
// silk_InitDecoder();
277278
}
278279

279-
samplesPerFrame = opus_packet_get_samples_per_frame(inbuf, s_opusSamplerate);
280+
samplesPerFrame = opus_packet_get_samples_per_frame(inbuf, /*s_opusSamplerate*/ 48000);
280281

281282
FramePacking: // https://www.tech-invite.com/y65/tinv-ietf-rfc-6716-2.html 3.2. Frame Packing
282283
//log_i("s_opusCountCode %i, configNr %i", s_opusCountCode, configNr);
@@ -801,7 +802,7 @@ int32_t parseOpusHead(uint8_t *inbuf, int32_t nBytes){ // reference https://wik
801802

802803
if(channelCount == 0 || channelCount >2) return ERR_OPUS_CHANNELS_OUT_OF_RANGE;
803804
s_opusChannels = channelCount;
804-
if(sampleRate != 48000) return ERR_OPUS_INVALID_SAMPLERATE;
805+
if(sampleRate != 48000 && sampleRate != 44100) return ERR_OPUS_INVALID_SAMPLERATE;
805806
s_opusSamplerate = sampleRate;
806807
if(channelMap > 1) return ERR_OPUS_EXTRA_CHANNELS_UNSUPPORTED;
807808

0 commit comments

Comments
 (0)