blob: 85f1a918baff5650135f545e51385bd91d4725f0
1 | /* ***** BEGIN LICENSE BLOCK ***** |
2 | * Source last modified: $Id: aaccommon.h,v 1.1 2005/02/26 01:47:34 jrecker Exp $ |
3 | * |
4 | * Portions Copyright (c) 1995-2005 RealNetworks, Inc. All Rights Reserved. |
5 | * |
6 | * The contents of this file, and the files included with this file, |
7 | * are subject to the current version of the RealNetworks Public |
8 | * Source License (the "RPSL") available at |
9 | * http://www.helixcommunity.org/content/rpsl unless you have licensed |
10 | * the file under the current version of the RealNetworks Community |
11 | * Source License (the "RCSL") available at |
12 | * http://www.helixcommunity.org/content/rcsl, in which case the RCSL |
13 | * will apply. You may also obtain the license terms directly from |
14 | * RealNetworks. You may not use this file except in compliance with |
15 | * the RPSL or, if you have a valid RCSL with RealNetworks applicable |
16 | * to this file, the RCSL. Please see the applicable RPSL or RCSL for |
17 | * the rights, obligations and limitations governing use of the |
18 | * contents of the file. |
19 | * |
20 | * This file is part of the Helix DNA Technology. RealNetworks is the |
21 | * developer of the Original Code and owns the copyrights in the |
22 | * portions it created. |
23 | * |
24 | * This file, and the files included with this file, is distributed |
25 | * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY |
26 | * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS |
27 | * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES |
28 | * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET |
29 | * ENJOYMENT OR NON-INFRINGEMENT. |
30 | * |
31 | * Technology Compatibility Kit Test Suite(s) Location: |
32 | * http://www.helixcommunity.org/content/tck |
33 | * |
34 | * Contributor(s): |
35 | * |
36 | * ***** END LICENSE BLOCK ***** */ |
37 | |
38 | /************************************************************************************** |
39 | * Fixed-point HE-AAC decoder |
40 | * Jon Recker (jrecker@real.com) |
41 | * February 2005 |
42 | * |
43 | * aaccommon.h - implementation-independent API's, datatypes, and definitions |
44 | **************************************************************************************/ |
45 | |
46 | #ifndef _AACCOMMON_H |
47 | #define _AACCOMMON_H |
48 | |
49 | #include "aacdec.h" |
50 | #include "statname.h" |
51 | |
52 | /* 12-bit syncword */ |
53 | #define SYNCWORDH 0xff |
54 | #define SYNCWORDL 0xf0 |
55 | |
56 | #define SYNCWORD0 0x67 |
57 | #define SYNCWORD1 0x89 |
58 | |
59 | #define MAX_NCHANS_ELEM 2 /* max number of channels in any single bitstream element (SCE,CPE,CCE,LFE) */ |
60 | |
61 | #define ADTS_HEADER_BYTES 7 |
62 | #define NUM_SAMPLE_RATES 12 |
63 | #define NUM_DEF_CHAN_MAPS 8 |
64 | #define NUM_ELEMENTS 8 |
65 | #define MAX_NUM_PCE_ADIF 16 |
66 | |
67 | #define MAX_WIN_GROUPS 8 |
68 | #define MAX_SFB_SHORT 15 |
69 | #define MAX_SF_BANDS (MAX_SFB_SHORT*MAX_WIN_GROUPS) /* worst case = 15 sfb's * 8 windows for short block */ |
70 | #define MAX_MS_MASK_BYTES ((MAX_SF_BANDS + 7) >> 3) |
71 | #define MAX_PRED_SFB 41 |
72 | #define MAX_TNS_FILTERS 8 |
73 | #define MAX_TNS_COEFS 60 |
74 | #define MAX_TNS_ORDER 20 |
75 | #define MAX_PULSES 4 |
76 | #define MAX_GAIN_BANDS 3 |
77 | #define MAX_GAIN_WIN 8 |
78 | #define MAX_GAIN_ADJUST 7 |
79 | |
80 | #define NSAMPS_LONG 1024 |
81 | #define NSAMPS_SHORT 128 |
82 | |
83 | #define NUM_SYN_ID_BITS 3 |
84 | #define NUM_INST_TAG_BITS 4 |
85 | |
86 | #define EXT_SBR_DATA 0x0d |
87 | #define EXT_SBR_DATA_CRC 0x0e |
88 | |
89 | #define IS_ADIF(p) ((p)[0] == 'A' && (p)[1] == 'D' && (p)[2] == 'I' && (p)[3] == 'F') |
90 | #define GET_ELE_ID(p) ((AACElementID)(*(p) >> (8-NUM_SYN_ID_BITS))) |
91 | |
92 | /* AAC file format */ |
93 | enum { |
94 | AAC_FF_Unknown = 0, /* should be 0 on init */ |
95 | |
96 | AAC_FF_ADTS = 1, |
97 | AAC_FF_ADIF = 2, |
98 | AAC_FF_RAW = 3 |
99 | |
100 | }; |
101 | |
102 | /* syntactic element type */ |
103 | enum { |
104 | AAC_ID_INVALID = -1, |
105 | |
106 | AAC_ID_SCE = 0, |
107 | AAC_ID_CPE = 1, |
108 | AAC_ID_CCE = 2, |
109 | AAC_ID_LFE = 3, |
110 | AAC_ID_DSE = 4, |
111 | AAC_ID_PCE = 5, |
112 | AAC_ID_FIL = 6, |
113 | AAC_ID_END = 7 |
114 | }; |
115 | |
116 | typedef struct _AACDecInfo { |
117 | /* pointers to platform-specific state information */ |
118 | void *psInfoBase; /* baseline MPEG-4 LC decoding */ |
119 | void *psInfoSBR; /* MPEG-4 SBR decoding */ |
120 | |
121 | /* raw decoded data, before rounding to 16-bit PCM (for postprocessing such as SBR) */ |
122 | void *rawSampleBuf[AAC_MAX_NCHANS]; |
123 | int rawSampleBytes; |
124 | int rawSampleFBits; |
125 | |
126 | /* fill data (can be used for processing SBR or other extensions) */ |
127 | unsigned char *fillBuf; |
128 | int fillCount; |
129 | int fillExtType; |
130 | |
131 | /* block information */ |
132 | int prevBlockID; |
133 | int currBlockID; |
134 | int currInstTag; |
135 | int sbDeinterleaveReqd[MAX_NCHANS_ELEM]; |
136 | int adtsBlocksLeft; |
137 | |
138 | /* user-accessible info */ |
139 | int bitRate; |
140 | int nChans; |
141 | int sampRate; |
142 | int profile; |
143 | int format; |
144 | int sbrEnabled; |
145 | int tnsUsed; |
146 | int pnsUsed; |
147 | int frameCount; |
148 | int byteParsed; |
149 | int sampleDecoded; |
150 | unsigned audio_send_by_frame; |
151 | } AACDecInfo; |
152 | |
153 | /* decoder functions which must be implemented for each platform */ |
154 | AACDecInfo *AllocateBuffers(void); |
155 | void FreeBuffers(AACDecInfo *aacDecInfo); |
156 | void ClearBuffer(void *buf, int nBytes); |
157 | |
158 | int UnpackADTSHeader(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail); |
159 | int GetADTSChannelMapping(AACDecInfo *aacDecInfo, unsigned char *buf, int bitOffset, int bitsAvail); |
160 | int UnpackADIFHeader(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail); |
161 | int SetRawBlockParams(AACDecInfo *aacDecInfo, int copyLast, int nChans, int sampRate, int profile); |
162 | int PrepareRawBlock(AACDecInfo *aacDecInfo); |
163 | int FlushCodec(AACDecInfo *aacDecInfo); |
164 | |
165 | int DecodeNextElement(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail); |
166 | int DecodeNoiselessData(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail, int ch); |
167 | |
168 | int Dequantize(AACDecInfo *aacDecInfo, int ch); |
169 | int StereoProcess(AACDecInfo *aacDecInfo); |
170 | int DeinterleaveShortBlocks(AACDecInfo *aacDecInfo, int ch); |
171 | int PNS(AACDecInfo *aacDecInfo, int ch); |
172 | int TNSFilter(AACDecInfo *aacDecInfo, int ch); |
173 | int IMDCT(AACDecInfo *aacDecInfo, int ch, int chBase, short *outbuf); |
174 | |
175 | /* SBR specific functions */ |
176 | int InitSBR(AACDecInfo *aacDecInfo); |
177 | void FreeSBR(AACDecInfo *aacDecInfo); |
178 | int DecodeSBRBitstream(AACDecInfo *aacDecInfo, int chBase); |
179 | int DecodeSBRData(AACDecInfo *aacDecInfo, int chBase, short *outbuf); |
180 | int FlushCodecSBR(AACDecInfo *aacDecInfo); |
181 | |
182 | /* aactabs.c - global ROM tables */ |
183 | extern const int sampRateTab[NUM_SAMPLE_RATES]; |
184 | extern const int predSFBMax[NUM_SAMPLE_RATES]; |
185 | extern const int channelMapTab[NUM_DEF_CHAN_MAPS]; |
186 | extern const int elementNumChans[NUM_ELEMENTS]; |
187 | extern const unsigned char sfBandTotalShort[NUM_SAMPLE_RATES]; |
188 | extern const unsigned char sfBandTotalLong[NUM_SAMPLE_RATES]; |
189 | extern const int sfBandTabShortOffset[NUM_SAMPLE_RATES]; |
190 | extern const short sfBandTabShort[76]; |
191 | extern const int sfBandTabLongOffset[NUM_SAMPLE_RATES]; |
192 | extern const short sfBandTabLong[325]; |
193 | extern const int tnsMaxBandsShortOffset[AAC_NUM_PROFILES]; |
194 | extern const unsigned char tnsMaxBandsShort[2 * NUM_SAMPLE_RATES]; |
195 | extern const unsigned char tnsMaxOrderShort[AAC_NUM_PROFILES]; |
196 | extern const int tnsMaxBandsLongOffset[AAC_NUM_PROFILES]; |
197 | extern const unsigned char tnsMaxBandsLong[2 * NUM_SAMPLE_RATES]; |
198 | extern const unsigned char tnsMaxOrderLong[AAC_NUM_PROFILES]; |
199 | |
200 | #endif /* _AACCOMMON_H */ |
201 |