CI13LC SDK API手册  2.1.1
本手册用于描述CI13LC SDK各个组件和驱动API
mp3coder.h
浏览该文件的文档.
1 /* ***** BEGIN LICENSE BLOCK *****
2  * Version: RCSL 1.0/RPSL 1.0
3  *
4  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved.
5  *
6  * The contents of this file, and the files included with this file, are
7  * subject to the current version of the RealNetworks Public Source License
8  * Version 1.0 (the "RPSL") available at
9  * http://www.helixcommunity.org/content/rpsl unless you have licensed
10  * the file under the RealNetworks Community Source License Version 1.0
11  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl,
12  * in which case the RCSL will apply. You may also obtain the license terms
13  * directly from RealNetworks. You may not use this file except in
14  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks
15  * applicable to this file, the RCSL. Please see the applicable RPSL or
16  * RCSL for the rights, obligations and limitations governing use of the
17  * contents of the file.
18  *
19  * This file is part of the Helix DNA Technology. RealNetworks is the
20  * developer of the Original Code and owns the copyrights in the portions
21  * it created.
22  *
23  * This file, and the files included with this file, is distributed and made
24  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
25  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES,
26  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS
27  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
28  *
29  * Technology Compatibility Kit Test Suite(s) Location:
30  * http://www.helixcommunity.org/content/tck
31  *
32  * Contributor(s):
33  *
34  * ***** END LICENSE BLOCK ***** */
35 
36 /**************************************************************************************
37  * Fixed-point MP3 decoder
38  * Jon Recker (jrecker@real.com), Ken Cooke (kenc@real.com)
39  * June 2003
40  *
41  * mp3coder.h - private, implementation-specific header file
42  **************************************************************************************/
43 
44 #ifndef _CODER_H
45 #define _CODER_H
46 
47 #include "mp3common.h"
48 
49 #if defined(ASSERT)
50 #undef ASSERT
51 #endif
52 #if defined(_WIN32) && defined(_M_IX86) && (defined (_DEBUG) || defined (REL_ENABLE_ASSERTS))
53 #define ASSERT(x) if (!(x)) __asm int 3;
54 #else
55 #define ASSERT(x) /* do nothing */
56 #endif
57 
58 #ifndef MAX
59 #define MAX(a,b) ((a) > (b) ? (a) : (b))
60 #endif
61 
62 #ifndef MIN
63 #define MIN(a,b) ((a) < (b) ? (a) : (b))
64 #endif
65 
66 /* clip to range [-2^n, 2^n - 1] */
67 #define CLIP_2N(y, n) { \
68  int sign = (y) >> 31; \
69  if (sign != (y) >> (n)) { \
70  (y) = sign ^ ((1 << (n)) - 1); \
71  } \
72 }
73 
74 #define SIBYTES_MPEG1_MONO 17
75 #define SIBYTES_MPEG1_STEREO 32
76 #define SIBYTES_MPEG2_MONO 9
77 #define SIBYTES_MPEG2_STEREO 17
78 
79 /* number of fraction bits for pow43Tab (see comments there) */
80 #define POW43_FRACBITS_LOW 22
81 #define POW43_FRACBITS_HIGH 12
82 
83 #define DQ_FRACBITS_OUT 25 /* number of fraction bits in output of dequant */
84 #define IMDCT_SCALE 2 /* additional scaling (by sqrt(2)) for fast IMDCT36 */
85 
86 #define HUFF_PAIRTABS 32
87 #define BLOCK_SIZE 18
88 #define NBANDS 32
89 #define MAX_REORDER_SAMPS ((192-126)*3) /* largest critical band for short blocks (see sfBandTable) */
90 #define VBUF_LENGTH (17 * 2 * NBANDS) /* for double-sized vbuf FIFO */
91 
92 /* additional external symbols to name-mangle for static linking */
93 #define SetBitstreamPointer STATNAME(SetBitstreamPointer)
94 #define GetBits STATNAME(GetBits)
95 #define CalcBitsUsed STATNAME(CalcBitsUsed)
96 #define DequantChannel STATNAME(DequantChannel)
97 #define MidSideProc STATNAME(MidSideProc)
98 #define IntensityProcMPEG1 STATNAME(IntensityProcMPEG1)
99 #define IntensityProcMPEG2 STATNAME(IntensityProcMPEG2)
100 //#define PolyphaseMono STATNAME(PolyphaseMono)
101 //#define PolyphaseStereo STATNAME(PolyphaseStereo)
102 #define FDCT32 STATNAME(FDCT32)
103 
104 #define ISFMpeg1 STATNAME(ISFMpeg1)
105 #define ISFMpeg2 STATNAME(ISFMpeg2)
106 #define ISFIIP STATNAME(ISFIIP)
107 #define uniqueIDTab STATNAME(uniqueIDTab)
108 #define coef32 STATNAME(coef32)
109 #define polyCoef STATNAME(polyCoef)
110 #define csa STATNAME(csa)
111 #define imdctWin STATNAME(imdctWin)
112 
113 #define huffTable_0 STATNAME(huffTable_0)
114 #define huffTable_1 STATNAME(huffTable_1)
115 #define huffTable_2 STATNAME(huffTable_2)
116 #define huffTabOffset STATNAME(huffTabOffset)
117 #define huffTabLookup STATNAME(huffTabLookup)
118 #define quadTable STATNAME(quadTable)
119 #define quadTabOffset STATNAME(quadTabOffset)
120 #define quadTabMaxBits STATNAME(quadTabMaxBits)
121 
122 /* map these to the corresponding 2-bit values in the frame header */
123 typedef enum {
124  Stereo = 0x00, /* two independent channels, but L and R frames might have different # of bits */
125  Joint = 0x01, /* coupled channels - layer III: mix of M-S and intensity, Layers I/II: intensity and direct coding only */
126  Dual = 0x02, /* two independent channels, L and R always have exactly 1/2 the total bitrate */
127  Mono = 0x03 /* one channel */
128 } StereoMode;
129 
130 typedef struct _BitStreamInfo {
131  unsigned char *bytePtr;
132  unsigned int iCache;
134  int nBytes;
135 } BitStreamInfo;
136 
137 typedef struct _FrameHeader {
138  MPEGVersion ver; /* version ID */
139  int layer; /* layer index (1, 2, or 3) */
140  int crc; /* CRC flag: 0 = disabled, 1 = enabled */
141  int brIdx; /* bitrate index (0 - 15) */
142  int srIdx; /* sample rate index (0 - 2) */
143  int paddingBit; /* padding flag: 0 = no padding, 1 = single pad byte */
144  int privateBit; /* unused */
145  StereoMode sMode; /* mono/stereo mode */
146  int modeExt; /* used to decipher joint stereo mode */
147  int copyFlag; /* copyright flag: 0 = no, 1 = yes */
148  int origFlag; /* original flag: 0 = copy, 1 = original */
149  int emphasis; /* deemphasis mode */
150  int CRCWord; /* CRC word (16 bits, 0 if crc not enabled) */
151 
153 } FrameHeader;
154 
155 typedef struct _SideInfoSub {
156  int part23Length; /* number of bits in main data */
157  int nBigvals; /* 2x this = first set of Huffman cw's (maximum amplitude can be > 1) */
158  int globalGain; /* overall gain for dequantizer */
159  int sfCompress; /* unpacked to figure out number of bits in scale factors */
160  int winSwitchFlag; /* window switching flag */
161  int blockType; /* block type */
162  int mixedBlock; /* 0 = regular block (all short or long), 1 = mixed block */
163  int tableSelect[3]; /* index of Huffman tables for the big values regions */
164  int subBlockGain[3]; /* subblock gain offset, relative to global gain */
165  int region0Count; /* 1+region0Count = num scale factor bands in first region of bigvals */
166  int region1Count; /* 1+region1Count = num scale factor bands in second region of bigvals */
167  int preFlag; /* for optional high frequency boost */
168  int sfactScale; /* scaling of the scalefactors */
169  int count1TableSelect; /* index of Huffman table for quad codewords */
170 } SideInfoSub;
171 
172 typedef struct _SideInfo {
175  int scfsi[MAX_NCHAN][MAX_SCFBD]; /* 4 scalefactor bands per channel */
176 
178 } SideInfo;
179 
180 typedef struct {
181  int cbType; /* pure long = 0, pure short = 1, mixed = 2 */
182  int cbEndS[3]; /* number nonzero short cb's, per subbblock */
183  int cbEndSMax; /* max of cbEndS[] */
184  int cbEndL; /* number nonzero long cb's */
186 
187 typedef struct _DequantInfo {
188  int workBuf[MAX_REORDER_SAMPS]; /* workbuf for reordering short blocks */
189  CriticalBandInfo cbi[MAX_NCHAN]; /* filled in dequantizer, used in joint stereo reconstruction */
190 } DequantInfo;
191 
192 typedef struct _HuffmanInfo {
193  int huffDecBuf[MAX_NCHAN][MAX_NSAMP]; /* used both for decoded Huffman values and dequantized coefficients */
194  int nonZeroBound[MAX_NCHAN]; /* number of coeffs in huffDecBuf[ch] which can be > 0 */
195  int gb[MAX_NCHAN]; /* minimum number of guard bits in huffDecBuf[ch] */
196 } HuffmanInfo;
197 
198 typedef enum _HuffTabType {
206 } HuffTabType;
207 
208 typedef struct _HuffTabLookup {
209  int linBits;
211 } HuffTabLookup;
212 
213 typedef struct _IMDCTInfo {
214  int outBuf[MAX_NCHAN][BLOCK_SIZE][NBANDS]; /* output of IMDCT */
215  int overBuf[MAX_NCHAN][MAX_NSAMP / 2]; /* overlap-add buffer (by symmetry, only need 1/2 size) */
216  int numPrevIMDCT[MAX_NCHAN]; /* how many IMDCT's calculated in this channel on prev. granule */
219  int gb[MAX_NCHAN];
220 } IMDCTInfo;
221 
222 typedef struct _BlockCount {
226  int prevType;
229  int gbIn;
230  int gbOut;
231 } BlockCount;
232 
233 /* max bits in scalefactors = 5, so use char's to save space */
234 typedef struct _ScaleFactorInfoSub {
235  char l[23]; /* [band] */
236  char s[13][3]; /* [band][window] */
238 
239 /* used in MPEG 2, 2.5 intensity (joint) stereo only */
240 typedef struct _ScaleFactorJS {
242  int slen[4];
243  int nr[4];
244 } ScaleFactorJS;
245 
246 typedef struct _ScaleFactorInfo {
250 
251 /* NOTE - could get by with smaller vbuf if memory is more important than speed
252  * (in Subband, instead of replicating each block in FDCT32 you would do a memmove on the
253  * last 15 blocks to shift them down one, a hardware style FIFO)
254  */
255 typedef struct _SubbandInfo {
256  int vbuf[MAX_NCHAN * VBUF_LENGTH]; /* vbuf for fast DCT-based synthesis PQMF - double size for speed (no modulo indexing) */
257  int vindex; /* internal index for tracking position in vbuf */
258 } SubbandInfo;
259 
260 /* mp3bitstream.c */
261 void SetBitstreamPointer(BitStreamInfo *bsi, int nBytes, unsigned char *buf);
262 unsigned int GetBits(BitStreamInfo *bsi, int nBits);
263 int CalcBitsUsed(BitStreamInfo *bsi, unsigned char *startBuf, int startOffset);
264 
265 /* mp3dequant.c, mp3dqchan.c, mp3stproc.c */
266 int DequantChannel(int *sampleBuf, int *workBuf, int *nonZeroBound, FrameHeader *fh, SideInfoSub *sis,
268 void MidSideProc(int x[MAX_NCHAN][MAX_NSAMP], int nSamps, int mOut[2]);
269 void IntensityProcMPEG1(int x[MAX_NCHAN][MAX_NSAMP], int nSamps, FrameHeader *fh, ScaleFactorInfoSub *sfis,
270  CriticalBandInfo *cbi, int midSideFlag, int mixFlag, int mOut[2]);
271 void IntensityProcMPEG2(int x[MAX_NCHAN][MAX_NSAMP], int nSamps, FrameHeader *fh, ScaleFactorInfoSub *sfis,
272  CriticalBandInfo *cbi, ScaleFactorJS *sfjs, int midSideFlag, int mixFlag, int mOut[2]);
273 
274 /* mp3dct32.c */
275 void FDCT32(int *x, int *d, int offset, int oddBlock, int gb);
276 
277 #ifdef USE_OUTSIDE_MP3_TABLE
278 /* mp3hufftabs.c */
280 extern int * huffTabOffset;
281 extern unsigned short * huffTable_0;
282 extern unsigned short * huffTable_1;
283 extern unsigned short * huffTable_2;
284 extern unsigned char * quadTable;
285 extern int * quadTabOffset;
286 extern int * quadTabMaxBits;
287 #else
288 /* mp3hufftabs.c */
290 extern const int huffTabOffset[HUFF_PAIRTABS];
291 extern const unsigned short huffTable_0[];
292 extern const unsigned short huffTable_1[];
293 extern const unsigned short huffTable_2[];
294 extern const unsigned char quadTable[64+16];
295 extern const int quadTabOffset[2];
296 extern const int quadTabMaxBits[2];
297 #endif /* USE_OUTSIDE_MP3_TABLE */
298 
299 /* mp3polyphase.c (or asmpoly.s)
300  * some platforms require a C++ compile of all source files,
301  * so if we're compiling C as C++ and using native assembly
302  * for these functions we need to prevent C++ name mangling.
303  */
304 #ifdef __cplusplus
305 extern "C" {
306 #endif
307 void PolyphaseMono(short *pcm, int *vbuf, const int *coefBase);
308 void PolyphaseStereo(short *pcm, int *vbuf, const int *coefBase);
309 #ifdef __cplusplus
310 }
311 #endif
312 
313 #ifdef USE_OUTSIDE_MP3_TABLE
314 /* mp3trigtabs.c */
315 extern int (* imdctWin)[36];
316 extern int (* ISFMpeg1)[7];
317 extern int (* ISFMpeg2)[2][16];
318 extern int (* ISFIIP)[2];
319 extern unsigned char * uniqueIDTab;
320 extern int (* csa)[2];
321 extern int * coef32;
322 extern int * polyCoef;
323 #else
324 /* mp3trigtabs.c */
325 extern const int imdctWin[4][36];
326 extern const int ISFMpeg1[2][7];
327 extern const int ISFMpeg2[2][2][16];
328 extern const int ISFIIP[2][2];
329 extern const int csa[8][2];
330 extern const int coef32[31];
331 extern const int polyCoef[264];
332 #endif /* USE_OUTSIDE_MP3_TABLE */
333 
334 #endif /* _CODER_H */
int linBits
Definition: mp3coder.h:209
#define CalcBitsUsed
Definition: mp3coder.h:95
#define MidSideProc
Definition: mp3coder.h:97
int nBytes
Definition: mp3coder.h:134
int vindex
Definition: mp3coder.h:257
Definition: mp3coder.h:255
Definition: mp3coder.h:222
int huffDecBuf[MAX_NCHAN][MAX_NSAMP]
Definition: mp3coder.h:193
struct _ScaleFactorInfo ScaleFactorInfo
StereoMode
Definition: mp3coder.h:123
int numPrevIMDCT[MAX_NCHAN]
Definition: mp3coder.h:216
#define uniqueIDTab
Definition: mp3coder.h:107
Definition: mp3coder.h:240
Definition: mp3coder.h:155
#define huffTable_2
Definition: mp3coder.h:115
struct _SideInfoSub SideInfoSub
#define imdctWin
Definition: mp3coder.h:111
ScaleFactorJS sfjs
Definition: mp3coder.h:248
int gb[MAX_NCHAN]
Definition: mp3coder.h:195
Definition: mp3coder.h:201
Definition: mp3coder.h:127
int nBigvals
Definition: mp3coder.h:157
#define HUFF_PAIRTABS
Definition: mp3coder.h:86
int layer
Definition: mp3coder.h:139
int vbuf[MAX_NCHAN *(17 *2 *32)]
Definition: mp3coder.h:256
Definition: mp3coder.h:137
int cbEndL
Definition: mp3coder.h:184
Definition: mp3coder.h:180
int preFlag
Definition: mp3coder.h:167
Definition: mp3coder.h:204
int overBuf[MAX_NCHAN][MAX_NSAMP/2]
Definition: mp3coder.h:215
#define NBANDS
Definition: mp3coder.h:88
int prevType[MAX_NCHAN]
Definition: mp3coder.h:217
Definition: mp3coder.h:192
#define huffTable_0
Definition: mp3coder.h:113
Definition: mp3coder.h:213
int winSwitchFlag
Definition: mp3coder.h:160
struct _ScaleFactorInfoSub ScaleFactorInfoSub
HuffTabType tabType
Definition: mp3coder.h:210
void PolyphaseStereo(short *pcm, int *vbuf, const int *coefBase)
Definition: mp3polyphase.c:227
int currWinSwitch
Definition: mp3coder.h:228
StereoMode sMode
Definition: mp3coder.h:145
ScaleFactorInfoSub sfis[MAX_NGRAN][MAX_NCHAN]
Definition: mp3coder.h:247
int brIdx
Definition: mp3coder.h:141
#define polyCoef
Definition: mp3coder.h:109
int mixedBlock
Definition: mp3coder.h:162
int region1Count
Definition: mp3coder.h:166
int part23Length
Definition: mp3coder.h:156
int nr[4]
Definition: mp3coder.h:243
struct _HuffmanInfo HuffmanInfo
int sfactScale
Definition: mp3coder.h:168
int prevWinSwitch
Definition: mp3coder.h:227
struct _SubbandInfo SubbandInfo
int count1TableSelect
Definition: mp3coder.h:169
#define MAX_SCFBD
Definition: mp3common.h:51
#define MAX_NSAMP
Definition: mp3dec.h:74
unsigned char * bytePtr
Definition: mp3coder.h:131
MPEGVersion ver
Definition: mp3coder.h:138
#define csa
Definition: mp3coder.h:110
Definition: mp3coder.h:172
#define ISFIIP
Definition: mp3coder.h:106
int nBlocksTotal
Definition: mp3coder.h:224
int nonZeroBound[MAX_NCHAN]
Definition: mp3coder.h:194
char s[13][3]
Definition: mp3coder.h:236
unsigned int iCache
Definition: mp3coder.h:132
#define quadTabMaxBits
Definition: mp3coder.h:120
Definition: mp3coder.h:125
const SFBandTable * sfBand
Definition: mp3coder.h:152
#define VBUF_LENGTH
Definition: mp3coder.h:90
Definition: mp3coder.h:124
int globalGain
Definition: mp3coder.h:158
int CRCWord
Definition: mp3coder.h:150
void PolyphaseMono(short *pcm, int *vbuf, const int *coefBase)
Definition: mp3polyphase.c:114
CriticalBandInfo cbi[MAX_NCHAN]
Definition: mp3coder.h:189
uint32_t offset
Definition: flash_update.c:82
#define quadTable
Definition: mp3coder.h:118
Definition: mp3coder.h:187
int copyFlag
Definition: mp3coder.h:147
int cbEndSMax
Definition: mp3coder.h:183
int nBlocksLong
Definition: mp3coder.h:223
Definition: mp3coder.h:199
Definition: mp3coder.h:246
int prevWinSwitch[MAX_NCHAN]
Definition: mp3coder.h:218
int nBlocksPrev
Definition: mp3coder.h:225
enum _HuffTabType HuffTabType
#define FDCT32
Definition: mp3coder.h:102
Definition: mp3coder.h:205
#define IntensityProcMPEG1
Definition: mp3coder.h:98
Definition: mp3coder.h:208
char l[23]
Definition: mp3coder.h:235
#define huffTable_1
Definition: mp3coder.h:114
#define huffTabOffset
Definition: mp3coder.h:116
int origFlag
Definition: mp3coder.h:148
MPEGVersion
Definition: mp3dec.h:77
Definition: mp3coder.h:200
#define MAX_REORDER_SAMPS
Definition: mp3coder.h:89
int prevType
Definition: mp3coder.h:226
Definition: mp3coder.h:202
#define ISFMpeg2
Definition: mp3coder.h:105
#define BLOCK_SIZE
Definition: mp3coder.h:87
int gbIn
Definition: mp3coder.h:229
SideInfoSub sis[MAX_NGRAN][MAX_NCHAN]
Definition: mp3coder.h:177
#define DequantChannel
Definition: mp3coder.h:96
int srIdx
Definition: mp3coder.h:142
int privateBit
Definition: mp3coder.h:144
int workBuf[((192-126) *3)]
Definition: mp3coder.h:188
#define huffTabLookup
Definition: mp3coder.h:117
#define coef32
Definition: mp3coder.h:108
struct _BitStreamInfo BitStreamInfo
int gbOut
Definition: mp3coder.h:230
int region0Count
Definition: mp3coder.h:165
struct _ScaleFactorJS ScaleFactorJS
#define MAX_NCHAN
Definition: mp3dec.h:73
#define GetBits
Definition: mp3coder.h:94
int emphasis
Definition: mp3coder.h:149
Definition: mp3coder.h:234
int crc
Definition: mp3coder.h:140
struct _SideInfo SideInfo
struct _IMDCTInfo IMDCTInfo
struct _DequantInfo DequantInfo
int paddingBit
Definition: mp3coder.h:143
int cbType
Definition: mp3coder.h:181
#define SetBitstreamPointer
Definition: mp3coder.h:93
#define ISFMpeg1
Definition: mp3coder.h:104
Definition: mp3coder.h:126
Definition: mp3common.h:98
int outBuf[MAX_NCHAN][18][32]
Definition: mp3coder.h:214
int tableSelect[3]
Definition: mp3coder.h:163
#define MAX_NGRAN
Definition: mp3dec.h:72
int cachedBits
Definition: mp3coder.h:133
int subBlockGain[3]
Definition: mp3coder.h:164
Definition: mp3coder.h:130
Definition: mp3coder.h:203
int mainDataBegin
Definition: mp3coder.h:173
int blockType
Definition: mp3coder.h:161
int privateBits
Definition: mp3coder.h:174
struct _BlockCount BlockCount
int intensityScale
Definition: mp3coder.h:241
struct _FrameHeader FrameHeader
#define quadTabOffset
Definition: mp3coder.h:119
int modeExt
Definition: mp3coder.h:146
int sfCompress
Definition: mp3coder.h:159
#define IntensityProcMPEG2
Definition: mp3coder.h:99
_HuffTabType
Definition: mp3coder.h:198
struct _HuffTabLookup HuffTabLookup
int slen[4]
Definition: mp3coder.h:242
int scfsi[MAX_NCHAN][MAX_SCFBD]
Definition: mp3coder.h:175