1 /*
2 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
3 ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
4 **
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ** GNU General Public License for more details.
14 **
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 **
19 ** Any non-GPL usage of this software or parts of this software is strictly
20 ** forbidden.
21 **
22 ** Commercial non-GPL licensing of this software is possible.
23 ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
24 **
25 ** $Id: neaacdec.h,v 1.5 2004/09/04 14:56:27 menno Exp $
26 **/
27 
28 #ifndef __NEAACDEC_H__
29 #define __NEAACDEC_H__
30 
31 #ifdef __cplusplus
32 extern "C" {
33 #endif /* __cplusplus */
34 
35 
36 #if 1
37 /* MACROS FOR BACKWARDS COMPATIBILITY */
38 /* structs */
39 #define faacDecHandle                  NeAACDecHandle
40 #define faacDecConfiguration           NeAACDecConfiguration
41 #define faacDecConfigurationPtr        NeAACDecConfigurationPtr
42 #define faacDecFrameInfo               NeAACDecFrameInfo
43 /* functions */
44 #define faacDecGetErrorMessage         NeAACDecGetErrorMessage
45 #define faacDecSetConfiguration        NeAACDecSetConfiguration
46 #define faacDecGetCurrentConfiguration NeAACDecGetCurrentConfiguration
47 #define faacDecInit                    NeAACDecInit
48 #define faacDecInit2                   NeAACDecInit2
49 #define faacDecInitDRM                 NeAACDecInitDRM
50 #define faacDecPostSeekReset           NeAACDecPostSeekReset
51 #define faacDecOpen                    NeAACDecOpen
52 #define faacDecClose                   NeAACDecClose
53 #define faacDecDecode                  NeAACDecDecode
54 #define AudioSpecificConfig            NeAACDecAudioSpecificConfig
55 #endif
56 
57 
58 #ifdef _WIN32
59   #pragma pack(push, 8)
60   #ifndef NEAACDECAPI
61     #define NEAACDECAPI __cdecl
62   #endif
63 #else
64   #ifndef NEAACDECAPI
65     #define NEAACDECAPI
66   #endif
67 #endif
68 
69 #define FAAD2_VERSION "2.1 beta"
70 
71 /* object types for AAC */
72 #define MAIN       1
73 #define LC         2
74 #define SSR        3
75 #define LTP        4
76 #define HE_AAC     5
77 #define ER_LC     17
78 #define ER_LTP    19
79 #define LD        23
80 #define DRM_ER_LC 27 /* special object type for DRM */
81 
82 /* header types */
83 #define RAW        0
84 #define ADIF       1
85 #define ADTS       2
86 
87 /* SBR signalling */
88 #define NO_SBR           0
89 #define SBR_UPSAMPLED    1
90 #define SBR_DOWNSAMPLED  2
91 #define NO_SBR_UPSAMPLED 3
92 
93 /* library output formats */
94 #define FAAD_FMT_16BIT  1
95 #define FAAD_FMT_24BIT  2
96 #define FAAD_FMT_32BIT  3
97 #define FAAD_FMT_FLOAT  4
98 #define FAAD_FMT_FIXED  FAAD_FMT_FLOAT
99 #define FAAD_FMT_DOUBLE 5
100 
101 /* Capabilities */
102 #define LC_DEC_CAP           (1<<0) /* Can decode LC */
103 #define MAIN_DEC_CAP         (1<<1) /* Can decode MAIN */
104 #define LTP_DEC_CAP          (1<<2) /* Can decode LTP */
105 #define LD_DEC_CAP           (1<<3) /* Can decode LD */
106 #define ERROR_RESILIENCE_CAP (1<<4) /* Can decode ER */
107 #define FIXED_POINT_CAP      (1<<5) /* Fixed point */
108 
109 /* Channel definitions */
110 #define FRONT_CHANNEL_CENTER (1)
111 #define FRONT_CHANNEL_LEFT   (2)
112 #define FRONT_CHANNEL_RIGHT  (3)
113 #define SIDE_CHANNEL_LEFT    (4)
114 #define SIDE_CHANNEL_RIGHT   (5)
115 #define BACK_CHANNEL_LEFT    (6)
116 #define BACK_CHANNEL_RIGHT   (7)
117 #define BACK_CHANNEL_CENTER  (8)
118 #define LFE_CHANNEL          (9)
119 #define UNKNOWN_CHANNEL      (0)
120 
121 /* DRM channel definitions */
122 #define DRMCH_MONO          1
123 #define DRMCH_STEREO        2
124 #define DRMCH_SBR_MONO      3
125 #define DRMCH_SBR_STEREO    4
126 #define DRMCH_SBR_PS_STEREO 5
127 
128 
129 /* A decode call can eat up to FAAD_MIN_STREAMSIZE bytes per decoded channel,
130    so at least so much bytes per channel should be available in this stream */
131 #define FAAD_MIN_STREAMSIZE 768 /* 6144 bits/channel */
132 
133 
134 typedef void *NeAACDecHandle;
135 
136 typedef struct mp4AudioSpecificConfig
137 {
138     /* Audio Specific Info */
139     unsigned char objectTypeIndex;
140     unsigned char samplingFrequencyIndex;
141     unsigned long samplingFrequency;
142     unsigned char channelsConfiguration;
143 
144     /* GA Specific Info */
145     unsigned char frameLengthFlag;
146     unsigned char dependsOnCoreCoder;
147     unsigned short coreCoderDelay;
148     unsigned char extensionFlag;
149     unsigned char aacSectionDataResilienceFlag;
150     unsigned char aacScalefactorDataResilienceFlag;
151     unsigned char aacSpectralDataResilienceFlag;
152     unsigned char epConfig;
153 
154     char sbr_present_flag;
155     char forceUpSampling;
156     char downSampledSBR;
157 } mp4AudioSpecificConfig;
158 
159 typedef struct NeAACDecConfiguration
160 {
161     unsigned char defObjectType;
162     unsigned long defSampleRate;
163     unsigned char outputFormat;
164     unsigned char downMatrix;
165     unsigned char useOldADTSFormat;
166     unsigned char dontUpSampleImplicitSBR;
167 } NeAACDecConfiguration, *NeAACDecConfigurationPtr;
168 
169 typedef struct NeAACDecFrameInfo
170 {
171     unsigned long bytesconsumed;
172     unsigned long samples;
173     unsigned char channels;
174     unsigned char error;
175     unsigned long samplerate;
176 
177     /* SBR: 0: off, 1: on; upsample, 2: on; downsampled, 3: off; upsampled */
178     unsigned char sbr;
179 
180     /* MPEG-4 ObjectType */
181     unsigned char object_type;
182 
183     /* AAC header type; MP4 will be signalled as RAW also */
184     unsigned char header_type;
185 
186     /* multichannel configuration */
187     unsigned char num_front_channels;
188     unsigned char num_side_channels;
189     unsigned char num_back_channels;
190     unsigned char num_lfe_channels;
191     unsigned char channel_position[64];
192 
193     /* PS: 0: off, 1: on */
194     unsigned char ps;
195 } NeAACDecFrameInfo;
196 
197 char* NEAACDECAPI NeAACDecGetErrorMessage(unsigned char errcode);
198 
199 unsigned long NEAACDECAPI NeAACDecGetCapabilities(void);
200 
201 NeAACDecHandle NEAACDECAPI NeAACDecOpen(void);
202 
203 NeAACDecConfigurationPtr NEAACDECAPI NeAACDecGetCurrentConfiguration(NeAACDecHandle hDecoder);
204 
205 unsigned char NEAACDECAPI NeAACDecSetConfiguration(NeAACDecHandle hDecoder,
206                                                    NeAACDecConfigurationPtr config);
207 
208 /* Init the library based on info from the AAC file (ADTS/ADIF) */
209 long NEAACDECAPI NeAACDecInit(NeAACDecHandle hDecoder,
210                               unsigned char *buffer,
211                               unsigned long buffer_size,
212                               unsigned long *samplerate,
213                               unsigned char *channels);
214 
215 /* Init the library using a DecoderSpecificInfo */
216 char NEAACDECAPI NeAACDecInit2(NeAACDecHandle hDecoder, unsigned char *pBuffer,
217                                unsigned long SizeOfDecoderSpecificInfo,
218                                unsigned long *samplerate, unsigned char *channels);
219 
220 /* Init the library for DRM */
221 char NEAACDECAPI NeAACDecInitDRM(NeAACDecHandle *hDecoder, unsigned long samplerate,
222                                  unsigned char channels);
223 
224 void NEAACDECAPI NeAACDecPostSeekReset(NeAACDecHandle hDecoder, long frame);
225 
226 void NEAACDECAPI NeAACDecClose(NeAACDecHandle hDecoder);
227 
228 void* NEAACDECAPI NeAACDecDecode(NeAACDecHandle hDecoder,
229                                  NeAACDecFrameInfo *hInfo,
230                                  unsigned char *buffer,
231                                  unsigned long buffer_size);
232 
233 void* NEAACDECAPI NeAACDecDecode2(NeAACDecHandle hDecoder,
234                                   NeAACDecFrameInfo *hInfo,
235                                   unsigned char *buffer,
236                                   unsigned long buffer_size,
237                                   void **sample_buffer,
238                                   unsigned long sample_buffer_size);
239 
240 char NEAACDECAPI NeAACDecAudioSpecificConfig(unsigned char *pBuffer,
241                                              unsigned long buffer_size,
242                                              mp4AudioSpecificConfig *mp4ASC);
243 
244 #ifdef _WIN32
245   #pragma pack(pop)
246 #endif
247 
248 #ifdef __cplusplus
249 }
250 #endif /* __cplusplus */
251 
252 #endif
253