1
2/* -----------------------------------------------------------------------------------------------------------
3Software License for The Fraunhofer FDK AAC Codec Library for Android
4
5� Copyright  1995 - 2013 Fraunhofer-Gesellschaft zur F�rderung der angewandten Forschung e.V.
6  All rights reserved.
7
8 1.    INTRODUCTION
9The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
10the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
11This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
12
13AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
14audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
15independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
16of the MPEG specifications.
17
18Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
19may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
20individually for the purpose of encoding or decoding bit streams in products that are compliant with
21the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
22these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
23software may already be covered under those patent licenses when it is used for those licensed purposes only.
24
25Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
26are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
27applications information and documentation.
28
292.    COPYRIGHT LICENSE
30
31Redistribution and use in source and binary forms, with or without modification, are permitted without
32payment of copyright license fees provided that you satisfy the following conditions:
33
34You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
35your modifications thereto in source code form.
36
37You must retain the complete text of this software license in the documentation and/or other materials
38provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
39You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
40modifications thereto to recipients of copies in binary form.
41
42The name of Fraunhofer may not be used to endorse or promote products derived from this library without
43prior written permission.
44
45You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
46software or your modifications thereto.
47
48Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
49and the date of any change. For modified versions of the FDK AAC Codec, the term
50"Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
51"Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
52
533.    NO PATENT LICENSE
54
55NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
56ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
57respect to this software.
58
59You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
60by appropriate patent licenses.
61
624.    DISCLAIMER
63
64This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
65"AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
66of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
67CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
68including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
69or business interruption, however caused and on any theory of liability, whether in contract, strict
70liability, or tort (including negligence), arising in any way out of the use of this software, even if
71advised of the possibility of such damage.
72
735.    CONTACT INFORMATION
74
75Fraunhofer Institute for Integrated Circuits IIS
76Attention: Audio and Multimedia Departments - FDK AAC LL
77Am Wolfsmantel 33
7891058 Erlangen, Germany
79
80www.iis.fraunhofer.de/amm
81amm-info@iis.fraunhofer.de
82----------------------------------------------------------------------------------------------------------- */
83
84/*!
85  \file
86  \brief  Framing generator prototypes and structs
87*/
88#ifndef _FRAM_GEN_H
89#define _FRAM_GEN_H
90
91#include "sbr_def.h" /* for MAX_ENVELOPES and MAX_NOISE_ENVELOPES in struct FRAME_INFO and CODEC_TYPE */
92
93#define MAX_ENVELOPES_VARVAR MAX_ENVELOPES /*!< worst case number of envelopes in a VARVAR frame */
94#define MAX_ENVELOPES_FIXVAR_VARFIX 4 /*!< worst case number of envelopes in VARFIX and FIXVAR frames */
95#define MAX_NUM_REL 3 /*!< maximum number of relative borders in any VAR frame */
96
97/* SBR frame class definitions */
98typedef enum {
99  FIXFIX = 0, /*!< bs_frame_class: leading and trailing frame borders are fixed */
100  FIXVAR,     /*!< bs_frame_class: leading frame border is fixed, trailing frame border is variable */
101  VARFIX,     /*!< bs_frame_class: leading frame border is variable, trailing frame border is fixed */
102  VARVAR      /*!< bs_frame_class: leading and trailing frame borders are variable */
103  ,FIXFIXonly  /*!< bs_frame_class: leading border fixed (0), trailing border fixed (nrTimeSlots) and encased borders are dynamically derived from the tranPos */
104}FRAME_CLASS;
105
106
107/* helper constants */
108#define DC      4711        /*!< helper constant: don't care */
109#define EMPTY   (-99)       /*!< helper constant: empty */
110
111
112/* system constants: AAC+SBR, DRM Frame-Length */
113#define FRAME_MIDDLE_SLOT_1920  4
114#define NUMBER_TIME_SLOTS_1920  15
115
116#define LD_PRETRAN_OFF           3
117#define FRAME_MIDDLE_SLOT_512LD  0
118#define NUMBER_TIME_SLOTS_512LD  8
119#define TRANSIENT_OFFSET_LD      0
120
121
122
123/*
124system constants: AAC+SBR or aacPRO (hybrid format), Standard Frame-Length, Multi-Rate
125---------------------------------------------------------------------------
126Number of slots (numberTimeSlots): 16  (NUMBER_TIME_SLOTS_2048)
127Detector-offset (frameMiddleSlot):  4
128Overlap                          :  3
129Buffer-offset                    :  8  (BUFFER_FRAME_START_2048 = 0)
130
131
132                        |<------------tranPos---------->|
133                |c|d|e|f|0|1|2|3|4|5|6|7|8|9|a|b|c|d|e|f|
134        FixFix  |                               |
135        FixVar  |                               :<- ->:
136        VarFix  :<- ->:                         |
137        VarVar  :<- ->:                         :<- ->:
138                0 1 2 3 4 5 6 7 8 9 a b c d e f 0 1 2 3
139................................................................................
140
141|-|-|-|-|-|-|-|-B-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-B-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|-|
142
143frame-generator:0                               16              24              32
144analysis-buffer:8                               24              32              40
145*/
146#define FRAME_MIDDLE_SLOT_2048  4
147#define NUMBER_TIME_SLOTS_2048  16
148
149
150/*
151system constants: mp3PRO, Multi-Rate & Single-Rate
152--------------------------------------------------
153Number of slots (numberTimeSlots):  9    (NUMBER_TIME_SLOTS_1152)
154Detector-offset (frameMiddleSlot):  4    (FRAME_MIDDLE_SLOT_1152)
155Overlap                          :  3
156Buffer-offset                    :  4.5  (BUFFER_FRAME_START_1152 = 0)
157
158
159                         |<----tranPos---->|
160                 |5|6|7|8|0|1|2|3|4|5|6|7|8|
161         FixFix  |                 |
162         FixVar  |                 :<- ->:
163         VarFix  :<- ->:           |
164         VarVar  :<- ->:           :<- ->:
165                 0 1 2 3 4 5 6 7 8 0 1 2 3
166        .............................................
167
168        -|-|-|-|-B-|-|-|-|-|-|-|-|-B-|-|-|-|-|-|-|-|-|
169
170frame-generator: 0                 9       13        18
171analysis-buffer: 4.5               13.5              22.5
172*/
173#define FRAME_MIDDLE_SLOT_1152  4
174#define NUMBER_TIME_SLOTS_1152  9
175
176
177/* system constants: Layer2+SBR */
178#define FRAME_MIDDLE_SLOT_2304  8
179#define NUMBER_TIME_SLOTS_2304  18
180
181
182/*!
183  \struct SBR_GRID
184  \brief  sbr_grid() signals to be converted to bitstream elements
185
186  The variables hold the signals (e.g. lengths and numbers) in "clear text"
187*/
188
189typedef struct
190{
191  /* system constants */
192  INT bufferFrameStart;     /*!< frame generator vs analysis buffer time alignment (currently set to 0, offset added elsewhere) */
193  INT numberTimeSlots;      /*!< number of SBR timeslots per frame */
194
195  /* will be adjusted for every frame */
196  FRAME_CLASS frameClass;   /*!< SBR frame class  */
197  INT bs_num_env;           /*!< bs_num_env, number of envelopes for FIXFIX */
198  INT bs_abs_bord;          /*!< bs_abs_bord, absolute border for VARFIX and FIXVAR */
199  INT n;                    /*!< number of relative borders for VARFIX and FIXVAR   */
200  INT p;                    /*!< pointer-to-transient-border  */
201  INT bs_rel_bord[MAX_NUM_REL];         /*!< bs_rel_bord, relative borders for all VAR */
202  INT v_f[MAX_ENVELOPES_FIXVAR_VARFIX]; /*!< envelope frequency resolutions for FIXVAR and VARFIX  */
203
204  INT bs_abs_bord_0;        /*!< bs_abs_bord_0, leading absolute border for VARVAR */
205  INT bs_abs_bord_1;        /*!< bs_abs_bord_1, trailing absolute border for VARVAR */
206  INT bs_num_rel_0;         /*!< bs_num_rel_0, number of relative borders associated with leading absolute border for VARVAR */
207  INT bs_num_rel_1;         /*!< bs_num_rel_1, number of relative borders associated with trailing absolute border for VARVAR */
208  INT bs_rel_bord_0[MAX_NUM_REL];       /*!< bs_rel_bord_0, relative borders associated with leading absolute border for VARVAR */
209  INT bs_rel_bord_1[MAX_NUM_REL];       /*!< bs_rel_bord_1, relative borders associated with trailing absolute border for VARVAR */
210  INT v_fLR[MAX_ENVELOPES_VARVAR];      /*!< envelope frequency resolutions for VARVAR  */
211
212}
213SBR_GRID;
214typedef SBR_GRID *HANDLE_SBR_GRID;
215
216
217
218/*!
219  \struct SBR_FRAME_INFO
220  \brief  time/frequency grid description for one frame
221*/
222typedef struct
223{
224  INT nEnvelopes;                         /*!< number of envelopes */
225  INT borders[MAX_ENVELOPES+1];           /*!< envelope borders in SBR timeslots */
226  FREQ_RES freqRes[MAX_ENVELOPES];        /*!< frequency resolution of each envelope */
227  INT shortEnv;                           /*!< number of an envelope to be shortened (starting at 1) or 0 for no shortened envelope */
228  INT nNoiseEnvelopes;                    /*!< number of noise floors */
229  INT bordersNoise[MAX_NOISE_ENVELOPES+1];/*!< noise floor borders in SBR timeslots */
230}
231SBR_FRAME_INFO;
232/* WARNING: When rearranging the elements of this struct keep in mind that the static
233 * initializations in the corresponding C-file have to be rearranged as well!
234 * snd 2002/01/23
235 */
236typedef SBR_FRAME_INFO *HANDLE_SBR_FRAME_INFO;
237
238
239/*!
240  \struct SBR_ENVELOPE_FRAME
241  \brief  frame generator main struct
242
243  Contains tuning parameters, time/frequency grid description, sbr_grid() bitstream elements, and generator internal signals
244*/
245typedef struct
246{
247  /* system constants */
248  INT frameMiddleSlot;      /*!< transient detector offset in SBR timeslots */
249
250  /* basic tuning parameters */
251  INT staticFraming;        /*!< 1: run static framing in time, i.e. exclusive use of bs_frame_class = FIXFIX */
252  INT numEnvStatic;         /*!< number of envelopes per frame for static framing */
253  INT freq_res_fixfix;      /*!< envelope frequency resolution to use for bs_frame_class = FIXFIX */
254
255  /* expert tuning parameters */
256  const int *v_tuningSegm;  /*!< segment lengths to use around transient */
257  const int *v_tuningFreq;  /*!< frequency resolutions to use around transient */
258  INT dmin;                 /*!< minimum length of dependent segments */
259  INT dmax;                 /*!< maximum length of dependent segments */
260  INT allowSpread;          /*!< 1: allow isolated transient to influence grid of 3 consecutive frames */
261
262  /* internally used signals */
263  FRAME_CLASS frameClassOld;                /*!< frame class used for previous frame */
264  INT spreadFlag;                           /*!< 1: use VARVAR instead of VARFIX to follow up old transient */
265
266  INT v_bord[2 * MAX_ENVELOPES_VARVAR + 1]; /*!< borders for current frame and preliminary borders for next frame (fixed borders excluded) */
267  INT length_v_bord;                        /*!< helper variable: length of v_bord */
268  INT v_freq[2 * MAX_ENVELOPES_VARVAR + 1]; /*!< frequency resolutions for current frame and preliminary resolutions for next frame */
269  INT length_v_freq;                        /*!< helper variable: length of v_freq */
270
271  INT v_bordFollow[MAX_ENVELOPES_VARVAR];   /*!< preliminary borders for current frame (calculated during previous frame) */
272  INT length_v_bordFollow;                  /*!< helper variable: length of v_bordFollow */
273  INT i_tranFollow;                         /*!< points to transient border in v_bordFollow (may be negative, see keepForFollowUp()) */
274  INT i_fillFollow;                         /*!< points to first fill border in v_bordFollow */
275  INT v_freqFollow[MAX_ENVELOPES_VARVAR];   /*!< preliminary frequency resolutions for current frame (calculated during previous frame) */
276  INT length_v_freqFollow;                  /*!< helper variable: length of v_freqFollow */
277
278
279  /* externally needed signals */
280  SBR_GRID         SbrGrid;         /*!< sbr_grid() signals to be converted to bitstream elements */
281  SBR_FRAME_INFO   SbrFrameInfo;    /*!< time/frequency grid description for one frame */
282}
283SBR_ENVELOPE_FRAME;
284typedef SBR_ENVELOPE_FRAME *HANDLE_SBR_ENVELOPE_FRAME;
285
286
287
288void
289FDKsbrEnc_initFrameInfoGenerator (HANDLE_SBR_ENVELOPE_FRAME  hSbrEnvFrame,
290                          INT allowSpread,
291                          INT numEnvStatic,
292                          INT staticFraming,
293                          INT timeSlots,
294                          INT freq_res_fixfix
295                          ,int ldGrid
296                          );
297
298HANDLE_SBR_FRAME_INFO
299FDKsbrEnc_frameInfoGenerator (HANDLE_SBR_ENVELOPE_FRAME hSbrEnvFrame,
300                    UCHAR *v_transient_info,
301                    UCHAR *v_transient_info_pre,
302                    int ldGrid,
303                    const int *v_tuning);
304
305#endif
306