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  SBR main definitions
87*/
88#ifndef __SBR_DEF_H
89#define __SBR_DEF_H
90
91#include "common_fix.h"
92
93#define noError 0
94#define HANDLE_ERROR_INFO INT
95#define ERROR(a,b) 1
96#define handBack
97
98/* #define SBR_ENV_STATISTICS_BITRATE */
99#undef SBR_ENV_STATISTICS_BITRATE
100
101/* #define SBR_ENV_STATISTICS */
102#undef SBR_ENV_STATISTICS
103
104/* #define SBR_PAYLOAD_MONITOR */
105#undef SBR_PAYLOAD_MONITOR
106
107#define SWAP(a,b)                               tempr=a, a=b, b=tempr
108#define TRUE  1
109#define FALSE 0
110
111
112/* Constants */
113#define EPS                                     1e-12
114#define LOG2                                    0.69314718056f  /* natural logarithm of 2 */
115#define ILOG2                                   1.442695041f    /* 1/LOG2 */
116#define RELAXATION_FLOAT                        (1e-6f)
117#define RELAXATION                              (FL2FXCONST_DBL(RELAXATION_FLOAT))
118#define RELAXATION_FRACT                        (FL2FXCONST_DBL(0.524288f))     /* 0.524288f is fractional part of RELAXATION */
119#define RELAXATION_SHIFT                        (19)
120#define RELAXATION_LD64                         (FL2FXCONST_DBL(0.31143075889f))/* (ld64(RELAXATION) */
121
122/************  Definitions ***************/
123#define SBR_COMP_MODE_DELTA                     0
124#define SBR_COMP_MODE_CTS                       1
125
126#define MAX_NUM_CHANNELS                        2
127
128#define MAX_NOISE_ENVELOPES                     2
129#define MAX_NUM_NOISE_COEFFS                    5
130#define MAX_NUM_NOISE_VALUES                    (MAX_NUM_NOISE_COEFFS*MAX_NOISE_ENVELOPES)
131
132#define MAX_NUM_ENVELOPE_VALUES                 (MAX_ENVELOPES * MAX_FREQ_COEFFS)
133#define MAX_ENVELOPES                           5
134#define MAX_FREQ_COEFFS                         48
135
136#define MAX_FREQ_COEFFS_FS44100                 35
137#define MAX_FREQ_COEFFS_FS48000                 32
138
139
140#define QMF_CHANNELS                            64
141#define QMF_FILTER_LENGTH                      640
142#define QMF_MAX_TIME_SLOTS                      32
143#define NO_OF_ESTIMATES_LC                      4
144#define NO_OF_ESTIMATES_LD                      3
145#define MAX_NO_OF_ESTIMATES                     4
146
147
148#define NOISE_FLOOR_OFFSET                      6
149#define NOISE_FLOOR_OFFSET_64                   (FL2FXCONST_DBL(0.09375f))
150
151#define LOW_RES                                 0
152#define HIGH_RES                                1
153
154#define LO                                      0
155#define HI                                      1
156
157#define LENGTH_SBR_FRAME_INFO                   35      /* 19 */
158
159#define SBR_NSFB_LOW_RES                        9       /*  8 */
160#define SBR_NSFB_HIGH_RES                       18      /* 16 */
161
162
163#define SBR_XPOS_CTRL_DEFAULT                   2
164
165#define SBR_FREQ_SCALE_DEFAULT                  2
166#define SBR_ALTER_SCALE_DEFAULT                 1
167#define SBR_NOISE_BANDS_DEFAULT                 2
168
169#define SBR_LIMITER_BANDS_DEFAULT               2
170#define SBR_LIMITER_GAINS_DEFAULT               2
171#define SBR_LIMITER_GAINS_INFINITE              3
172#define SBR_INTERPOL_FREQ_DEFAULT               1
173#define SBR_SMOOTHING_LENGTH_DEFAULT            0
174
175
176/* sbr_header */
177#define SI_SBR_AMP_RES_BITS                     1
178#define SI_SBR_COUPLING_BITS                    1
179#define SI_SBR_START_FREQ_BITS                  4
180#define SI_SBR_STOP_FREQ_BITS                   4
181#define SI_SBR_XOVER_BAND_BITS                  3
182#define SI_SBR_RESERVED_BITS                    2
183#define SI_SBR_DATA_EXTRA_BITS                  1
184#define SI_SBR_HEADER_EXTRA_1_BITS              1
185#define SI_SBR_HEADER_EXTRA_2_BITS              1
186
187/* sbr_header extra 1 */
188#define SI_SBR_FREQ_SCALE_BITS                  2
189#define SI_SBR_ALTER_SCALE_BITS                 1
190#define SI_SBR_NOISE_BANDS_BITS                 2
191
192/* sbr_header extra 2 */
193#define SI_SBR_LIMITER_BANDS_BITS               2
194#define SI_SBR_LIMITER_GAINS_BITS               2
195#define SI_SBR_INTERPOL_FREQ_BITS               1
196#define SI_SBR_SMOOTHING_LENGTH_BITS            1
197
198/* sbr_grid */
199#define SBR_CLA_BITS                            2   /*!< size of bs_frame_class */
200#define SBR_CLA_BITS_LD                         1   /*!< size of bs_frame_class */
201#define SBR_ENV_BITS                            2   /*!< size of bs_num_env_raw */
202#define SBR_ABS_BITS                            2   /*!< size of bs_abs_bord_raw for HE-AAC */
203#define SBR_NUM_BITS                            2   /*!< size of bs_num_rel */
204#define SBR_REL_BITS                            2   /*!< size of bs_rel_bord_raw */
205#define SBR_RES_BITS                            1   /*!< size of bs_freq_res_flag */
206#define SBR_DIR_BITS                            1   /*!< size of bs_df_flag */
207
208
209/* sbr_data */
210#define SI_SBR_INVF_MODE_BITS                   2
211
212
213#define SI_SBR_START_ENV_BITS_AMP_RES_3_0           6
214#define SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_3_0   5
215#define SI_SBR_START_NOISE_BITS_AMP_RES_3_0         5
216#define SI_SBR_START_NOISE_BITS_BALANCE_AMP_RES_3_0 5
217
218#define SI_SBR_START_ENV_BITS_AMP_RES_1_5           7
219#define SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_1_5   6
220
221
222#define SI_SBR_EXTENDED_DATA_BITS               1
223#define SI_SBR_EXTENSION_SIZE_BITS              4
224#define SI_SBR_EXTENSION_ESC_COUNT_BITS         8
225#define SI_SBR_EXTENSION_ID_BITS                2
226
227#define SBR_EXTENDED_DATA_MAX_CNT               (15+255)
228
229#define EXTENSION_ID_PS_CODING                  2
230
231/* Envelope coding constants */
232#define FREQ                      0
233#define TIME                      1
234
235
236/* huffman tables */
237#define CODE_BOOK_SCF_LAV00         60
238#define CODE_BOOK_SCF_LAV01         31
239#define CODE_BOOK_SCF_LAV10         60
240#define CODE_BOOK_SCF_LAV11         31
241#define CODE_BOOK_SCF_LAV_BALANCE11 12
242#define CODE_BOOK_SCF_LAV_BALANCE10 24
243
244typedef enum
245{
246  SBR_AMP_RES_1_5=0,
247  SBR_AMP_RES_3_0
248}
249AMP_RES;
250
251typedef enum
252{
253  XPOS_MDCT,
254  XPOS_MDCT_CROSS,
255  XPOS_LC,
256  XPOS_RESERVED,
257  XPOS_SWITCHED /* not a real choice but used here to control behaviour */
258}
259XPOS_MODE;
260
261typedef enum
262{
263  INVF_OFF = 0,
264  INVF_LOW_LEVEL,
265  INVF_MID_LEVEL,
266  INVF_HIGH_LEVEL,
267  INVF_SWITCHED /* not a real choice but used here to control behaviour */
268}
269INVF_MODE;
270
271typedef enum
272{
273  FREQ_RES_LOW = 0,
274  FREQ_RES_HIGH
275}
276FREQ_RES;
277
278
279#endif
280