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