Skip to content

Commit

Permalink
stopSong() Wait for the decoding to finish
Browse files Browse the repository at this point in the history
  • Loading branch information
schreibfaul1 committed Sep 9, 2024
1 parent 8f1c5d6 commit 32d5f04
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 23 deletions.
45 changes: 23 additions & 22 deletions src/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Created on: Oct 27.2018
*
* Version 3.0.12m
* Version 3.0.12n
* Updated on: Sep 09.2024
* Author: Wolle (schreibfaul1)
*
Expand Down Expand Up @@ -2243,27 +2243,28 @@ size_t Audio::process_m3u8_ID3_Header(uint8_t* packet) {
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
uint32_t Audio::stopSong() {
uint32_t pos = 0;
if(m_f_running) {
m_f_running = false;
if(m_dataMode == AUDIO_LOCALFILE) {
m_streamType = ST_NONE;
pos = getFilePos() - inBufferFilled();
m_f_lockInBuffer = true; // wait for the decoding to finish
while(m_f_audioTaskIsDecoding) vTaskDelay(1);
uint32_t pos = 0;
if(m_f_running) {
m_f_running = false;
if(m_dataMode == AUDIO_LOCALFILE) {
m_streamType = ST_NONE;
pos = getFilePos() - inBufferFilled();
}
if(_client->connected()) _client->stop();
}
if(_client->connected()) _client->stop();
}
if(audiofile) {
// added this before putting 'm_f_localfile = false' in stopSong(); shoulf never occur....
AUDIO_INFO("Closing audio file \"%s\"", audiofile.name());
audiofile.close();
}
memset(m_outBuff, 0, m_outbuffSize); // Clear OutputBuffer
memset(m_filterBuff, 0, sizeof(m_filterBuff)); // Clear FilterBuffer
m_validSamples = 0;
m_audioCurrentTime = 0;
m_audioFileDuration = 0;
m_codec = CODEC_NONE;

if(audiofile) {
// added this before putting 'm_f_localfile = false' in stopSong(); shoulf never occur....
AUDIO_INFO("Closing audio file \"%s\"", audiofile.name());
audiofile.close();
}
memset(m_filterBuff, 0, sizeof(m_filterBuff)); // Clear FilterBuffer
m_validSamples = 0;
m_audioCurrentTime = 0;
m_audioFileDuration = 0;
m_codec = CODEC_NONE;
m_f_lockInBuffer = false;
return pos;
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -4409,7 +4410,7 @@ void Audio::setDecoderItems() {
}
//------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
int Audio::sendBytes(uint8_t* data, size_t len) {

if(!m_f_running) return 0; // guard
int32_t bytesLeft;
static bool f_setDecodeParamsOnce = true;
int nextSync = 0;
Expand Down
2 changes: 1 addition & 1 deletion src/Audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
*
* Created on: Oct 28,2018
*
* Version 3.0.12m
* Version 3.0.12n
* Updated on: Sep 09.2024
* Author: Wolle (schreibfaul1)
*/
Expand Down
1 change: 1 addition & 0 deletions src/aac_decoder/libfaad/neaacdec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9918,6 +9918,7 @@ uint8_t window_grouping_info(NeAACDecStruct_t* hDecoder, ic_stream_t* ics) {
if(hDecoder->object_type == LD) {
if(hDecoder->frameLength == 512) {
for(i = 0; i < ics->num_swb; i++) {
log_e("i %i", i);
ics->sect_sfb_offset[0][i] = swb_offset_512_window[sf_index][i];
ics->swb_offset[i] = swb_offset_512_window[sf_index][i];
}
Expand Down

0 comments on commit 32d5f04

Please sign in to comment.