Skip to content

Commit d8253f9

Browse files
committed
aac channel config change
1 parent e817fb9 commit d8253f9

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/Audio.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
audio.cpp
44
55
Created on: Oct 28.2018 */char audioI2SVers[] ="\
6-
Version 3.3.0b ";
7-
/* Updated on: Jun 01.2025
6+
Version 3.3.0c ";
7+
/* Updated on: Jun 02.2025
88
99
Author: Wolle (schreibfaul1)
1010
Audio library for ESP32, ESP32-S3 or ESP32-P4
@@ -4733,6 +4733,22 @@ int Audio::sendBytes(uint8_t* data, size_t len) {
47334733
return findNextSync(data, bytesLeft); // skip last mp3 frame and search for next syncword
47344734
}
47354735
}
4736+
// According to the specification, the channel configuration is transferred in the first ADTS header and no longer changes in the entire
4737+
// stream. Some streams send short mono blocks in a stereo stream. e.g. http://mp3.ffh.de/ffhchannels/soundtrack.aac
4738+
// This triggers error -21 because the faad2 decoder cannot switch automatically.
4739+
if(m_codec == CODEC_AAC && m_decodeError == -21){ // mono <-> stereo change
4740+
static uint8_t channels = 0;
4741+
if ((data[0] == 0xFF) || ((data[1] & 0xF0) == 0xF0)){
4742+
int channel_config = ((data[2] & 0x01) << 2) | ((data[3] & 0xC0) >> 6);
4743+
if(channel_config != channels) {
4744+
channels = channel_config;
4745+
AUDIO_INFO("AAC channel config changed to %d", channels);
4746+
}
4747+
}
4748+
AACDecoder_FreeBuffers();
4749+
AACDecoder_AllocateBuffers();
4750+
return 0;
4751+
}
47364752

47374753
printDecodeError(m_decodeError);
47384754
m_f_playing = false; // seek for new syncword

src/aac_decoder/libfaad/neaacdec.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7214,8 +7214,8 @@ uint8_t reconstruct_single_channel(NeAACDecStruct* hDecoder, ic_stream* ics, ele
72147214
sizeof(uint8_t) * (MAX_SYNTAX_ELEMENTS - hDecoder->fr_ch_ele));
72157215

72167216
hDecoder->element_output_channels[hDecoder->fr_ch_ele] = output_channels;
7217-
//retval = 21;
7218-
//goto exit;
7217+
retval = 21;
7218+
goto exit;
72197219
}
72207220
if (hDecoder->element_alloced[hDecoder->fr_ch_ele] == 0) {
72217221
retval = allocate_single_channel(hDecoder, sce->channel, output_channels);

0 commit comments

Comments
 (0)