OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
coder.h
Go to the documentation of this file.
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 * coder.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 STATNAME(huffTable)
114#define huffTabOffset STATNAME(huffTabOffset)
115#define huffTabLookup STATNAME(huffTabLookup)
116#define quadTable STATNAME(quadTable)
117#define quadTabOffset STATNAME(quadTabOffset)
118#define quadTabMaxBits STATNAME(quadTabMaxBits)
119
120/* map these to the corresponding 2-bit values in the frame header */
121typedef enum {
122 Stereo = 0x00, /* two independent channels, but L and R frames might have different # of bits */
123 Joint = 0x01, /* coupled channels - layer III: mix of M-S and intensity, Layers I/II: intensity and direct coding only */
124 Dual = 0x02, /* two independent channels, L and R always have exactly 1/2 the total bitrate */
125 Mono = 0x03 /* one channel */
127
128typedef struct _BitStreamInfo {
129 unsigned char *bytePtr;
130 unsigned int iCache;
134
135typedef struct _FrameHeader {
136 MPEGVersion ver; /* version ID */
137 int layer; /* layer index (1, 2, or 3) */
138 int crc; /* CRC flag: 0 = disabled, 1 = enabled */
139 int brIdx; /* bitrate index (0 - 15) */
140 int srIdx; /* sample rate index (0 - 2) */
141 int paddingBit; /* padding flag: 0 = no padding, 1 = single pad byte */
142 int privateBit; /* unused */
143 StereoMode sMode; /* mono/stereo mode */
144 int modeExt; /* used to decipher joint stereo mode */
145 int copyFlag; /* copyright flag: 0 = no, 1 = yes */
146 int origFlag; /* original flag: 0 = copy, 1 = original */
147 int emphasis; /* deemphasis mode */
148 int CRCWord; /* CRC word (16 bits, 0 if crc not enabled) */
149
152
153typedef struct _SideInfoSub {
154 int part23Length; /* number of bits in main data */
155 int nBigvals; /* 2x this = first set of Huffman cw's (maximum amplitude can be > 1) */
156 int globalGain; /* overall gain for dequantizer */
157 int sfCompress; /* unpacked to figure out number of bits in scale factors */
158 int winSwitchFlag; /* window switching flag */
159 int blockType; /* block type */
160 int mixedBlock; /* 0 = regular block (all short or long), 1 = mixed block */
161 int tableSelect[3]; /* index of Huffman tables for the big values regions */
162 int subBlockGain[3]; /* subblock gain offset, relative to global gain */
163 int region0Count; /* 1+region0Count = num scale factor bands in first region of bigvals */
164 int region1Count; /* 1+region1Count = num scale factor bands in second region of bigvals */
165 int preFlag; /* for optional high frequency boost */
166 int sfactScale; /* scaling of the scalefactors */
167 int count1TableSelect; /* index of Huffman table for quad codewords */
169
170typedef struct _SideInfo {
173 int scfsi[MAX_NCHAN][MAX_SCFBD]; /* 4 scalefactor bands per channel */
174
177
178typedef struct {
179 int cbType; /* pure long = 0, pure short = 1, mixed = 2 */
180 int cbEndS[3]; /* number nonzero short cb's, per subbblock */
181 int cbEndSMax; /* max of cbEndS[] */
182 int cbEndL; /* number nonzero long cb's */
184
185typedef struct _DequantInfo {
186 int workBuf[MAX_REORDER_SAMPS]; /* workbuf for reordering short blocks */
187 CriticalBandInfo cbi[MAX_NCHAN]; /* filled in dequantizer, used in joint stereo reconstruction */
189
190typedef struct _HuffmanInfo {
191 int huffDecBuf[MAX_NCHAN][MAX_NSAMP]; /* used both for decoded Huffman values and dequantized coefficients */
192 int nonZeroBound[MAX_NCHAN]; /* number of coeffs in huffDecBuf[ch] which can be > 0 */
193 int gb[MAX_NCHAN]; /* minimum number of guard bits in huffDecBuf[ch] */
195
205
210
211typedef struct _IMDCTInfo {
212 int outBuf[MAX_NCHAN][BLOCK_SIZE][NBANDS]; /* output of IMDCT */
213 int overBuf[MAX_NCHAN][MAX_NSAMP / 2]; /* overlap-add buffer (by symmetry, only need 1/2 size) */
214 int numPrevIMDCT[MAX_NCHAN]; /* how many IMDCT's calculated in this channel on prev. granule */
219
230
231/* max bits in scalefactors = 5, so use char's to save space */
232typedef struct _ScaleFactorInfoSub {
233 char l[23]; /* [band] */
234 char s[13][3]; /* [band][window] */
236
237/* used in MPEG 2, 2.5 intensity (joint) stereo only */
238typedef struct _ScaleFactorJS {
240 int slen[4];
241 int nr[4];
243
248
249/* NOTE - could get by with smaller vbuf if memory is more important than speed
250 * (in Subband, instead of replicating each block in FDCT32 you would do a memmove on the
251 * last 15 blocks to shift them down one, a hardware style FIFO)
252 */
253typedef struct _SubbandInfo {
254 int vbuf[MAX_NCHAN * VBUF_LENGTH]; /* vbuf for fast DCT-based synthesis PQMF - double size for speed (no modulo indexing) */
255 int vindex; /* internal index for tracking position in vbuf */
257
258/* bitstream.c */
259void SetBitstreamPointer(BitStreamInfo *bsi, int nBytes, unsigned char *buf);
260unsigned int GetBits(BitStreamInfo *bsi, int nBits);
261int CalcBitsUsed(BitStreamInfo *bsi, unsigned char *startBuf, int startOffset);
262
263/* dequant.c, dqchan.c, stproc.c */
264int DequantChannel(int *sampleBuf, int *workBuf, int *nonZeroBound, FrameHeader *fh, SideInfoSub *sis,
266void MidSideProc(int x[MAX_NCHAN][MAX_NSAMP], int nSamps, int mOut[2]);
267void IntensityProcMPEG1(int x[MAX_NCHAN][MAX_NSAMP], int nSamps, FrameHeader *fh, ScaleFactorInfoSub *sfis,
268 CriticalBandInfo *cbi, int midSideFlag, int mixFlag, int mOut[2]);
269void IntensityProcMPEG2(int x[MAX_NCHAN][MAX_NSAMP], int nSamps, FrameHeader *fh, ScaleFactorInfoSub *sfis,
270 CriticalBandInfo *cbi, ScaleFactorJS *sfjs, int midSideFlag, int mixFlag, int mOut[2]);
271
272/* dct32.c */
273// about 1 ms faster in RAM, but very large
274void FDCT32(int *x, int *d, int offset, int oddBlock, int gb);// __attribute__ ((section (".data")));
275
276/* hufftabs.c */
278extern const int huffTabOffset[HUFF_PAIRTABS];
279extern const unsigned short huffTable[];
280extern const unsigned char quadTable[64+16];
281extern const int quadTabOffset[2];
282extern const int quadTabMaxBits[2];
283
284/* polyphase.c (or asmpoly.s)
285 * some platforms require a C++ compile of all source files,
286 * so if we're compiling C as C++ and using native assembly
287 * for these functions we need to prevent C++ name mangling.
288 */
289#ifdef __cplusplus
290extern "C" {
291#endif
292void PolyphaseMono(short *pcm, int *vbuf, const int *coefBase);
293void PolyphaseStereo(short *pcm, int *vbuf, const int *coefBase);
294#ifdef __cplusplus
295}
296#endif
297
298/* trigtabs.c */
299extern const int imdctWin[4][36];
300extern const int ISFMpeg1[2][7];
301extern const int ISFMpeg2[2][2][16];
302extern const int ISFIIP[2][2];
303extern const int csa[8][2];
304extern const int coef32[31];
305extern const int polyCoef[264];
306
307#endif /* _CODER_H */
UINT16 x
Definition BmfFile.h:83
#define PolyphaseStereo
Definition coder.h:101
#define HUFF_PAIRTABS
Definition coder.h:86
struct _IMDCTInfo IMDCTInfo
#define DequantChannel
Definition coder.h:96
#define VBUF_LENGTH
Definition coder.h:90
struct _HuffTabLookup HuffTabLookup
struct _FrameHeader FrameHeader
StereoMode
Definition coder.h:121
@ Stereo
Definition coder.h:122
@ Mono
Definition coder.h:125
@ Dual
Definition coder.h:124
@ Joint
Definition coder.h:123
#define IntensityProcMPEG2
Definition coder.h:99
#define CalcBitsUsed
Definition coder.h:95
#define NBANDS
Definition coder.h:88
struct _SideInfoSub SideInfoSub
#define quadTabOffset
Definition coder.h:117
#define huffTabLookup
Definition coder.h:115
#define MAX_REORDER_SAMPS
Definition coder.h:89
#define GetBits
Definition coder.h:94
#define ISFIIP
Definition coder.h:106
#define MidSideProc
Definition coder.h:97
enum _HuffTabType HuffTabType
struct _BlockCount BlockCount
#define coef32
Definition coder.h:108
struct _SideInfo SideInfo
#define ISFMpeg1
Definition coder.h:104
#define FDCT32
Definition coder.h:102
#define IntensityProcMPEG1
Definition coder.h:98
#define ISFMpeg2
Definition coder.h:105
struct _ScaleFactorInfo ScaleFactorInfo
#define SetBitstreamPointer
Definition coder.h:93
#define huffTabOffset
Definition coder.h:114
#define huffTable
Definition coder.h:113
struct _SubbandInfo SubbandInfo
#define quadTable
Definition coder.h:116
#define PolyphaseMono
Definition coder.h:100
struct _ScaleFactorJS ScaleFactorJS
struct _DequantInfo DequantInfo
#define BLOCK_SIZE
Definition coder.h:87
_HuffTabType
Definition coder.h:196
@ quadA
Definition coder.h:201
@ quadB
Definition coder.h:202
@ oneShot
Definition coder.h:198
@ loopNoLinbits
Definition coder.h:199
@ invalidTab
Definition coder.h:203
@ noBits
Definition coder.h:197
@ loopLinbits
Definition coder.h:200
struct _ScaleFactorInfoSub ScaleFactorInfoSub
struct _BitStreamInfo BitStreamInfo
#define imdctWin
Definition coder.h:111
#define csa
Definition coder.h:110
struct _HuffmanInfo HuffmanInfo
#define quadTabMaxBits
Definition coder.h:118
#define polyCoef
Definition coder.h:109
#define MAX_SCFBD
Definition mp3common.h:50
#define MAX_NCHAN
Definition mp3dec.h:79
MPEGVersion
Definition mp3dec.h:83
#define MAX_NGRAN
Definition mp3dec.h:78
#define MAX_NSAMP
Definition mp3dec.h:80
unsigned char * bytePtr
Definition coder.h:129
int cachedBits
Definition coder.h:131
unsigned int iCache
Definition coder.h:130
int nBlocksTotal
Definition coder.h:222
int nBlocksPrev
Definition coder.h:223
int prevWinSwitch
Definition coder.h:225
int gbOut
Definition coder.h:228
int gbIn
Definition coder.h:227
int currWinSwitch
Definition coder.h:226
int prevType
Definition coder.h:224
int nBlocksLong
Definition coder.h:221
int workBuf[MAX_REORDER_SAMPS]
Definition coder.h:186
CriticalBandInfo cbi[MAX_NCHAN]
Definition coder.h:187
const SFBandTable * sfBand
Definition coder.h:150
int brIdx
Definition coder.h:139
int srIdx
Definition coder.h:140
int CRCWord
Definition coder.h:148
int emphasis
Definition coder.h:147
int copyFlag
Definition coder.h:145
MPEGVersion ver
Definition coder.h:136
int origFlag
Definition coder.h:146
int paddingBit
Definition coder.h:141
int modeExt
Definition coder.h:144
StereoMode sMode
Definition coder.h:143
int privateBit
Definition coder.h:142
int layer
Definition coder.h:137
HuffTabType tabType
Definition coder.h:208
int nonZeroBound[MAX_NCHAN]
Definition coder.h:192
int huffDecBuf[MAX_NCHAN][MAX_NSAMP]
Definition coder.h:191
int gb[MAX_NCHAN]
Definition coder.h:193
int gb[MAX_NCHAN]
Definition coder.h:217
int overBuf[MAX_NCHAN][MAX_NSAMP/2]
Definition coder.h:213
int numPrevIMDCT[MAX_NCHAN]
Definition coder.h:214
int prevType[MAX_NCHAN]
Definition coder.h:215
int prevWinSwitch[MAX_NCHAN]
Definition coder.h:216
int outBuf[MAX_NCHAN][BLOCK_SIZE][NBANDS]
Definition coder.h:212
ScaleFactorJS sfjs
Definition coder.h:246
ScaleFactorInfoSub sfis[MAX_NGRAN][MAX_NCHAN]
Definition coder.h:245
char s[13][3]
Definition coder.h:234
int intensityScale
Definition coder.h:239
int nr[4]
Definition coder.h:241
int slen[4]
Definition coder.h:240
int scfsi[MAX_NCHAN][MAX_SCFBD]
Definition coder.h:173
int privateBits
Definition coder.h:172
SideInfoSub sis[MAX_NGRAN][MAX_NCHAN]
Definition coder.h:175
int mainDataBegin
Definition coder.h:171
int preFlag
Definition coder.h:165
int sfactScale
Definition coder.h:166
int mixedBlock
Definition coder.h:160
int nBigvals
Definition coder.h:155
int part23Length
Definition coder.h:154
int count1TableSelect
Definition coder.h:167
int winSwitchFlag
Definition coder.h:158
int sfCompress
Definition coder.h:157
int tableSelect[3]
Definition coder.h:161
int region1Count
Definition coder.h:164
int region0Count
Definition coder.h:163
int subBlockGain[3]
Definition coder.h:162
int blockType
Definition coder.h:159
int globalGain
Definition coder.h:156
int vindex
Definition coder.h:255
int vbuf[MAX_NCHAN *VBUF_LENGTH]
Definition coder.h:254