@@ -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 }
0 commit comments