coder.h
来自「An complete pmp solution for mattel juic」· C头文件 代码 · 共 308 行
H
308 行
/* ***** BEGIN LICENSE BLOCK *****
* Version: RCSL 1.0/RPSL 1.0
*
* Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
*
* The contents of this file, and the files included with this file, are
* subject to the current version of the RealNetworks Public Source License
* Version 1.0 (the "RPSL") available at
* http://www.helixcommunity.org/content/rpsl unless you have licensed
* the file under the RealNetworks Community Source License Version 1.0
* (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
* in which case the RCSL will apply. You may also obtain the license terms
* directly from RealNetworks. You may not use this file except in
* compliance with the RPSL or, if you have a valid RCSL with RealNetworks
* applicable to this file, the RCSL. Please see the applicable RPSL or
* RCSL for the rights, obligations and limitations governing use of the
* contents of the file.
*
* This file is part of the Helix DNA Technology. RealNetworks is the
* developer of the Original Code and owns the copyrights in the portions
* it created.
*
* This file, and the files included with this file, is distributed and made
* available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
* INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
* FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
*
* Technology Compatibility Kit Test Suite(s) Location:
* http://www.helixcommunity.org/content/tck
*
* Contributor(s):
*
* ***** END LICENSE BLOCK ***** */
/**************************************************************************************
* Fixed-point MP3 decoder
* Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com)
* June 2003
*
* coder.h - private, implementation-specific header file
**************************************************************************************/
#ifndef _CODER_H
#define _CODER_H
#include "mp3common.h"
#if defined(ASSERT)
#undef ASSERT
#endif
#if defined(_WIN32) && defined(_M_IX86) && (defined (_DEBUG) || defined (REL_ENABLE_ASSERTS))
#define ASSERT(x) if (!(x)) __asm i32 3;
#else
#define ASSERT(x) /* do nothing */
#endif
#ifndef MAX
#define MAX(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef MIN
#define MIN(a,b) ((a) < (b) ? (a) : (b))
#endif
/* clip to range [-2^n, 2^n - 1] */
#define CLIP_2N(y, n) { \
i32 sign = (y) >> 31; \
if (sign != (y) >> (n)) { \
(y) = sign ^ ((1 << (n)) - 1); \
} \
}
#define SIBYTES_MPEG1_MONO 17
#define SIBYTES_MPEG1_STEREO 32
#define SIBYTES_MPEG2_MONO 9
#define SIBYTES_MPEG2_STEREO 17
/* number of fraction bits for pow43Tab (see comments there) */
#define POW43_FRACBITS_LOW 22
#define POW43_FRACBITS_HIGH 12
#define DQ_FRACBITS_OUT 25 /* number of fraction bits in output of dequant */
#define IMDCT_SCALE 2 /* additional scaling (by sqrt(2)) for fast IMDCT36 */
#define HUFF_PAIRTABS 32
#define BLOCK_SIZE 18
#define NBANDS 32
#define MAX_REORDER_SAMPS ((192-126)*3) /* largest critical band for i16 blocks (see sfBandTable) */
#define VBUF_LENGTH (17 * 2 * NBANDS) /* for double-sized vbuf FIFO */
/* additional external symbols to name-mangle for static linking */
#define SetBitstreamPointer STATNAME(SetBitstreamPointer)
#define GetBits STATNAME(GetBits)
#define CalcBitsUsed STATNAME(CalcBitsUsed)
#define DequantChannel STATNAME(DequantChannel)
#define MidSideProc STATNAME(MidSideProc)
#define IntensityProcMPEG1 STATNAME(IntensityProcMPEG1)
#define IntensityProcMPEG2 STATNAME(IntensityProcMPEG2)
#define PolyphaseMono STATNAME(PolyphaseMono)
#define PolyphaseStereo STATNAME(PolyphaseStereo)
#define FDCT32 STATNAME(FDCT32)
#define ISFMpeg1 STATNAME(ISFMpeg1)
#define ISFMpeg2 STATNAME(ISFMpeg2)
#define ISFIIP STATNAME(ISFIIP)
#define uniqueIDTab STATNAME(uniqueIDTab)
#define coef32 STATNAME(coef32)
#define polyCoef STATNAME(polyCoef)
#define csa STATNAME(csa)
#define imdctWin STATNAME(imdctWin)
#define huffTable STATNAME(huffTable)
#define huffTabOffset STATNAME(huffTabOffset)
#define huffTabLookup STATNAME(huffTabLookup)
#define quadTable STATNAME(quadTable)
#define quadTabOffset STATNAME(quadTabOffset)
#define quadTabMaxBits STATNAME(quadTabMaxBits)
/* map these to the corresponding 2-bit values in the frame header */
typedef enum {
Stereo = 0x00, /* two independent channels, but L and R frames might have different # of bits */
Joint = 0x01, /* coupled channels - layer III: mix of M-S and intensity, Layers I/II: intensity and direct coding only */
Dual = 0x02, /* two independent channels, L and R always have exactly 1/2 the total bitrate */
Mono = 0x03 /* one channel */
} StereoMode;
typedef struct _BitStreamInfo {
u08 *bytePtr;
u32 iCache;
i32 cachedBits;
i32 nBytes;
} BitStreamInfo;
typedef struct _FrameHeader {
MPEGVersion ver; /* version ID */
i32 layer; /* layer index (1, 2, or 3) */
i32 crc; /* CRC flag: 0 = disabled, 1 = enabled */
i32 brIdx; /* bitrate index (0 - 15) */
i32 srIdx; /* sample rate index (0 - 2) */
i32 paddingBit; /* padding flag: 0 = no padding, 1 = single pad byte */
i32 privateBit; /* unused */
StereoMode sMode; /* mono/stereo mode */
i32 modeExt; /* used to decipher joint stereo mode */
i32 copyFlag; /* copyright flag: 0 = no, 1 = yes */
i32 origFlag; /* original flag: 0 = copy, 1 = original */
i32 emphasis; /* deemphasis mode */
i32 CRCWord; /* CRC word (16 bits, 0 if crc not enabled) */
const SFBandTable *sfBand;
} FrameHeader;
typedef struct _SideInfoSub {
i32 part23Length; /* number of bits in main data */
i32 nBigvals; /* 2x this = first set of Huffman cw's (maximum amplitude can be > 1) */
i32 globalGain; /* overall gain for dequantizer */
i32 sfCompress; /* unpacked to figure out number of bits in scale factors */
i32 winSwitchFlag; /* window switching flag */
i32 blockType; /* block type */
i32 mixedBlock; /* 0 = regular block (all i16 or long), 1 = mixed block */
i32 tableSelect[3]; /* index of Huffman tables for the big values regions */
i32 subBlockGain[3]; /* subblock gain offset, relative to global gain */
i32 region0Count; /* 1+region0Count = num scale factor bands in first region of bigvals */
i32 region1Count; /* 1+region1Count = num scale factor bands in second region of bigvals */
i32 preFlag; /* for optional high frequency boost */
i32 sfactScale; /* scaling of the scalefactors */
i32 count1TableSelect; /* index of Huffman table for quad codewords */
} SideInfoSub;
typedef struct _SideInfo {
i32 mainDataBegin;
i32 privateBits;
i32 scfsi[MAX_NCHAN][MAX_SCFBD]; /* 4 scalefactor bands per channel */
SideInfoSub sis[MAX_NGRAN][MAX_NCHAN];
} SideInfo;
typedef struct {
i32 cbType; /* pure long = 0, pure i16 = 1, mixed = 2 */
i32 cbEndS[3]; /* number nonzero i16 cb's, per subbblock */
i32 cbEndSMax; /* max of cbEndS[] */
i32 cbEndL; /* number nonzero long cb's */
} CriticalBandInfo;
typedef struct _DequantInfo {
i32 workBuf[MAX_REORDER_SAMPS]; /* workbuf for reordering i16 blocks */
CriticalBandInfo cbi[MAX_NCHAN]; /* filled in dequantizer, used in joint stereo reconstruction */
} DequantInfo;
typedef struct _HuffmanInfo {
i32 huffDecBuf[MAX_NCHAN][MAX_NSAMP]; /* used both for decoded Huffman values and dequantized coefficients */
i32 nonZeroBound[MAX_NCHAN]; /* number of coeffs in huffDecBuf[ch] which can be > 0 */
i32 gb[MAX_NCHAN]; /* minimum number of guard bits in huffDecBuf[ch] */
} HuffmanInfo;
typedef enum _HuffTabType {
noBits,
oneShot,
loopNoLinbits,
loopLinbits,
quadA,
quadB,
invalidTab
} HuffTabType;
typedef struct _HuffTabLookup {
i32 linBits;
HuffTabType tabType;
} HuffTabLookup;
typedef struct _IMDCTInfo {
i32 outBuf[MAX_NCHAN][BLOCK_SIZE][NBANDS]; /* output of IMDCT */
i32 overBuf[MAX_NCHAN][MAX_NSAMP / 2]; /* overlap-add buffer (by symmetry, only need 1/2 size) */
i32 numPrevIMDCT[MAX_NCHAN]; /* how many IMDCT's calculated in this channel on prev. granule */
i32 prevType[MAX_NCHAN];
i32 prevWinSwitch[MAX_NCHAN];
i32 gb[MAX_NCHAN];
} IMDCTInfo;
typedef struct _BlockCount {
i32 nBlocksLong;
i32 nBlocksTotal;
i32 nBlocksPrev;
i32 prevType;
i32 prevWinSwitch;
i32 currWinSwitch;
i32 gbIn;
i32 gbOut;
} BlockCount;
/* max bits in scalefactors = 5, so use char's to save space */
typedef struct _ScaleFactorInfoSub {
char l[23]; /* [band] */
char s[13][3]; /* [band][window] */
} ScaleFactorInfoSub;
/* used in MPEG 2, 2.5 intensity (joint) stereo only */
typedef struct _ScaleFactorJS {
i32 intensityScale;
i32 slen[4];
i32 nr[4];
} ScaleFactorJS;
typedef struct _ScaleFactorInfo {
ScaleFactorInfoSub sfis[MAX_NGRAN][MAX_NCHAN];
ScaleFactorJS sfjs;
} ScaleFactorInfo;
/* NOTE - could get by with smaller vbuf if memory is more important than speed
* (in Subband, instead of replicating each block in FDCT32 you would do a memmove on the
* last 15 blocks to shift them down one, a hardware style FIFO)
*/
typedef struct _SubbandInfo {
i32 vbuf[MAX_NCHAN * VBUF_LENGTH]; /* vbuf for fast DCT-based synthesis PQMF - double size for speed (no modulo indexing) */
i32 vindex; /* internal index for tracking position in vbuf */
} SubbandInfo;
/* bitstream.c */
void SetBitstreamPointer(BitStreamInfo *bsi, i32 nBytes, u08 *buf);
u32 GetBits(BitStreamInfo *bsi, i32 nBits);
i32 CalcBitsUsed(BitStreamInfo *bsi, u08 *startBuf, i32 startOffset);
/* dequant.c, dqchan.c, stproc.c */
i32 DequantChannel(i32 *sampleBuf, i32 *workBuf, i32 *nonZeroBound, FrameHeader *fh, SideInfoSub *sis,
ScaleFactorInfoSub *sfis, CriticalBandInfo *cbi);
void MidSideProc(i32 x[MAX_NCHAN][MAX_NSAMP], i32 nSamps, i32 mOut[2]);
void IntensityProcMPEG1(i32 x[MAX_NCHAN][MAX_NSAMP], i32 nSamps, FrameHeader *fh, ScaleFactorInfoSub *sfis,
CriticalBandInfo *cbi, i32 midSideFlag, i32 mixFlag, i32 mOut[2]);
void IntensityProcMPEG2(i32 x[MAX_NCHAN][MAX_NSAMP], i32 nSamps, FrameHeader *fh, ScaleFactorInfoSub *sfis,
CriticalBandInfo *cbi, ScaleFactorJS *sfjs, i32 midSideFlag, i32 mixFlag, i32 mOut[2]);
/* dct32.c */
// about 1 ms faster in RAM, but very large
void FDCT32(i32 *x, i32 *d, i32 offset, i32 oddBlock, i32 gb);// __attribute__ ((section (".data")));
/* hufftabs.c */
extern const HuffTabLookup huffTabLookup[HUFF_PAIRTABS];
extern const i32 huffTabOffset[HUFF_PAIRTABS];
extern const u16 huffTable[];
extern const u08 quadTable[64+16];
extern const i32 quadTabOffset[2];
extern const i32 quadTabMaxBits[2];
/* polyphase.c (or asmpoly.s)
* some platforms require a C++ compile of all source files,
* so if we're compiling C as C++ and using native assembly
* for these functions we need to prevent C++ name mangling.
*/
#ifdef __cplusplus
extern "C" {
#endif
void PolyphaseMono(i16 *pcm, i32 *vbuf, const i32 *coefBase);
void PolyphaseStereo(i16 *pcm, i32 *vbuf, const i32 *coefBase);
#ifdef __cplusplus
}
#endif
/* trigtabs.c */
extern const i32 imdctWin[4][36];
extern const i32 ISFMpeg1[2][7];
extern const i32 ISFMpeg2[2][2][16];
extern const i32 ISFIIP[2][2];
extern const i32 csa[8][2];
extern const i32 coef32[31];
extern const i32 polyCoef[264];
#endif /* _CODER_H */
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?