blob: ab900b7fd3610c266900e73a95ff4e05dc7c9f38
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 | #include <android/log.h> |
53 | #include <stdio.h> |
54 | #include <stdarg.h> |
55 | //#include <string.h> |
56 | #define LOG_TAG "FaadDecoder" |
57 | #define audio_codec_print(...) __android_log_print(ANDROID_LOG_INFO,LOG_TAG,__VA_ARGS__) |
58 | #define printk audio_codec_print |
59 | #define LOCAL /*inline*/ |
60 | |
61 | /* 12-bit syncword */ |
62 | #define SYNCWORDH 0xff |
63 | #define SYNCWORDL 0xf0 |
64 | |
65 | #define SYNCWORD0 0x67 |
66 | #define SYNCWORD1 0x89 |
67 | |
68 | #define MAX_NCHANS_ELEM 2// /* max number of channels in any single bitstream element (SCE,CPE,CCE,LFE) */ |
69 | |
70 | #define ADTS_HEADER_BYTES 7 |
71 | #define NUM_SAMPLE_RATES 12 |
72 | #define NUM_DEF_CHAN_MAPS 8 |
73 | #define NUM_ELEMENTS 8 |
74 | #define MAX_NUM_PCE_ADIF 16 |
75 | |
76 | #define MAX_WIN_GROUPS 8 |
77 | #define MAX_SFB_SHORT 15 |
78 | #define MAX_SF_BANDS (MAX_SFB_SHORT*MAX_WIN_GROUPS) /* worst case = 15 sfb's * 8 windows for short block */ |
79 | #define MAX_MS_MASK_BYTES ((MAX_SF_BANDS + 7) >> 3) |
80 | #define MAX_PRED_SFB 41 |
81 | #define MAX_TNS_FILTERS 8 |
82 | #define MAX_TNS_COEFS 60 |
83 | #define MAX_TNS_ORDER 20 |
84 | #define MAX_PULSES 4 |
85 | #define MAX_GAIN_BANDS 3 |
86 | #define MAX_GAIN_WIN 8 |
87 | #define MAX_GAIN_ADJUST 7 |
88 | |
89 | #define NSAMPS_LONG 1024 |
90 | #define NSAMPS_SHORT 128 |
91 | |
92 | #define NUM_SYN_ID_BITS 3 |
93 | #define NUM_INST_TAG_BITS 4 |
94 | |
95 | #define EXT_SBR_DATA 0x0d |
96 | #define EXT_SBR_DATA_CRC 0x0e |
97 | |
98 | #define IS_ADIF(p) ((p)[0] == 'A' && (p)[1] == 'D' && (p)[2] == 'I' && (p)[3] == 'F') |
99 | #define GET_ELE_ID(p) ((AACElementID)(*(p) >> (8-NUM_SYN_ID_BITS))) |
100 | |
101 | /* AAC file format */ |
102 | enum { |
103 | AAC_FF_Unknown = 0, /* should be 0 on init */ |
104 | |
105 | AAC_FF_ADTS = 1, |
106 | AAC_FF_ADIF = 2, |
107 | AAC_FF_RAW = 3 |
108 | |
109 | }; |
110 | |
111 | /* syntactic element type */ |
112 | enum { |
113 | AAC_ID_INVALID = -1, |
114 | |
115 | AAC_ID_SCE = 0, |
116 | AAC_ID_CPE = 1, |
117 | AAC_ID_CCE = 2, |
118 | AAC_ID_LFE = 3, |
119 | AAC_ID_DSE = 4, |
120 | AAC_ID_PCE = 5, |
121 | AAC_ID_FIL = 6, |
122 | AAC_ID_END = 7 |
123 | }; |
124 | |
125 | typedef struct _AACDecInfo { |
126 | /* pointers to platform-specific state information */ |
127 | void *psInfoBase; /* baseline MPEG-4 LC decoding */ |
128 | void *psInfoSBR; /* MPEG-4 SBR decoding */ |
129 | |
130 | /* raw decoded data, before rounding to 16-bit PCM (for postprocessing such as SBR) */ |
131 | void *rawSampleBuf[AAC_MAX_NCHANS]; |
132 | int rawSampleBytes; |
133 | int rawSampleFBits; |
134 | |
135 | /* fill data (can be used for processing SBR or other extensions) */ |
136 | unsigned char *fillBuf; |
137 | int fillCount; |
138 | int fillExtType; |
139 | |
140 | /* block information */ |
141 | int prevBlockID; |
142 | int currBlockID; |
143 | int currInstTag; |
144 | int sbDeinterleaveReqd[MAX_NCHANS_ELEM]; |
145 | int adtsBlocksLeft; |
146 | |
147 | /* user-accessible info */ |
148 | int bitRate; |
149 | int nChans; |
150 | int sampRate; |
151 | int profile; |
152 | int format; |
153 | int sbrEnabled; |
154 | int tnsUsed; |
155 | int pnsUsed; |
156 | int frameCount; |
157 | int byteParsed; |
158 | int sampleDecoded; |
159 | unsigned audio_send_by_frame; |
160 | unsigned frame_length; |
161 | } AACDecInfo; |
162 | |
163 | /* decoder functions which must be implemented for each platform */ |
164 | AACDecInfo *AllocateBuffers(void); |
165 | void FreeBuffers(AACDecInfo *aacDecInfo); |
166 | void ClearBuffer(void *buf, int nBytes); |
167 | |
168 | int UnpackADTSHeader(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail); |
169 | int GetADTSChannelMapping(AACDecInfo *aacDecInfo, unsigned char *buf, int bitOffset, int bitsAvail); |
170 | int UnpackADIFHeader(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail); |
171 | int SetRawBlockParams(AACDecInfo *aacDecInfo, int copyLast, int nChans, int sampRate, int profile); |
172 | int PrepareRawBlock(AACDecInfo *aacDecInfo); |
173 | int FlushCodec(AACDecInfo *aacDecInfo); |
174 | |
175 | int DecodeNextElement(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail); |
176 | int DecodeNoiselessData(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail, int ch); |
177 | |
178 | int Dequantize(AACDecInfo *aacDecInfo, int ch); |
179 | int StereoProcess(AACDecInfo *aacDecInfo); |
180 | int DeinterleaveShortBlocks(AACDecInfo *aacDecInfo, int ch); |
181 | int PNS(AACDecInfo *aacDecInfo, int ch); |
182 | int TNSFilter(AACDecInfo *aacDecInfo, int ch); |
183 | int IMDCT(AACDecInfo *aacDecInfo, int ch, int chBase, short *outbuf); |
184 | |
185 | /* SBR specific functions */ |
186 | int InitSBR(AACDecInfo *aacDecInfo); |
187 | void FreeSBR(AACDecInfo *aacDecInfo); |
188 | int DecodeSBRBitstream(AACDecInfo *aacDecInfo, int chBase); |
189 | int DecodeSBRData(AACDecInfo *aacDecInfo, int chBase, short *outbuf); |
190 | int FlushCodecSBR(AACDecInfo *aacDecInfo); |
191 | |
192 | /* aactabs.c - global ROM tables */ |
193 | extern const int sampRateTab[NUM_SAMPLE_RATES]; |
194 | extern const int predSFBMax[NUM_SAMPLE_RATES]; |
195 | extern const int channelMapTab[NUM_DEF_CHAN_MAPS]; |
196 | extern const int elementNumChans[NUM_ELEMENTS]; |
197 | extern const unsigned char sfBandTotalShort[NUM_SAMPLE_RATES]; |
198 | extern const unsigned char sfBandTotalLong[NUM_SAMPLE_RATES]; |
199 | extern const int sfBandTabShortOffset[NUM_SAMPLE_RATES]; |
200 | extern const short sfBandTabShort[76]; |
201 | extern const int sfBandTabLongOffset[NUM_SAMPLE_RATES]; |
202 | extern const short sfBandTabLong[325]; |
203 | extern const int tnsMaxBandsShortOffset[AAC_NUM_PROFILES]; |
204 | extern const unsigned char tnsMaxBandsShort[2 * NUM_SAMPLE_RATES]; |
205 | extern const unsigned char tnsMaxOrderShort[AAC_NUM_PROFILES]; |
206 | extern const int tnsMaxBandsLongOffset[AAC_NUM_PROFILES]; |
207 | extern const unsigned char tnsMaxBandsLong[2 * NUM_SAMPLE_RATES]; |
208 | extern const unsigned char tnsMaxOrderLong[AAC_NUM_PROFILES]; |
209 | |
210 | #endif /* _AACCOMMON_H */ |
211 |