RSeries astromech firmware
mp3_decoder.h File Reference
#include "Arduino.h"
#include "assert.h"
+ Include dependency graph for mp3_decoder.h:

Go to the source code of this file.

Classes

struct  MP3FrameInfo
 
struct  SFBandTable
 
struct  BitStreamInfo
 
struct  FrameHeader
 
struct  SideInfoSub
 
struct  SideInfo
 
struct  CriticalBandInfo_t
 
struct  DequantInfo
 
struct  HuffmanInfo
 
struct  HuffTabLookup
 
struct  IMDCTInfo
 
struct  BlockCount
 
struct  ScaleFactorInfoSub
 
struct  ScaleFactorJS
 
struct  SubbandInfo
 
struct  MP3DecInfo
 

Typedefs

typedef struct MP3FrameInfo MP3FrameInfo_t
 
typedef struct SFBandTable SFBandTable_t
 
typedef struct BitStreamInfo BitStreamInfo_t
 
typedef struct FrameHeader FrameHeader_t
 
typedef struct SideInfoSub SideInfoSub_t
 
typedef struct SideInfo SideInfo_t
 
typedef struct DequantInfo DequantInfo_t
 
typedef struct HuffmanInfo HuffmanInfo_t
 
typedef enum HuffTabType HuffTabType_t
 
typedef struct HuffTabLookup HuffTabLookup_t
 
typedef struct IMDCTInfo IMDCTInfo_t
 
typedef struct BlockCount BlockCount_t
 
typedef struct ScaleFactorInfoSub ScaleFactorInfoSub_t
 
typedef struct ScaleFactorJS ScaleFactorJS_t
 
typedef struct SubbandInfo SubbandInfo_t
 
typedef struct MP3DecInfo MP3DecInfo_t
 

Enumerations

enum  {
  ERR_MP3_NONE = 0, ERR_MP3_INDATA_UNDERFLOW = -1, ERR_MP3_MAINDATA_UNDERFLOW = -2, ERR_MP3_FREE_BITRATE_SYNC = -3,
  ERR_MP3_OUT_OF_MEMORY = -4, ERR_MP3_NULL_POINTER = -5, ERR_MP3_INVALID_FRAMEHEADER = -6, ERR_MP3_INVALID_SIDEINFO = -7,
  ERR_MP3_INVALID_SCALEFACT = -8, ERR_MP3_INVALID_HUFFCODES = -9, ERR_MP3_INVALID_DEQUANTIZE = -10, ERR_MP3_INVALID_IMDCT = -11,
  ERR_MP3_INVALID_SUBBAND = -12, ERR_UNKNOWN = -9999
}
 
enum  StereoMode_t { Stereo = 0x00, Joint = 0x01, Dual = 0x02, Mono = 0x03 }
 
enum  MPEGVersion_t { MPEG1 = 0, MPEG2 = 1, MPEG25 = 2 }
 
enum  HuffTabType {
  noBits, oneShot, loopNoLinbits, loopLinbits,
  quadA, quadB, invalidTab
}
 

Functions

bool MP3Decoder_AllocateBuffers (void)
 
void MP3Decoder_FreeBuffers ()
 
int MP3Decode (unsigned char *inbuf, int *bytesLeft, short *outbuf, int useSize)
 
void MP3GetLastFrameInfo ()
 
int MP3GetNextFrameInfo (unsigned char *buf)
 
int MP3FindSyncWord (unsigned char *buf, int nBytes)
 
int MP3GetSampRate ()
 
int MP3GetChannels ()
 
int MP3GetBitsPerSample ()
 
int MP3GetBitrate ()
 
int MP3GetOutputSamps ()
 
int MP3GetDecodedSamps ()
 
void MP3Decoder_ClearBuffer (void)
 
void PolyphaseMono (short *pcm, int *vbuf, const uint32_t *coefBase)
 
void PolyphaseStereo (short *pcm, int *vbuf, const uint32_t *coefBase)
 
void SetBitstreamPointer (BitStreamInfo_t *bsi, int nBytes, unsigned char *buf)
 
unsigned int GetBits (BitStreamInfo_t *bsi, int nBits)
 
int CalcBitsUsed (BitStreamInfo_t *bsi, unsigned char *startBuf, int startOffset)
 
int DequantChannel (int *sampleBuf, int *workBuf, int *nonZeroBound, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi)
 
void MidSideProc (int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, int mOut[2])
 
void IntensityProcMPEG1 (int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi, int midSideFlag, int mixFlag, int mOut[2])
 
void IntensityProcMPEG2 (int x[m_MAX_NCHAN][m_MAX_NSAMP], int nSamps, ScaleFactorInfoSub_t *sfis, CriticalBandInfo_t *cbi, ScaleFactorJS_t *sfjs, int midSideFlag, int mixFlag, int mOut[2])
 
void FDCT32 (int *x, int *d, int offset, int oddBlock, int gb)
 
void FreeBuffers ()
 
int CheckPadBit ()
 
int UnpackFrameHeader (unsigned char *buf)
 
int UnpackSideInfo (unsigned char *buf)
 
int DecodeHuffman (unsigned char *buf, int *bitOffset, int huffBlockBits, int gr, int ch)
 
int MP3Dequantize (int gr)
 
int IMDCT (int gr, int ch)
 
int UnpackScaleFactors (unsigned char *buf, int *bitOffset, int bitsAvail, int gr, int ch)
 
int Subband (short *pcmBuf)
 
short ClipToShort (int x, int fracBits)
 
void RefillBitstreamCache (BitStreamInfo_t *bsi)
 
void UnpackSFMPEG1 (BitStreamInfo_t *bsi, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, int *scfsi, int gr, ScaleFactorInfoSub_t *sfisGr0)
 
void UnpackSFMPEG2 (BitStreamInfo_t *bsi, SideInfoSub_t *sis, ScaleFactorInfoSub_t *sfis, int gr, int ch, int modeExt, ScaleFactorJS_t *sfjs)
 
int MP3FindFreeSync (unsigned char *buf, unsigned char firstFH[4], int nBytes)
 
void MP3ClearBadFrame (short *outbuf)
 
int DecodeHuffmanPairs (int *xy, int nVals, int tabIdx, int bitsLeft, unsigned char *buf, int bitOffset)
 
int DecodeHuffmanQuads (int *vwxy, int nVals, int tabIdx, int bitsLeft, unsigned char *buf, int bitOffset)
 
int DequantBlock (int *inbuf, int *outbuf, int num, int scale)
 
void AntiAlias (int *x, int nBfly)
 
void WinPrevious (int *xPrev, int *xPrevWin, int btPrev)
 
int FreqInvertRescale (int *y, int *xPrev, int blockIdx, int es)
 
void idct9 (int *x)
 
int IMDCT36 (int *xCurr, int *xPrev, int *y, int btCurr, int btPrev, int blockIdx, int gb)
 
void imdct12 (int *x, int *out)
 
int IMDCT12x3 (int *xCurr, int *xPrev, int *y, int btPrev, int blockIdx, int gb)
 
int HybridTransform (int *xCurr, int *xPrev, int y[m_BLOCK_SIZE][m_NBANDS], SideInfoSub_t *sis, BlockCount_t *bc)
 
uint64_t SAR64 (uint64_t x, int n)
 
int MULSHIFT32 (int x, int y)
 
uint64_t MADD64 (uint64_t sum64, int x, int y)
 
int CLZ (int x)
 
uint64_t xSAR64 (uint64_t x, int n)
 
int FASTABS (int x)
 

Variables

const int c9_0 = 0x6ed9eba1
 
const int c9_1 = 0x620dbe8b
 
const int c9_2 = 0x163a1a7e
 
const int c9_3 = 0x5246dd49
 
const int c9_4 = 0x7e0e2e32
 
const int c3_0 = 0x6ed9eba1
 
const int c6 [3] = { 0x7ba3751d, 0x5a82799a, 0x2120fb83 }
 
const uint32_t c18 [9] = { 0x7f834ed0, 0x7ba3751d, 0x7401e4c1, 0x68d9f964, 0x5a82799a, 0x496af3e2, 0x36185aee, 0x2120fb83, 0x0b27eb5c}
 
const char m_SFLenTab [16][2]
 
const char NRTab [6][3][4]
 
const char preTab [22] = { 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0 }
 
const int pow14[4] PROGMEM
 
const uint16_t m_HUFF_OFFSET_01 = 0
 
const uint16_t m_HUFF_OFFSET_02 = 9 + m_HUFF_OFFSET_01
 
const uint16_t m_HUFF_OFFSET_03 = 65 + m_HUFF_OFFSET_02
 
const uint16_t m_HUFF_OFFSET_05 = 65 + m_HUFF_OFFSET_03
 
const uint16_t m_HUFF_OFFSET_06 =257 + m_HUFF_OFFSET_05
 
const uint16_t m_HUFF_OFFSET_07 =129 + m_HUFF_OFFSET_06
 
const uint16_t m_HUFF_OFFSET_08 =110 + m_HUFF_OFFSET_07
 
const uint16_t m_HUFF_OFFSET_09 =280 + m_HUFF_OFFSET_08
 
const uint16_t m_HUFF_OFFSET_10 = 93 + m_HUFF_OFFSET_09
 
const uint16_t m_HUFF_OFFSET_11 =320 + m_HUFF_OFFSET_10
 
const uint16_t m_HUFF_OFFSET_12 =296 + m_HUFF_OFFSET_11
 
const uint16_t m_HUFF_OFFSET_13 =185 + m_HUFF_OFFSET_12
 
const uint16_t m_HUFF_OFFSET_15 =497 + m_HUFF_OFFSET_13
 
const uint16_t m_HUFF_OFFSET_16 =580 + m_HUFF_OFFSET_15
 
const uint16_t m_HUFF_OFFSET_24 =651 + m_HUFF_OFFSET_16
 
const short bitsPerSlotTab [3] = { 32, 8, 8 }
 
const unsigned char uniqueIDTab [8] = {0x5f, 0x4b, 0x43, 0x5f, 0x5f, 0x4a, 0x52, 0x5f}
 

Typedef Documentation

◆ BitStreamInfo_t

◆ BlockCount_t

typedef struct BlockCount BlockCount_t

◆ DequantInfo_t

typedef struct DequantInfo DequantInfo_t

◆ FrameHeader_t

typedef struct FrameHeader FrameHeader_t

◆ HuffmanInfo_t

typedef struct HuffmanInfo HuffmanInfo_t

◆ HuffTabLookup_t

◆ HuffTabType_t

typedef enum HuffTabType HuffTabType_t

◆ IMDCTInfo_t

typedef struct IMDCTInfo IMDCTInfo_t

◆ MP3DecInfo_t

typedef struct MP3DecInfo MP3DecInfo_t

◆ MP3FrameInfo_t

typedef struct MP3FrameInfo MP3FrameInfo_t

◆ ScaleFactorInfoSub_t

◆ ScaleFactorJS_t

◆ SFBandTable_t

typedef struct SFBandTable SFBandTable_t

◆ SideInfo_t

typedef struct SideInfo SideInfo_t

◆ SideInfoSub_t

typedef struct SideInfoSub SideInfoSub_t

◆ SubbandInfo_t

typedef struct SubbandInfo SubbandInfo_t

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
ERR_MP3_NONE 
ERR_MP3_INDATA_UNDERFLOW 
ERR_MP3_MAINDATA_UNDERFLOW 
ERR_MP3_FREE_BITRATE_SYNC 
ERR_MP3_OUT_OF_MEMORY 
ERR_MP3_NULL_POINTER 
ERR_MP3_INVALID_FRAMEHEADER 
ERR_MP3_INVALID_SIDEINFO 
ERR_MP3_INVALID_SCALEFACT 
ERR_MP3_INVALID_HUFFCODES 
ERR_MP3_INVALID_DEQUANTIZE 
ERR_MP3_INVALID_IMDCT 
ERR_MP3_INVALID_SUBBAND 
ERR_UNKNOWN 

◆ HuffTabType

Enumerator
noBits 
oneShot 
loopNoLinbits 
loopLinbits 
quadA 
quadB 
invalidTab 

◆ MPEGVersion_t

Enumerator
MPEG1 
MPEG2 
MPEG25 

◆ StereoMode_t

Enumerator
Stereo 
Joint 
Dual 
Mono 

Function Documentation

◆ AntiAlias()

void AntiAlias ( int *  x,
int  nBfly 
)

◆ CalcBitsUsed()

int CalcBitsUsed ( BitStreamInfo_t bsi,
unsigned char *  startBuf,
int  startOffset 
)

◆ CheckPadBit()

int CheckPadBit ( )

◆ ClipToShort()

short ClipToShort ( int  x,
int  fracBits 
)

◆ CLZ()

int CLZ ( int  x)
inline

◆ DecodeHuffman()

int DecodeHuffman ( unsigned char *  buf,
int *  bitOffset,
int  huffBlockBits,
int  gr,
int  ch 
)

◆ DecodeHuffmanPairs()

int DecodeHuffmanPairs ( int *  xy,
int  nVals,
int  tabIdx,
int  bitsLeft,
unsigned char *  buf,
int  bitOffset 
)

◆ DecodeHuffmanQuads()

int DecodeHuffmanQuads ( int *  vwxy,
int  nVals,
int  tabIdx,
int  bitsLeft,
unsigned char *  buf,
int  bitOffset 
)

◆ DequantBlock()

int DequantBlock ( int *  inbuf,
int *  outbuf,
int  num,
int  scale 
)

◆ DequantChannel()

int DequantChannel ( int *  sampleBuf,
int *  workBuf,
int *  nonZeroBound,
SideInfoSub_t sis,
ScaleFactorInfoSub_t sfis,
CriticalBandInfo_t cbi 
)

◆ FASTABS()

int FASTABS ( int  x)
inline

◆ FDCT32()

void FDCT32 ( int *  x,
int *  d,
int  offset,
int  oddBlock,
int  gb 
)

◆ FreeBuffers()

void FreeBuffers ( )

◆ FreqInvertRescale()

int FreqInvertRescale ( int *  y,
int *  xPrev,
int  blockIdx,
int  es 
)

◆ GetBits()

unsigned int GetBits ( BitStreamInfo_t bsi,
int  nBits 
)

◆ HybridTransform()

int HybridTransform ( int *  xCurr,
int *  xPrev,
int  y[m_BLOCK_SIZE][m_NBANDS],
SideInfoSub_t sis,
BlockCount_t bc 
)

◆ idct9()

void idct9 ( int *  x)

◆ IMDCT()

int IMDCT ( int  gr,
int  ch 
)

◆ imdct12()

void imdct12 ( int *  x,
int *  out 
)

◆ IMDCT12x3()

int IMDCT12x3 ( int *  xCurr,
int *  xPrev,
int *  y,
int  btPrev,
int  blockIdx,
int  gb 
)

◆ IMDCT36()

int IMDCT36 ( int *  xCurr,
int *  xPrev,
int *  y,
int  btCurr,
int  btPrev,
int  blockIdx,
int  gb 
)

◆ IntensityProcMPEG1()

void IntensityProcMPEG1 ( int  x[m_MAX_NCHAN][m_MAX_NSAMP],
int  nSamps,
ScaleFactorInfoSub_t sfis,
CriticalBandInfo_t cbi,
int  midSideFlag,
int  mixFlag,
int  mOut[2] 
)

◆ IntensityProcMPEG2()

void IntensityProcMPEG2 ( int  x[m_MAX_NCHAN][m_MAX_NSAMP],
int  nSamps,
ScaleFactorInfoSub_t sfis,
CriticalBandInfo_t cbi,
ScaleFactorJS_t sfjs,
int  midSideFlag,
int  mixFlag,
int  mOut[2] 
)

◆ MADD64()

uint64_t MADD64 ( uint64_t  sum64,
int  x,
int  y 
)
inline

◆ MidSideProc()

void MidSideProc ( int  x[m_MAX_NCHAN][m_MAX_NSAMP],
int  nSamps,
int  mOut[2] 
)

◆ MP3ClearBadFrame()

void MP3ClearBadFrame ( short *  outbuf)

◆ MP3Decode()

int MP3Decode ( unsigned char *  inbuf,
int *  bytesLeft,
short *  outbuf,
int  useSize 
)

◆ MP3Decoder_AllocateBuffers()

bool MP3Decoder_AllocateBuffers ( void  )

◆ MP3Decoder_ClearBuffer()

void MP3Decoder_ClearBuffer ( void  )

◆ MP3Decoder_FreeBuffers()

void MP3Decoder_FreeBuffers ( )

◆ MP3Dequantize()

int MP3Dequantize ( int  gr)

◆ MP3FindFreeSync()

int MP3FindFreeSync ( unsigned char *  buf,
unsigned char  firstFH[4],
int  nBytes 
)

◆ MP3FindSyncWord()

int MP3FindSyncWord ( unsigned char *  buf,
int  nBytes 
)

◆ MP3GetBitrate()

int MP3GetBitrate ( )

◆ MP3GetBitsPerSample()

int MP3GetBitsPerSample ( )

◆ MP3GetChannels()

int MP3GetChannels ( )

◆ MP3GetDecodedSamps()

int MP3GetDecodedSamps ( )

◆ MP3GetLastFrameInfo()

void MP3GetLastFrameInfo ( )

◆ MP3GetNextFrameInfo()

int MP3GetNextFrameInfo ( unsigned char *  buf)

◆ MP3GetOutputSamps()

int MP3GetOutputSamps ( )

◆ MP3GetSampRate()

int MP3GetSampRate ( )

◆ MULSHIFT32()

int MULSHIFT32 ( int  x,
int  y 
)
inline

◆ PolyphaseMono()

void PolyphaseMono ( short *  pcm,
int *  vbuf,
const uint32_t *  coefBase 
)

◆ PolyphaseStereo()

void PolyphaseStereo ( short *  pcm,
int *  vbuf,
const uint32_t *  coefBase 
)

◆ RefillBitstreamCache()

void RefillBitstreamCache ( BitStreamInfo_t bsi)

◆ SAR64()

uint64_t SAR64 ( uint64_t  x,
int  n 
)
inline

◆ SetBitstreamPointer()

void SetBitstreamPointer ( BitStreamInfo_t bsi,
int  nBytes,
unsigned char *  buf 
)

◆ Subband()

int Subband ( short *  pcmBuf)

◆ UnpackFrameHeader()

int UnpackFrameHeader ( unsigned char *  buf)

◆ UnpackScaleFactors()

int UnpackScaleFactors ( unsigned char *  buf,
int *  bitOffset,
int  bitsAvail,
int  gr,
int  ch 
)

◆ UnpackSFMPEG1()

void UnpackSFMPEG1 ( BitStreamInfo_t bsi,
SideInfoSub_t sis,
ScaleFactorInfoSub_t sfis,
int *  scfsi,
int  gr,
ScaleFactorInfoSub_t sfisGr0 
)

◆ UnpackSFMPEG2()

void UnpackSFMPEG2 ( BitStreamInfo_t bsi,
SideInfoSub_t sis,
ScaleFactorInfoSub_t sfis,
int  gr,
int  ch,
int  modeExt,
ScaleFactorJS_t sfjs 
)

◆ UnpackSideInfo()

int UnpackSideInfo ( unsigned char *  buf)

◆ WinPrevious()

void WinPrevious ( int *  xPrev,
int *  xPrevWin,
int  btPrev 
)

◆ xSAR64()

uint64_t xSAR64 ( uint64_t  x,
int  n 
)
inline

Variable Documentation

◆ bitsPerSlotTab

const short bitsPerSlotTab[3] = { 32, 8, 8 }

◆ c18

const uint32_t c18[9] = { 0x7f834ed0, 0x7ba3751d, 0x7401e4c1, 0x68d9f964, 0x5a82799a, 0x496af3e2, 0x36185aee, 0x2120fb83, 0x0b27eb5c}

◆ c3_0

const int c3_0 = 0x6ed9eba1

◆ c6

const int c6[3] = { 0x7ba3751d, 0x5a82799a, 0x2120fb83 }

◆ c9_0

const int c9_0 = 0x6ed9eba1

◆ c9_1

const int c9_1 = 0x620dbe8b

◆ c9_2

const int c9_2 = 0x163a1a7e

◆ c9_3

const int c9_3 = 0x5246dd49

◆ c9_4

const int c9_4 = 0x7e0e2e32

◆ m_HUFF_OFFSET_01

const uint16_t m_HUFF_OFFSET_01 = 0

◆ m_HUFF_OFFSET_02

const uint16_t m_HUFF_OFFSET_02 = 9 + m_HUFF_OFFSET_01

◆ m_HUFF_OFFSET_03

const uint16_t m_HUFF_OFFSET_03 = 65 + m_HUFF_OFFSET_02

◆ m_HUFF_OFFSET_05

const uint16_t m_HUFF_OFFSET_05 = 65 + m_HUFF_OFFSET_03

◆ m_HUFF_OFFSET_06

const uint16_t m_HUFF_OFFSET_06 =257 + m_HUFF_OFFSET_05

◆ m_HUFF_OFFSET_07

const uint16_t m_HUFF_OFFSET_07 =129 + m_HUFF_OFFSET_06

◆ m_HUFF_OFFSET_08

const uint16_t m_HUFF_OFFSET_08 =110 + m_HUFF_OFFSET_07

◆ m_HUFF_OFFSET_09

const uint16_t m_HUFF_OFFSET_09 =280 + m_HUFF_OFFSET_08

◆ m_HUFF_OFFSET_10

const uint16_t m_HUFF_OFFSET_10 = 93 + m_HUFF_OFFSET_09

◆ m_HUFF_OFFSET_11

const uint16_t m_HUFF_OFFSET_11 =320 + m_HUFF_OFFSET_10

◆ m_HUFF_OFFSET_12

const uint16_t m_HUFF_OFFSET_12 =296 + m_HUFF_OFFSET_11

◆ m_HUFF_OFFSET_13

const uint16_t m_HUFF_OFFSET_13 =185 + m_HUFF_OFFSET_12

◆ m_HUFF_OFFSET_15

const uint16_t m_HUFF_OFFSET_15 =497 + m_HUFF_OFFSET_13

◆ m_HUFF_OFFSET_16

const uint16_t m_HUFF_OFFSET_16 =580 + m_HUFF_OFFSET_15

◆ m_HUFF_OFFSET_24

const uint16_t m_HUFF_OFFSET_24 =651 + m_HUFF_OFFSET_16

◆ m_SFLenTab

const char m_SFLenTab[16][2]
Initial value:
= { {0, 0}, {0, 1}, {0, 2}, {0, 3}, {3, 0}, {1, 1}, {1, 2}, {1, 3},
{2, 1}, {2, 2}, {2, 3}, {3, 1}, {3, 2}, {3, 3}, {4, 2}, {4, 3}}

◆ NRTab

const char NRTab[6][3][4]
Initial value:
= {
{{ 6, 5, 5, 5}, {3, 3, 3, 3}, {6, 3, 3, 3}},
{{ 6, 5, 7, 3}, {3, 3, 4, 2}, {6, 3, 4, 2}},
{{11, 10, 0, 0}, {6, 6, 0, 0}, {6, 3, 6, 0}},
{{ 7, 7, 7, 0}, {4, 4, 4, 0}, {6, 5, 4, 0}},
{{ 6, 6, 6, 3}, {4, 3, 3, 2}, {6, 4, 3, 2}},
{{ 8, 8, 5, 0}, {5, 4, 3, 0}, {6, 6, 3, 0}}
}

◆ preTab

const char preTab[22] = { 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0 }

◆ PROGMEM

static const ServoSequence SeqPanelLongHarlemShake PROGMEM
Initial value:
= {
0x7fffffff, 0x6ba27e65, 0x5a82799a, 0x4c1bf829
}

◆ uniqueIDTab

const unsigned char uniqueIDTab[8] = {0x5f, 0x4b, 0x43, 0x5f, 0x5f, 0x4a, 0x52, 0x5f}