FastLED 3.9.15
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
48#include "fl/stl/noexcept.h"
49
50#if defined(ASSERT)
51#undef ASSERT
52#endif
53#if defined(_WIN32) && defined(_M_IX86) && (defined (_DEBUG) || defined (REL_ENABLE_ASSERTS))
54#define ASSERT(x) if (!(x)) __asm int 3;
55#else
56#define ASSERT(x) /* do nothing */
57#endif
58
59#ifndef MAX
60#define MAX(a,b) ((a) > (b) ? (a) : (b))
61#endif
62
63#ifndef MIN
64#define MIN(a,b) ((a) < (b) ? (a) : (b))
65#endif
66
67/* Helper function for clipping to range [-2^n, 2^n - 1] */
68__inline int32_t clip_2n_helper(int32_t val, int32_t n) FL_NOEXCEPT {
69 int32_t sign = val >> 31;
70 int32_t shifted;
71 int32_t mask;
72
73 if (n < 31) {
74 shifted = val >> n;
75 mask = (1L << n) - 1;
76 } else {
77 /* Handle edge case where n >= 31 */
78 shifted = sign;
79 mask = 0x7FFFFFFF;
80 }
81
82 if (sign != shifted) {
83 val = sign ^ mask;
84 }
85 return val;
86}
87
88/* clip to range [-2^n, 2^n - 1] */
89#define CLIP_2N(y, n) { \
90 (y) = clip_2n_helper((y), (n)); \
91}
92
93#define SIBYTES_MPEG1_MONO 17
94#define SIBYTES_MPEG1_STEREO 32
95#define SIBYTES_MPEG2_MONO 9
96#define SIBYTES_MPEG2_STEREO 17
97
98/* number of fraction bits for pow43Tab (see comments there) */
99#define POW43_FRACBITS_LOW 22
100#define POW43_FRACBITS_HIGH 12
101
102#define DQ_FRACBITS_OUT 25 /* number of fraction bits in output of dequant */
103#define IMDCT_SCALE 2 /* additional scaling (by sqrt(2)) for fast IMDCT36 */
104
105#define HUFF_PAIRTABS 32
106#define BLOCK_SIZE 18
107#define NBANDS 32
108#define MAX_REORDER_SAMPS ((192-126)*3) /* largest critical band for short blocks (see sfBandTable) */
109#define VBUF_LENGTH (17 * 2 * NBANDS) /* for double-sized vbuf FIFO */
110
111/* additional external symbols to name-mangle for static linking
112 * NOTE: These macros are disabled because we use C++ namespaces (fl::third_party)
113 * for symbol isolation instead of preprocessor prefixing
114 */
115// #define SetBitstreamPointer STATNAME(SetBitstreamPointer)
116// #define GetBits STATNAME(GetBits)
117// #define CalcBitsUsed STATNAME(CalcBitsUsed)
118// #define DequantChannel STATNAME(DequantChannel)
119// #define MidSideProc STATNAME(MidSideProc)
120// #define IntensityProcMPEG1 STATNAME(IntensityProcMPEG1)
121// #define IntensityProcMPEG2 STATNAME(IntensityProcMPEG2)
122// #define PolyphaseMono STATNAME(PolyphaseMono)
123// #define PolyphaseStereo STATNAME(PolyphaseStereo)
124// #define FDCT32 STATNAME(FDCT32)
125
126// #define ISFMpeg1 STATNAME(ISFMpeg1)
127// #define ISFMpeg2 STATNAME(ISFMpeg2)
128// #define ISFIIP STATNAME(ISFIIP)
129// #define uniqueIDTab STATNAME(uniqueIDTab)
130// #define coef32 STATNAME(coef32)
131// #define polyCoef STATNAME(polyCoef)
132// #define csa STATNAME(csa)
133// #define imdctWin STATNAME(imdctWin)
134
135// #define huffTable STATNAME(huffTable)
136// #define huffTabOffset STATNAME(huffTabOffset)
137// #define huffTabLookup STATNAME(huffTabLookup)
138// #define quadTable STATNAME(quadTable)
139// #define quadTabOffset STATNAME(quadTabOffset)
140// #define quadTabMaxBits STATNAME(quadTabMaxBits)
141
142/* map these to the corresponding 2-bit values in the frame header */
143typedef enum {
144 Stereo = 0x00, /* two independent channels, but L and R frames might have different # of bits */
145 Joint = 0x01, /* coupled channels - layer III: mix of M-S and intensity, Layers I/II: intensity and direct coding only */
146 Dual = 0x02, /* two independent channels, L and R always have exactly 1/2 the total bitrate */
147 Mono = 0x03 /* one channel */
148} StereoMode;
149
150namespace fl {
151namespace third_party {
152
159
160typedef struct _FrameHeader {
161 MPEGVersion ver; /* version ID */
162 int32_t layer; /* layer index (1, 2, or 3) */
163 int32_t crc; /* CRC flag: 0 = disabled, 1 = enabled */
164 int32_t brIdx; /* bitrate index (0 - 15) */
165 int32_t srIdx; /* sample rate index (0 - 2) */
166 int32_t paddingBit; /* padding flag: 0 = no padding, 1 = single pad byte */
167 int32_t privateBit; /* unused */
168 StereoMode sMode; /* mono/stereo mode */
169 int32_t modeExt; /* used to decipher joint stereo mode */
170 int32_t copyFlag; /* copyright flag: 0 = no, 1 = yes */
171 int32_t origFlag; /* original flag: 0 = copy, 1 = original */
172 int32_t emphasis; /* deemphasis mode */
173 int32_t CRCWord; /* CRC word (16 bits, 0 if crc not enabled) */
174
177
178typedef struct _SideInfoSub {
179 int32_t part23Length; /* number of bits in main data */
180 int32_t nBigvals; /* 2x this = first set of Huffman cw's (maximum amplitude can be > 1) */
181 int32_t globalGain; /* overall gain for dequantizer */
182 int32_t sfCompress; /* unpacked to figure out number of bits in scale factors */
183 int32_t winSwitchFlag; /* window switching flag */
184 int32_t blockType; /* block type */
185 int32_t mixedBlock; /* 0 = regular block (all short or long), 1 = mixed block */
186 int32_t tableSelect[3]; /* index of Huffman tables for the big values regions */
187 int32_t subBlockGain[3]; /* subblock gain offset, relative to global gain */
188 int32_t region0Count; /* 1+region0Count = num scale factor bands in first region of bigvals */
189 int32_t region1Count; /* 1+region1Count = num scale factor bands in second region of bigvals */
190 int32_t preFlag; /* for optional high frequency boost */
191 int32_t sfactScale; /* scaling of the scalefactors */
192 int32_t count1TableSelect; /* index of Huffman table for quad codewords */
194
202
203typedef struct {
204 int32_t cbType; /* pure long = 0, pure short = 1, mixed = 2 */
205 int32_t cbEndS[3]; /* number nonzero short cb's, per subbblock */
206 int32_t cbEndSMax; /* max of cbEndS[] */
207 int32_t cbEndL; /* number nonzero long cb's */
210typedef struct _DequantInfo {
211 int32_t workBuf[MAX_REORDER_SAMPS]; /* workbuf for reordering short blocks */
212 CriticalBandInfo cbi[MAX_NCHAN]; /* filled in dequantizer, used in joint stereo reconstruction */
215typedef struct _HuffmanInfo {
216 int32_t huffDecBuf[MAX_NCHAN][MAX_NSAMP]; /* used both for decoded Huffman values and dequantized coefficients */
217 int32_t nonZeroBound[MAX_NCHAN]; /* number of coeffs in huffDecBuf[ch] which can be > 0 */
218 int32_t gb[MAX_NCHAN]; /* minimum number of guard bits in huffDecBuf[ch] */
230
235
236typedef struct _IMDCTInfo {
237 int32_t outBuf[MAX_NCHAN][BLOCK_SIZE][NBANDS]; /* output of IMDCT */
238 int32_t overBuf[MAX_NCHAN][MAX_NSAMP / 2]; /* overlap-add buffer (by symmetry, only need 1/2 size) */
239 int32_t numPrevIMDCT[MAX_NCHAN]; /* how many IMDCT's calculated in this channel on prev. granule */
244
255
256/* max bits in scalefactors = 5, so use char's to save space */
257typedef struct _ScaleFactorInfoSub {
258 char l[23]; /* [band] */
259 char s[13][3]; /* [band][window] */
261
262/* used in MPEG 2, 2.5 intensity (joint) stereo only */
268
273
274/* NOTE - could get by with smaller vbuf if memory is more important than speed
275 * (in Subband, instead of replicating each block in FDCT32 you would do a memmove on the
276 * last 15 blocks to shift them down one, a hardware style FIFO)
277 */
278typedef struct _SubbandInfo {
279 int32_t vbuf[MAX_NCHAN * VBUF_LENGTH]; /* vbuf for fast DCT-based synthesis PQMF - double size for speed (no modulo indexing) */
280 int32_t vindex; /* internal index for tracking position in vbuf */
282
283/* bitstream.c */
284void SetBitstreamPointer(BitStreamInfo *bsi, int32_t nBytes, const unsigned char *buf) FL_NOEXCEPT;
286int32_t CalcBitsUsed(BitStreamInfo *bsi, const unsigned char *startBuf, int32_t startOffset) FL_NOEXCEPT;
287
288/* dequant.c, dqchan.c, stproc.c */
289int32_t DequantChannel(int32_t *sampleBuf, int32_t *workBuf, int32_t *nonZeroBound, FrameHeader *fh, SideInfoSub *sis,
290 ScaleFactorInfoSub *sfis, CriticalBandInfo *cbi) FL_NOEXCEPT;
293 CriticalBandInfo *cbi, int32_t midSideFlag, int32_t mixFlag, int32_t mOut[2]) FL_NOEXCEPT;
295 CriticalBandInfo *cbi, ScaleFactorJS *sfjs, int32_t midSideFlag, int32_t mixFlag, int32_t mOut[2]) FL_NOEXCEPT;
296
297/* dct32.c */
298// about 1 ms faster in RAM, but very large
299void FDCT32(int32_t *x, int32_t *d, int32_t offset, int32_t oddBlock, int32_t gb) FL_NOEXCEPT;// __attribute__ ((section (".data")));
300
301/* hufftabs.c */
304extern const unsigned short huffTable[];
305extern const unsigned char quadTable[64+16];
306extern const int32_t quadTabOffset[2];
307extern const int32_t quadTabMaxBits[2];
308
309/* polyphase.c (or asmpoly.s)
310 * some platforms require a C++ compile of all source files,
311 * so if we're compiling C as C++ and using native assembly
312 * for these functions we need to prevent C++ name mangling.
313 */
314#ifdef __cplusplus
315extern "C" {
316#endif
317void PolyphaseMono(short *pcm, int32_t *vbuf, const int32_t *coefBase);
318void PolyphaseStereo(short *pcm, int32_t *vbuf, const int32_t *coefBase);
319#ifdef __cplusplus
320}
321#endif
322
323/* trigtabs.c */
324#include "fl/stl/stdint.h"
325extern const int32_t imdctWin[4][36];
326extern const int32_t ISFMpeg1[2][7];
327extern const int32_t ISFMpeg2[2][2][16];
328extern const int32_t ISFIIP[2][2];
329extern const int32_t csa[8][2];
330extern const int32_t coef32[31];
331extern const int32_t polyCoef[264];
332
333} // namespace third_party
334} // namespace fl
335
336#endif /* _CODER_H */
#define HUFF_PAIRTABS
Definition coder.h:105
#define VBUF_LENGTH
Definition coder.h:109
StereoMode
Definition coder.h:143
@ Stereo
Definition coder.h:144
@ Mono
Definition coder.h:147
@ Dual
Definition coder.h:146
@ Joint
Definition coder.h:145
#define NBANDS
Definition coder.h:107
__inline int32_t clip_2n_helper(int32_t val, int32_t n) FL_NOEXCEPT
Definition coder.h:68
#define MAX_REORDER_SAMPS
Definition coder.h:108
#define BLOCK_SIZE
Definition coder.h:106
fl::UISlider offset("Offset", 0.0f, 0.0f, 1.0f, 0.01f)
#define MAX_SCFBD
Definition mp3common.h:52
#define MAX_NCHAN
Definition mp3dec.h:78
MPEGVersion
Definition mp3dec.h:82
#define MAX_NGRAN
Definition mp3dec.h:77
#define MAX_NSAMP
Definition mp3dec.h:79
const int32_t quadTabOffset[2]
Definition hufftabs.hpp:758
struct fl::third_party::_BitStreamInfo BitStreamInfo
struct fl::third_party::_SFBandTable SFBandTable
fl::u32 uint32_t
Definition coder.h:219
struct fl::third_party::_IMDCTInfo IMDCTInfo
void MidSideProc(int32_t x[MAX_NCHAN][MAX_NSAMP], int32_t nSamps, int32_t mOut[2]) FL_NOEXCEPT
Definition stproc.hpp:71
enum fl::third_party::_HuffTabType HuffTabType
struct fl::third_party::_DequantInfo DequantInfo
const int32_t ISFIIP[2][2]
Definition trigtabs.hpp:218
void FDCT32(int32_t *x, int32_t *d, int32_t offset, int32_t oddBlock, int32_t gb) FL_NOEXCEPT
Definition dct32.hpp:151
const int32_t huffTabOffset[HUFF_PAIRTABS]
Definition hufftabs.hpp:668
const unsigned char quadTable[64+16]
Definition hufftabs.hpp:743
struct fl::third_party::_HuffmanInfo HuffmanInfo
struct fl::third_party::_SubbandInfo SubbandInfo
struct fl::third_party::_ScaleFactorInfoSub ScaleFactorInfoSub
const int32_t imdctWin[4][36]
Definition trigtabs.hpp:107
struct fl::third_party::_FrameHeader FrameHeader
uint32_t GetBits(BitStreamInfo *bsi, int32_t nBits) FL_NOEXCEPT
void SetBitstreamPointer(BitStreamInfo *bsi, int32_t nBytes, const unsigned char *buf) FL_NOEXCEPT
Definition bitstream.hpp:65
const int32_t csa[8][2]
Definition trigtabs.hpp:229
void IntensityProcMPEG1(int32_t x[MAX_NCHAN][MAX_NSAMP], int32_t nSamps, FrameHeader *fh, ScaleFactorInfoSub *sfis, CriticalBandInfo *cbi, int32_t midSideFlag, int32_t mixFlag, int32_t mOut[2]) FL_NOEXCEPT
Definition stproc.hpp:113
struct fl::third_party::_SideInfo SideInfo
struct fl::third_party::_BlockCount BlockCount
const int32_t coef32[31]
Definition trigtabs.hpp:252
const HuffTabLookup huffTabLookup[HUFF_PAIRTABS]
Definition hufftabs.hpp:703
const int32_t ISFMpeg2[2][2][16]
Definition trigtabs.hpp:186
const int32_t ISFMpeg1[2][7]
Definition trigtabs.hpp:164
const int32_t polyCoef[264]
Definition trigtabs.hpp:282
void IntensityProcMPEG2(int32_t x[MAX_NCHAN][MAX_NSAMP], int32_t nSamps, FrameHeader *fh, ScaleFactorInfoSub *sfis, CriticalBandInfo *cbi, ScaleFactorJS *sfjs, int32_t midSideFlag, int32_t mixFlag, int32_t mOut[2]) FL_NOEXCEPT
Definition stproc.hpp:220
fl::i32 int32_t
Definition coder.h:220
struct fl::third_party::_SideInfoSub SideInfoSub
struct fl::third_party::_HuffTabLookup HuffTabLookup
struct fl::third_party::_ScaleFactorJS ScaleFactorJS
struct fl::third_party::_ScaleFactorInfo ScaleFactorInfo
void PolyphaseMono(short *pcm, int32_t *vbuf, const int32_t *coefBase)
const unsigned short huffTable[]
Definition hufftabs.hpp:81
int32_t DequantChannel(int32_t *sampleBuf, int32_t *workBuf, int32_t *nonZeroBound, FrameHeader *fh, SideInfoSub *sis, ScaleFactorInfoSub *sfis, CriticalBandInfo *cbi) FL_NOEXCEPT
Definition dqchan.hpp:252
void PolyphaseStereo(short *pcm, int32_t *vbuf, const int32_t *coefBase)
const int32_t quadTabMaxBits[2]
Definition hufftabs.hpp:759
int32_t CalcBitsUsed(BitStreamInfo *bsi, const unsigned char *startBuf, int32_t startOffset) FL_NOEXCEPT
int32_t overBuf[MAX_NCHAN][MAX_NSAMP/2]
Definition coder.h:238
ScaleFactorInfoSub sfis[MAX_NGRAN][MAX_NCHAN]
Definition coder.h:270
int32_t outBuf[MAX_NCHAN][BLOCK_SIZE][NBANDS]
Definition coder.h:237
int32_t prevType[MAX_NCHAN]
Definition coder.h:240
int32_t prevWinSwitch[MAX_NCHAN]
Definition coder.h:241
const unsigned char * bytePtr
Definition coder.h:154
CriticalBandInfo cbi[MAX_NCHAN]
Definition coder.h:212
int32_t workBuf[MAX_REORDER_SAMPS]
Definition coder.h:211
int32_t nonZeroBound[MAX_NCHAN]
Definition coder.h:217
int32_t gb[MAX_NCHAN]
Definition coder.h:218
int32_t huffDecBuf[MAX_NCHAN][MAX_NSAMP]
Definition coder.h:216
int32_t numPrevIMDCT[MAX_NCHAN]
Definition coder.h:239
int32_t gb[MAX_NCHAN]
Definition coder.h:242
const SFBandTable * sfBand
Definition coder.h:175
SideInfoSub sis[MAX_NGRAN][MAX_NCHAN]
Definition coder.h:200
int32_t vbuf[MAX_NCHAN *VBUF_LENGTH]
Definition coder.h:279
int32_t scfsi[MAX_NCHAN][MAX_SCFBD]
Definition coder.h:198
fl::u32 uint32_t
Definition s16x16x4.h:219
fl::i32 int32_t
Definition s16x16x4.h:220
Base definition for an LED controller.
Definition crgb.hpp:179
#define FL_NOEXCEPT