Skip to content

Commit 3bed917

Browse files
authored
Merge pull request #1212 from schreibfaul1/32bit
out buffer 16bit --> 32bit
2 parents 369335e + cddf33c commit 3bed917

File tree

15 files changed

+592
-244
lines changed

15 files changed

+592
-244
lines changed

src/Audio.cpp

Lines changed: 424 additions & 145 deletions
Large diffs are not rendered by default.

src/Audio.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,10 @@ class Audio {
200200
size_t resampleTo48kStereo(const int16_t* input, size_t inputFrames);
201201
void playChunk();
202202
void computeVUlevel(int16_t sample[2]);
203+
void computeVUlevel1(int32_t* sample);
203204
void computeLimit();
204205
void Gain(int16_t* sample);
206+
void Gain1(int32_t* sample);
205207
void showstreamtitle(char* ml);
206208
bool parseContentType(char* ct);
207209
bool parseHttpResponseHeader();
@@ -210,9 +212,13 @@ class Audio {
210212
esp_err_t I2Sstart();
211213
esp_err_t I2Sstop();
212214
void zeroI2Sbuff();
213-
void IIR_filterChain0(int16_t iir_in[2], bool clear = false);
214-
void IIR_filterChain1(int16_t iir_in[2], bool clear = false);
215-
void IIR_filterChain2(int16_t iir_in[2], bool clear = false);
215+
void reconfigI2S();
216+
void IIR_filterChain0_s16(int16_t* iir_in, bool clear = false);
217+
void IIR_filterChain1_s16(int16_t* iir_in, bool clear = false);
218+
void IIR_filterChain2_s16(int16_t* iir_in, bool clear = false);
219+
void IIR_filterChain0_s32(int32_t* iir_in, bool clear = false);
220+
void IIR_filterChain1_s32(int32_t* iir_in, bool clear = false);
221+
void IIR_filterChain2_s32(int32_t* iir_in, bool clear = false);
216222
uint32_t streamavail() { return m_client ? m_client->available() : 0; }
217223
void IIR_calculateCoefficients(int8_t G1, int8_t G2, int8_t G3);
218224
bool ts_parsePacket(uint8_t* packet, uint8_t* packetStart, uint8_t* packetLength);
@@ -347,7 +353,7 @@ class Audio {
347353
static const uint8_t m_tsHeaderSize = 4;
348354

349355
std::unique_ptr<Decoder> m_decoder = {};
350-
ps_ptr<int16_t> m_outBuff; // Interleaved L/R
356+
ps_ptr<int32_t> m_outBuff; // Interleaved L/R
351357
ps_ptr<int16_t> m_samplesBuff48K; // Interleaved L/R
352358
ps_ptr<char> m_ibuff; // used in log_info()
353359
ps_ptr<char> m_lastHost; // Store the last URL to a webstream
@@ -662,7 +668,7 @@ class Decoder {
662668
virtual uint32_t getAudioDataStart() = 0;
663669
virtual uint32_t getAudioFileDuration() = 0;
664670
virtual uint32_t getOutputSamples() = 0;
665-
virtual int32_t decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf) = 0;
671+
virtual int32_t decode(uint8_t* inbuf, int32_t* bytesLeft, int32_t* outbuf1) = 0;
666672
virtual void setRawBlockParams(uint8_t param1, uint32_t param2, uint8_t param3, uint32_t param4, uint32_t param5) = 0;
667673
virtual const char* getStreamTitle();
668674
virtual const char* whoIsIt();

src/aac_decoder/aac_decoder.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,11 @@ const char* AACDecoder::getErrorMessage(int8_t err) {
116116
return m_neaacdec->NeAACDecGetErrorMessage(abs(err));
117117
}
118118
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
119-
int32_t AACDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf) {
120-
uint8_t* ob = (uint8_t*)outbuf;
119+
int32_t AACDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int32_t* outbuf) {
120+
121+
int16_t* out16 = reinterpret_cast<int16_t*>(outbuf);
122+
123+
uint8_t* ob = (uint8_t*)out16;
121124
if (m_f_firstCall == false) {
122125
if (m_f_setRaWBlockParams) { // set raw AAC values, e.g. for M4A config.
123126
m_f_setRaWBlockParams = false;

src/aac_decoder/aac_decoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ class AACDecoder : public Decoder {
3737
uint32_t getAudioFileDuration() override;
3838
const char* getStreamTitle() override;
3939
const char* whoIsIt() override;
40-
int32_t decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf) override;
40+
int32_t decode(uint8_t* inbuf, int32_t* bytesLeft, int32_t* outbuf) override;
4141
void setRawBlockParams(uint8_t channels, uint32_t sampleRate, uint8_t BPS, uint32_t tsis, uint32_t AuDaLength) override;
4242
std::vector<uint32_t> getMetadataBlockPicture() override;
4343
const char* arg1() override;

src/audiolib_structs.hpp

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,11 @@ struct plCh_t { // used in playChunk
125125
int32_t samples48K = 0;
126126
uint32_t count = 0;
127127
size_t i2s_bytesConsumed;
128+
uint16_t samples;
128129
int16_t* sample[2];
129-
int16_t* s2;
130+
int32_t* sample1;
131+
int16_t* s16;
132+
int32_t* s32;
130133
int sampleSize;
131134
esp_err_t err;
132135
int i;
@@ -184,15 +187,26 @@ struct cVUl_t { // used in computeVUlevel
184187
};
185188

186189
struct ifCh_t { // used in IIR_filterChain0, 1, 2
187-
float inSample0[2];
188-
float outSample0[2];
189-
int16_t iir_out0[2];
190-
float inSample1[2];
191-
float outSample1[2];
192-
int16_t iir_out1[2];
193-
float inSample2[2];
194-
float outSample2[2];
195-
int16_t iir_out2[2];
190+
// s16
191+
float inSample0_16[2];
192+
float outSample0_16[2];
193+
int16_t iir_out0_16[2];
194+
float inSample1_16[2];
195+
float outSample1_16[2];
196+
int16_t iir_out1_16[2];
197+
float inSample2_16[2];
198+
float outSample2_16[2];
199+
int16_t iir_out2_16[2];
200+
// s32
201+
float inSample0_32[2];
202+
float outSample0_32[2];
203+
int32_t iir_out0_32[2];
204+
float inSample1_32[2];
205+
float outSample1_32[2];
206+
int32_t iir_out1_32[2];
207+
float inSample2_32[2];
208+
float outSample2_32[2];
209+
int32_t iir_out2_32[2];
196210
};
197211

198212
typedef struct _tspp { // used in ts_parsePacket

src/flac_decoder/flac_decoder.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,9 @@ int32_t FlacDecoder::parseMetaDataBlockHeader(uint8_t* inbuf, int16_t nBytes) {
524524
return 0;
525525
}
526526
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
527-
int32_t FlacDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf) { // MAIN LOOP
527+
int32_t FlacDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int32_t* outbuf) { // MAIN LOOP
528+
529+
int16_t* out16 = reinterpret_cast<int16_t*>(outbuf);
528530

529531
int32_t ret = 0;
530532
uint32_t segmLen = 0;
@@ -559,7 +561,7 @@ int32_t FlacDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
559561
if (m_nBytes > 0) {
560562
int16_t diff = m_nBytes;
561563
if (m_flacAudioDataStart == 0) { m_flacAudioDataStart = m_flacCurrentFilePos; }
562-
ret = decodeNative(inbuf, &m_nBytes, outbuf);
564+
ret = decodeNative(inbuf, &m_nBytes, out16);
563565
diff -= m_nBytes;
564566
m_flacCurrentFilePos += diff;
565567
*bytesLeft -= diff;
@@ -641,7 +643,7 @@ int32_t FlacDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
641643
m_flacCurrentFilePos += segmLen;
642644
return ret;
643645
}
644-
ret = decodeNative(inbuf, bytesLeft, outbuf);
646+
ret = decodeNative(inbuf, bytesLeft, out16);
645647
return ret;
646648
}
647649
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

src/flac_decoder/flac_decoder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FlacDecoder : public Decoder {
4747
uint32_t getAudioFileDuration() override;
4848
const char* getStreamTitle() override;
4949
const char* whoIsIt() override;
50-
int32_t decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf) override;
50+
int32_t decode(uint8_t* inbuf, int32_t* bytesLeft, int32_t* outbuf) override;
5151
void setRawBlockParams(uint8_t channels, uint32_t sampleRate, uint8_t BPS, uint32_t tsis, uint32_t AuDaLength) override;
5252
std::vector<uint32_t> getMetadataBlockPicture() override;
5353
const char* arg1() override;

src/mp3_decoder/mp3_decoder.cpp

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,7 +1088,10 @@ int32_t MP3Decoder::IsLikelyRealFrame(const uint8_t* p, int32_t bytesLeft) {
10881088
* Notes: switching useSize on and off between frames in the same stream
10891089
* is not supported (bit reservoir is not maintained if useSize on)
10901090
*/
1091-
int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf) {
1091+
1092+
int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int32_t* outbuf) {
1093+
1094+
int16_t* out16 = reinterpret_cast<int16_t*>(outbuf);
10921095

10931096
// Skip fake frames
10941097
int frameLen = IsLikelyRealFrame(inbuf, *bytesLeft);
@@ -1141,14 +1144,14 @@ int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
11411144
/* unpack frame header */
11421145
fhBytes = UnpackFrameHeader(inbuf);
11431146
if (fhBytes < 0) {
1144-
MP3_LOG_ERROR("MP3 invalid frameheader"); /* don't clear outbuf since we don't know size (failed to parse header) */
1147+
MP3_LOG_ERROR("MP3 invalid frameheader"); /* don't clear out16 since we don't know size (failed to parse header) */
11451148
return MP3_ERR;
11461149
}
11471150
inbuf += fhBytes;
11481151
/* unpack side info */
11491152
siBytes = UnpackSideInfo(inbuf);
11501153
if (siBytes < 0) {
1151-
MP3ClearBadFrame(outbuf);
1154+
MP3ClearBadFrame(out16);
11521155
MP3_LOG_ERROR("MP3 invalid sideinfo");
11531156
return MP3_ERR;
11541157
}
@@ -1162,7 +1165,7 @@ int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
11621165
m_MP3DecInfo->freeBitrateFlag = 1;
11631166
m_MP3DecInfo->freeBitrateSlots = MP3FindFreeSync(inbuf, inbuf - fhBytes - siBytes, *bytesLeft);
11641167
if (m_MP3DecInfo->freeBitrateSlots < 0) {
1165-
MP3ClearBadFrame(outbuf);
1168+
MP3ClearBadFrame(out16);
11661169
m_MP3DecInfo->freeBitrateFlag = 0;
11671170
MP3_LOG_ERROR("MP3, ca'nt find free bitrate slot");
11681171
return MP3_ERR;
@@ -1174,7 +1177,7 @@ int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
11741177
}
11751178

11761179
if (m_MP3DecInfo->nSlots > *bytesLeft) {
1177-
MP3ClearBadFrame(outbuf);
1180+
MP3ClearBadFrame(out16);
11781181
MP3_LOG_DEBUG("MP3, indata underflow");
11791182
return MP3_MAIN_DATA_UNDERFLOW;
11801183
}
@@ -1198,7 +1201,7 @@ int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
11981201
inbuf += m_MP3DecInfo->nSlots;
11991202
*bytesLeft -= (m_MP3DecInfo->nSlots);
12001203
if (underflowCounter < 4) { return MP3_NONE; }
1201-
MP3ClearBadFrame(outbuf);
1204+
MP3ClearBadFrame(out16);
12021205
MP3_LOG_DEBUG("MP3, maindata underflow");
12031206
return MP3_NONE;
12041207
}
@@ -1218,15 +1221,15 @@ int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
12181221
mainBits -= sfBlockBits;
12191222

12201223
if (offset < 0 || mainBits < huffBlockBits) {
1221-
MP3ClearBadFrame(outbuf);
1224+
MP3ClearBadFrame(out16);
12221225
MP3_LOG_ERROR("MP3, invalid scalefact");
12231226
return MP3_ERR;
12241227
}
12251228
/* decode Huffman code words */
12261229
prevBitOffset = bitOffset;
12271230
offset = DecodeHuffman(mainPtr, &bitOffset, huffBlockBits, gr, ch);
12281231
if (offset < 0) {
1229-
MP3ClearBadFrame(outbuf);
1232+
MP3ClearBadFrame(out16);
12301233
MP3_LOG_ERROR("MP3, invalid Huffman code words");
12311234
return MP3_ERR;
12321235
}
@@ -1235,22 +1238,22 @@ int32_t MP3Decoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
12351238
}
12361239
/* dequantize coefficients, decode stereo, reorder int16_t blocks */
12371240
if (MP3Dequantize(gr) < 0) {
1238-
MP3ClearBadFrame(outbuf);
1241+
MP3ClearBadFrame(out16);
12391242
MP3_LOG_ERROR("MP3, invalid dequantize coefficients");
12401243
return MP3_ERR;
12411244
}
12421245

12431246
/* alias reduction, inverse MDCT, overlap-add, frequency inversion */
12441247
for (ch = 0; ch < m_MP3DecInfo->nChans; ch++) {
12451248
if (IMDCT(gr, ch) < 0) {
1246-
MP3ClearBadFrame(outbuf);
1249+
MP3ClearBadFrame(out16);
12471250
MP3_LOG_ERROR("MP3, invalid inverse MDCT");
12481251
return MP3_ERR;
12491252
}
12501253
}
12511254
/* subband transform - if stereo, interleaves pcm LRLRLR */
1252-
if (Subband(outbuf + gr * m_MP3DecInfo->nGranSamps * m_MP3DecInfo->nChans) < 0) {
1253-
MP3ClearBadFrame(outbuf);
1255+
if (Subband(out16 + gr * m_MP3DecInfo->nGranSamps * m_MP3DecInfo->nChans) < 0) {
1256+
MP3ClearBadFrame(out16);
12541257
MP3_LOG_ERROR("MP3, invalid subband");
12551258
return MP3_ERR;
12561259
}

src/mp3_decoder/mp3_decoder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MP3Decoder : public Decoder {
2424
uint32_t getAudioFileDuration() override;
2525
const char* getStreamTitle() override;
2626
const char* whoIsIt() override;
27-
int32_t decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf) override;
27+
int32_t decode(uint8_t* inbuf, int32_t* bytesLeft, int32_t* outbuf) override;
2828
void setRawBlockParams(uint8_t channels, uint32_t sampleRate, uint8_t BPS, uint32_t tsis, uint32_t AuDaLength) override;
2929
std::vector<uint32_t> getMetadataBlockPicture() override;
3030
const char* arg1() override; // MPEG Version and Layer
@@ -35,7 +35,7 @@ class MP3Decoder : public Decoder {
3535
enum {
3636
MP3_NONE = 0,
3737
MP3_ERR = -1,
38-
MP3_MAIN_DATA_UNDERFLOW = - 2,
38+
MP3_MAIN_DATA_UNDERFLOW = -2,
3939
MP3_NEED_RESTART = -3,
4040
MP3_STOP = -100,
4141
MP3_NEXT_FRAME = 100,
@@ -62,7 +62,7 @@ class MP3Decoder : public Decoder {
6262
ps_ptr<MP3FrameInfo_t> m_MP3FrameInfo;
6363
ps_ptr<char> m_mpeg_version_str;
6464

65-
invalid_frame m_invalid_frame;
65+
invalid_frame m_invalid_frame;
6666

6767
// internally used
6868
int32_t IsLikelyRealFrame(const uint8_t* p, int32_t bytesLeft);

src/opus_decoder/opus_decoder.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,10 @@ void OpusDecoder::OPUSsetDefaults() {
124124
m_opusBlockPicItem.shrink_to_fit();
125125
}
126126
// —————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————
127-
int32_t OpusDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf) {
127+
int32_t OpusDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int32_t* outbuf) {
128+
129+
int16_t* out16 = reinterpret_cast<int16_t*>(outbuf);
130+
128131
int32_t ret = OPUS_NONE;
129132
int32_t segmLen = 0;
130133
int32_t bytesLeft_begin = *bytesLeft;
@@ -139,7 +142,7 @@ int32_t OpusDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
139142
}
140143

141144
if (m_frameCount > 0) { // decode audio, next part
142-
ret = opusDecodePage3(inbuf, bytesLeft, segmLen, outbuf);
145+
ret = opusDecodePage3(inbuf, bytesLeft, segmLen, out16);
143146
goto exit;
144147
}
145148

@@ -182,7 +185,7 @@ int32_t OpusDecoder::decode(uint8_t* inbuf, int32_t* bytesLeft, int16_t* outbuf)
182185
}
183186

184187
else if (m_opusPageNr == 3) {
185-
ret = opusDecodePage3(inbuf, bytesLeft, segmLen, outbuf); // decode audio
188+
ret = opusDecodePage3(inbuf, bytesLeft, segmLen, out16); // decode audio
186189
goto exit;
187190
}
188191

0 commit comments

Comments
 (0)