summaryrefslogtreecommitdiff
path: root/audio_codec/wfd_aac_decoder/aaccommon.h (plain)
blob: e349dce479eeaaa0ac954b3951dd535ac481bc0d
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 "WFDAAC"
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 */
102enum {
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 */
112enum {
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
125typedef 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 */
164AACDecInfo *AllocateBuffers(void);
165void FreeBuffers(AACDecInfo *aacDecInfo);
166void ClearBuffer(void *buf, int nBytes);
167
168int UnpackADTSHeader(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail);
169int GetADTSChannelMapping(AACDecInfo *aacDecInfo, unsigned char *buf, int bitOffset, int bitsAvail);
170int UnpackADIFHeader(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail);
171int SetRawBlockParams(AACDecInfo *aacDecInfo, int copyLast, int nChans, int sampRate, int profile);
172int PrepareRawBlock(AACDecInfo *aacDecInfo);
173int FlushCodec(AACDecInfo *aacDecInfo);
174
175int DecodeNextElement(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail);
176int DecodeNoiselessData(AACDecInfo *aacDecInfo, unsigned char **buf, int *bitOffset, int *bitsAvail, int ch);
177
178int Dequantize(AACDecInfo *aacDecInfo, int ch);
179int StereoProcess(AACDecInfo *aacDecInfo);
180int DeinterleaveShortBlocks(AACDecInfo *aacDecInfo, int ch);
181int PNS(AACDecInfo *aacDecInfo, int ch);
182int TNSFilter(AACDecInfo *aacDecInfo, int ch);
183int IMDCT(AACDecInfo *aacDecInfo, int ch, int chBase, short *outbuf);
184
185/* SBR specific functions */
186int InitSBR(AACDecInfo *aacDecInfo);
187void FreeSBR(AACDecInfo *aacDecInfo);
188int DecodeSBRBitstream(AACDecInfo *aacDecInfo, int chBase);
189int DecodeSBRData(AACDecInfo *aacDecInfo, int chBase, short *outbuf);
190int FlushCodecSBR(AACDecInfo *aacDecInfo);
191
192/* aactabs.c - global ROM tables */
193extern const int sampRateTab[NUM_SAMPLE_RATES];
194extern const int predSFBMax[NUM_SAMPLE_RATES];
195extern const int channelMapTab[NUM_DEF_CHAN_MAPS];
196extern const int elementNumChans[NUM_ELEMENTS];
197extern const unsigned char sfBandTotalShort[NUM_SAMPLE_RATES];
198extern const unsigned char sfBandTotalLong[NUM_SAMPLE_RATES];
199extern const int sfBandTabShortOffset[NUM_SAMPLE_RATES];
200extern const short sfBandTabShort[76];
201extern const int sfBandTabLongOffset[NUM_SAMPLE_RATES];
202extern const short sfBandTabLong[325];
203extern const int tnsMaxBandsShortOffset[AAC_NUM_PROFILES];
204extern const unsigned char tnsMaxBandsShort[2 * NUM_SAMPLE_RATES];
205extern const unsigned char tnsMaxOrderShort[AAC_NUM_PROFILES];
206extern const int tnsMaxBandsLongOffset[AAC_NUM_PROFILES];
207extern const unsigned char tnsMaxBandsLong[2 * NUM_SAMPLE_RATES];
208extern const unsigned char tnsMaxOrderLong[AAC_NUM_PROFILES];
209
210#endif /* _AACCOMMON_H */
211