Unverified Commit e8bac79b authored by Wolle's avatar Wolle Committed by GitHub

Add files via upload

parent b72d36ac
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
* libhelix_mp3.cpp * libhelix_mp3.cpp
* *
* Created on: 26.10.2018 * Created on: 26.10.2018
* Updated on: 04.11.2018
*/ */
#include "mp3_decoder.h" #include "mp3_decoder.h"
...@@ -794,7 +795,7 @@ static void MP3ClearBadFrame(MP3DecInfo *mp3DecInfo, short *outbuf) { ...@@ -794,7 +795,7 @@ static void MP3ClearBadFrame(MP3DecInfo *mp3DecInfo, short *outbuf) {
* Notes: switching useSize on and off between frames in the same stream * Notes: switching useSize on and off between frames in the same stream
* is not supported (bit reservoir is not maintained if useSize on) * is not supported (bit reservoir is not maintained if useSize on)
**************************************************************************************/ **************************************************************************************/
int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, short *outbuf, int useSize){ int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize){
int offset, bitOffset, mainBits, gr, ch, fhBytes, siBytes, freeFrameBytes; int offset, bitOffset, mainBits, gr, ch, fhBytes, siBytes, freeFrameBytes;
int prevBitOffset, sfBlockBits, huffBlockBits; int prevBitOffset, sfBlockBits, huffBlockBits;
unsigned char *mainPtr; unsigned char *mainPtr;
...@@ -803,17 +804,17 @@ int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, sh ...@@ -803,17 +804,17 @@ int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, sh
return ERR_MP3_NULL_POINTER; return ERR_MP3_NULL_POINTER;
/* unpack frame header */ /* unpack frame header */
fhBytes = UnpackFrameHeader(mp3DecInfo, *inbuf); fhBytes = UnpackFrameHeader(mp3DecInfo, inbuf);
if (fhBytes < 0) if (fhBytes < 0)
return ERR_MP3_INVALID_FRAMEHEADER; /* don't clear outbuf since we don't know size (failed to parse header) */ return ERR_MP3_INVALID_FRAMEHEADER; /* don't clear outbuf since we don't know size (failed to parse header) */
*inbuf += fhBytes; inbuf += fhBytes;
/* unpack side info */ /* unpack side info */
siBytes = UnpackSideInfo(mp3DecInfo, *inbuf); siBytes = UnpackSideInfo(mp3DecInfo, inbuf);
if (siBytes < 0) { if (siBytes < 0) {
MP3ClearBadFrame(mp3DecInfo, outbuf); MP3ClearBadFrame(mp3DecInfo, outbuf);
return ERR_MP3_INVALID_SIDEINFO; return ERR_MP3_INVALID_SIDEINFO;
} }
*inbuf += siBytes; inbuf += siBytes;
*bytesLeft -= (fhBytes + siBytes); *bytesLeft -= (fhBytes + siBytes);
/* if free mode, need to calculate bitrate and nSlots manually, based on frame size */ /* if free mode, need to calculate bitrate and nSlots manually, based on frame size */
...@@ -821,8 +822,7 @@ int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, sh ...@@ -821,8 +822,7 @@ int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, sh
if (!mp3DecInfo->freeBitrateFlag) { if (!mp3DecInfo->freeBitrateFlag) {
/* first time through, need to scan for next sync word and figure out frame size */ /* first time through, need to scan for next sync word and figure out frame size */
mp3DecInfo->freeBitrateFlag = 1; mp3DecInfo->freeBitrateFlag = 1;
mp3DecInfo->freeBitrateSlots = MP3FindFreeSync(*inbuf, mp3DecInfo->freeBitrateSlots = MP3FindFreeSync(inbuf, inbuf - fhBytes - siBytes, *bytesLeft);
*inbuf - fhBytes - siBytes, *bytesLeft);
if (mp3DecInfo->freeBitrateSlots < 0) { if (mp3DecInfo->freeBitrateSlots < 0) {
MP3ClearBadFrame(mp3DecInfo, outbuf); MP3ClearBadFrame(mp3DecInfo, outbuf);
return ERR_MP3_FREE_BITRATE_SYNC; return ERR_MP3_FREE_BITRATE_SYNC;
...@@ -851,8 +851,8 @@ int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, sh ...@@ -851,8 +851,8 @@ int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, sh
/* can operate in-place on reformatted frames */ /* can operate in-place on reformatted frames */
mp3DecInfo->mainDataBytes = mp3DecInfo->nSlots; mp3DecInfo->mainDataBytes = mp3DecInfo->nSlots;
mainPtr = *inbuf; mainPtr = inbuf;
*inbuf += mp3DecInfo->nSlots; inbuf += mp3DecInfo->nSlots;
*bytesLeft -= (mp3DecInfo->nSlots); *bytesLeft -= (mp3DecInfo->nSlots);
} else { } else {
/* out of data - assume last or truncated frame */ /* out of data - assume last or truncated frame */
...@@ -867,20 +867,20 @@ int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, sh ...@@ -867,20 +867,20 @@ int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, sh
mp3DecInfo->mainBuf + mp3DecInfo->mainDataBytes mp3DecInfo->mainBuf + mp3DecInfo->mainDataBytes
- mp3DecInfo->mainDataBegin, - mp3DecInfo->mainDataBegin,
mp3DecInfo->mainDataBegin); mp3DecInfo->mainDataBegin);
memcpy(mp3DecInfo->mainBuf + mp3DecInfo->mainDataBegin, *inbuf, memcpy(mp3DecInfo->mainBuf + mp3DecInfo->mainDataBegin, inbuf,
mp3DecInfo->nSlots); mp3DecInfo->nSlots);
mp3DecInfo->mainDataBytes = mp3DecInfo->mainDataBegin mp3DecInfo->mainDataBytes = mp3DecInfo->mainDataBegin
+ mp3DecInfo->nSlots; + mp3DecInfo->nSlots;
*inbuf += mp3DecInfo->nSlots; inbuf += mp3DecInfo->nSlots;
*bytesLeft -= (mp3DecInfo->nSlots); *bytesLeft -= (mp3DecInfo->nSlots);
mainPtr = mp3DecInfo->mainBuf; mainPtr = mp3DecInfo->mainBuf;
} else { } else {
/* not enough data in bit reservoir from previous frames (perhaps starting in middle of file) */ /* not enough data in bit reservoir from previous frames (perhaps starting in middle of file) */
memcpy(mp3DecInfo->mainBuf + mp3DecInfo->mainDataBytes, *inbuf, memcpy(mp3DecInfo->mainBuf + mp3DecInfo->mainDataBytes, inbuf,
mp3DecInfo->nSlots); mp3DecInfo->nSlots);
mp3DecInfo->mainDataBytes += mp3DecInfo->nSlots; mp3DecInfo->mainDataBytes += mp3DecInfo->nSlots;
*inbuf += mp3DecInfo->nSlots; inbuf += mp3DecInfo->nSlots;
*bytesLeft -= (mp3DecInfo->nSlots); *bytesLeft -= (mp3DecInfo->nSlots);
MP3ClearBadFrame(mp3DecInfo, outbuf); MP3ClearBadFrame(mp3DecInfo, outbuf);
return ERR_MP3_MAINDATA_UNDERFLOW; return ERR_MP3_MAINDATA_UNDERFLOW;
......
...@@ -1401,7 +1401,7 @@ extern "C" { ...@@ -1401,7 +1401,7 @@ extern "C" {
typedef void *HMP3Decoder; typedef void *HMP3Decoder;
HMP3Decoder MP3InitDecoder(void); HMP3Decoder MP3InitDecoder(void);
void MP3FreeDecoder(HMP3Decoder hMP3Decoder); void MP3FreeDecoder(HMP3Decoder hMP3Decoder);
int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char **inbuf, int *bytesLeft, short *outbuf, int useSize); int MP3Decode(HMP3Decoder hMP3Decoder, unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize);
void MP3GetLastFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo); void MP3GetLastFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo);
int MP3GetNextFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo, unsigned char *buf); int MP3GetNextFrameInfo(HMP3Decoder hMP3Decoder, MP3FrameInfo *mp3FrameInfo, unsigned char *buf);
int MP3FindSyncWord(unsigned char *buf, int nBytes); int MP3FindSyncWord(unsigned char *buf, int nBytes);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment