1 /* ----------------------------------------------------------------------------- 2 Software License for The Fraunhofer FDK AAC Codec Library for Android 3 4 © Copyright 1995 - 2019 Fraunhofer-Gesellschaft zur Förderung der angewandten 5 Forschung e.V. All rights reserved. 6 7 1. INTRODUCTION 8 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software 9 that implements the MPEG Advanced Audio Coding ("AAC") encoding and decoding 10 scheme for digital audio. This FDK AAC Codec software is intended to be used on 11 a wide variety of Android devices. 12 13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient 14 general perceptual audio codecs. AAC-ELD is considered the best-performing 15 full-bandwidth communications codec by independent studies and is widely 16 deployed. AAC has been standardized by ISO and IEC as part of the MPEG 17 specifications. 18 19 Patent licenses for necessary patent claims for the FDK AAC Codec (including 20 those of Fraunhofer) may be obtained through Via Licensing 21 (www.vialicensing.com) or through the respective patent owners individually for 22 the purpose of encoding or decoding bit streams in products that are compliant 23 with the ISO/IEC MPEG audio standards. Please note that most manufacturers of 24 Android devices already license these patent claims through Via Licensing or 25 directly from the patent owners, and therefore FDK AAC Codec software may 26 already be covered under those patent licenses when it is used for those 27 licensed purposes only. 28 29 Commercially-licensed AAC software libraries, including floating-point versions 30 with enhanced sound quality, are also available from Fraunhofer. Users are 31 encouraged to check the Fraunhofer website for additional applications 32 information and documentation. 33 34 2. COPYRIGHT LICENSE 35 36 Redistribution and use in source and binary forms, with or without modification, 37 are permitted without payment of copyright license fees provided that you 38 satisfy the following conditions: 39 40 You must retain the complete text of this software license in redistributions of 41 the FDK AAC Codec or your modifications thereto in source code form. 42 43 You must retain the complete text of this software license in the documentation 44 and/or other materials provided with redistributions of the FDK AAC Codec or 45 your modifications thereto in binary form. You must make available free of 46 charge copies of the complete source code of the FDK AAC Codec and your 47 modifications thereto to recipients of copies in binary form. 48 49 The name of Fraunhofer may not be used to endorse or promote products derived 50 from this library without prior written permission. 51 52 You may not charge copyright license fees for anyone to use, copy or distribute 53 the FDK AAC Codec software or your modifications thereto. 54 55 Your modified versions of the FDK AAC Codec must carry prominent notices stating 56 that you changed the software and the date of any change. For modified versions 57 of the FDK AAC Codec, the term "Fraunhofer FDK AAC Codec Library for Android" 58 must be replaced by the term "Third-Party Modified Version of the Fraunhofer FDK 59 AAC Codec Library for Android." 60 61 3. NO PATENT LICENSE 62 63 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without 64 limitation the patents of Fraunhofer, ARE GRANTED BY THIS SOFTWARE LICENSE. 65 Fraunhofer provides no warranty of patent non-infringement with respect to this 66 software. 67 68 You may use this FDK AAC Codec software or modifications thereto only for 69 purposes that are authorized by appropriate patent licenses. 70 71 4. DISCLAIMER 72 73 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright 74 holders and contributors "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, 75 including but not limited to the implied warranties of merchantability and 76 fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 77 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, 78 or consequential damages, including but not limited to procurement of substitute 79 goods or services; loss of use, data, or profits, or business interruption, 80 however caused and on any theory of liability, whether in contract, strict 81 liability, or tort (including negligence), arising in any way out of the use of 82 this software, even if advised of the possibility of such damage. 83 84 5. CONTACT INFORMATION 85 86 Fraunhofer Institute for Integrated Circuits IIS 87 Attention: Audio and Multimedia Departments - FDK AAC LL 88 Am Wolfsmantel 33 89 91058 Erlangen, Germany 90 91 www.iis.fraunhofer.de/amm 92 amm-info@iis.fraunhofer.de 93 ----------------------------------------------------------------------------- */ 94 95 /******************* Library for basic calculation routines ******************** 96 97 Author(s): 98 99 Description: 100 101 *******************************************************************************/ 102 103 /*! 104 \file qmf.h 105 \brief Complex qmf analysis/synthesis 106 \author Markus Werner 107 108 */ 109 110 #ifndef QMF_H 111 #define QMF_H 112 113 #include "common_fix.h" 114 #include "FDK_tools_rom.h" 115 #include "dct.h" 116 117 #define FIXP_QAS FIXP_PCM 118 #define QAS_BITS SAMPLE_BITS 119 #define INT_PCM_QMFIN INT_PCM 120 121 #define FIXP_QSS FIXP_DBL 122 #define QSS_BITS DFRACT_BITS 123 124 /* Flags for QMF intialization */ 125 /* Low Power mode flag */ 126 #define QMF_FLAG_LP 1 127 /* Filter is not symmetric. This flag is set internally in the QMF 128 * initialization as required. */ 129 /* DO NOT PASS THIS FLAG TO qmfInitAnalysisFilterBank or 130 * qmfInitSynthesisFilterBank */ 131 #define QMF_FLAG_NONSYMMETRIC 2 132 /* Complex Low Delay Filter Bank (or std symmetric filter bank) */ 133 #define QMF_FLAG_CLDFB 4 134 /* Flag indicating that the states should be kept. */ 135 #define QMF_FLAG_KEEP_STATES 8 136 /* Complex Low Delay Filter Bank used in MPEG Surround Encoder */ 137 #define QMF_FLAG_MPSLDFB 16 138 /* Complex Low Delay Filter Bank used in MPEG Surround Encoder allows a 139 * optimized calculation of the modulation in qmfForwardModulationHQ() */ 140 #define QMF_FLAG_MPSLDFB_OPTIMIZE_MODULATION 32 141 /* Flag to indicate HE-AAC down-sampled SBR mode (decoder) -> adapt analysis 142 * post twiddling */ 143 #define QMF_FLAG_DOWNSAMPLED 64 144 145 #define QMF_MAX_SYNTHESIS_BANDS (64) 146 147 /*! 148 * \brief Algorithmic scaling in sbrForwardModulation() 149 * 150 * The scaling in sbrForwardModulation() is caused by: 151 * 152 * \li 1 R_SHIFT in sbrForwardModulation() 153 * \li 5/6 R_SHIFT in dct3() if using 32/64 Bands 154 * \li 1 omitted gain of 2.0 in qmfForwardModulation() 155 */ 156 #define ALGORITHMIC_SCALING_IN_ANALYSIS_FILTERBANK 7 157 158 /*! 159 * \brief Algorithmic scaling in cplxSynthesisQmfFiltering() 160 * 161 * The scaling in cplxSynthesisQmfFiltering() is caused by: 162 * 163 * \li 5/6 R_SHIFT in dct2() if using 32/64 Bands 164 * \li 1 omitted gain of 2.0 in qmfInverseModulation() 165 * \li -6 division by 64 in synthesis filterbank 166 * \li x bits external influence 167 */ 168 #define ALGORITHMIC_SCALING_IN_SYNTHESIS_FILTERBANK 1 169 170 typedef struct { 171 int lb_scale; /*!< Scale of low band area */ 172 int ov_lb_scale; /*!< Scale of adjusted overlap low band area */ 173 int hb_scale; /*!< Scale of high band area */ 174 int ov_hb_scale; /*!< Scale of adjusted overlap high band area */ 175 } QMF_SCALE_FACTOR; 176 177 struct QMF_FILTER_BANK { 178 const FIXP_PFT *p_filter; /*!< Pointer to filter coefficients */ 179 180 void *FilterStates; /*!< Pointer to buffer of filter states 181 FIXP_PCM in analyse and 182 FIXP_DBL in synthesis filter */ 183 int FilterSize; /*!< Size of prototype filter. */ 184 const FIXP_QTW *t_cos; /*!< Modulation tables. */ 185 const FIXP_QTW *t_sin; 186 int filterScale; /*!< filter scale */ 187 188 int no_channels; /*!< Total number of channels (subbands) */ 189 int no_col; /*!< Number of time slots */ 190 int lsb; /*!< Top of low subbands */ 191 int usb; /*!< Top of high subbands */ 192 193 int synScalefactor; /*!< Scale factor of synthesis qmf (syn only) */ 194 int outScalefactor; /*!< Scale factor of output data (syn only) */ 195 FIXP_DBL outGain_m; /*!< Mantissa of gain output data (syn only) (init with 196 0x80000000 to ignore) */ 197 int outGain_e; /*!< Exponent of gain output data (syn only) */ 198 199 UINT flags; /*!< flags */ 200 UCHAR p_stride; /*!< Stride Factor of polyphase filters */ 201 }; 202 203 typedef struct QMF_FILTER_BANK *HANDLE_QMF_FILTER_BANK; 204 205 int qmfInitAnalysisFilterBank( 206 HANDLE_QMF_FILTER_BANK h_Qmf, /*!< QMF Handle */ 207 FIXP_QAS *pFilterStates, /*!< Pointer to filter state buffer */ 208 int noCols, /*!< Number of time slots */ 209 int lsb, /*!< Number of lower bands */ 210 int usb, /*!< Number of upper bands */ 211 int no_channels, /*!< Number of critically sampled bands */ 212 int flags); /*!< Flags */ 213 #if SAMPLE_BITS == 16 214 215 int qmfInitAnalysisFilterBank( 216 HANDLE_QMF_FILTER_BANK h_Qmf, /*!< QMF Handle */ 217 FIXP_DBL *pFilterStates, /*!< Pointer to filter state buffer */ 218 int noCols, /*!< Number of time slots */ 219 int lsb, /*!< Number of lower bands */ 220 int usb, /*!< Number of upper bands */ 221 int no_channels, /*!< Number of critically sampled bands */ 222 int flags); /*!< Flags */ 223 #endif 224 225 void qmfAnalysisFiltering( 226 HANDLE_QMF_FILTER_BANK anaQmf, /*!< Handle of Qmf Analysis Bank */ 227 FIXP_DBL **qmfReal, /*!< Pointer to real subband slots */ 228 FIXP_DBL **qmfImag, /*!< Pointer to imag subband slots */ 229 QMF_SCALE_FACTOR *scaleFactor, /*!< Scale factors of QMF data */ 230 const INT_PCM *timeIn, /*!< Time signal */ 231 const int timeIn_e, /*!< Exponent of audio data */ 232 const int stride, /*!< Stride factor of audio data */ 233 FIXP_DBL *pWorkBuffer /*!< pointer to temporal working buffer */ 234 ); 235 #if SAMPLE_BITS == 16 236 237 void qmfAnalysisFiltering( 238 HANDLE_QMF_FILTER_BANK anaQmf, /*!< Handle of Qmf Analysis Bank */ 239 FIXP_DBL **qmfReal, /*!< Pointer to real subband slots */ 240 FIXP_DBL **qmfImag, /*!< Pointer to imag subband slots */ 241 QMF_SCALE_FACTOR *scaleFactor, /*!< Scale factors of QMF data */ 242 const LONG *timeIn, /*!< Time signal */ 243 const int timeIn_e, /*!< Exponent of audio data */ 244 const int stride, /*!< Stride factor of audio data */ 245 FIXP_DBL *pWorkBuffer /*!< pointer to temporary working buffer */ 246 ); 247 #endif 248 249 void qmfAnalysisFilteringSlot( 250 HANDLE_QMF_FILTER_BANK anaQmf, /*!< Handle of Qmf Synthesis Bank */ 251 FIXP_DBL *qmfReal, /*!< Low and High band, real */ 252 FIXP_DBL *qmfImag, /*!< Low and High band, imag */ 253 const INT_PCM *timeIn, /*!< Pointer to input */ 254 const int stride, /*!< stride factor of input */ 255 FIXP_DBL *pWorkBuffer /*!< pointer to temporal working buffer */ 256 ); 257 #if SAMPLE_BITS == 16 258 259 void qmfAnalysisFilteringSlot( 260 HANDLE_QMF_FILTER_BANK anaQmf, /*!< Handle of Qmf Synthesis Bank */ 261 FIXP_DBL *qmfReal, /*!< Low and High band, real */ 262 FIXP_DBL *qmfImag, /*!< Low and High band, imag */ 263 const LONG *timeIn, /*!< Pointer to input */ 264 const int stride, /*!< stride factor of input */ 265 FIXP_DBL *pWorkBuffer /*!< pointer to temporary working buffer */ 266 ); 267 #endif 268 269 int qmfInitSynthesisFilterBank( 270 HANDLE_QMF_FILTER_BANK h_Qmf, /*!< QMF Handle */ 271 FIXP_QSS *pFilterStates, /*!< Pointer to filter state buffer */ 272 int noCols, /*!< Number of time slots */ 273 int lsb, /*!< Number of lower bands */ 274 int usb, /*!< Number of upper bands */ 275 int no_channels, /*!< Number of critically sampled bands */ 276 int flags); /*!< Flags */ 277 278 void qmfSynthesisFiltering( 279 HANDLE_QMF_FILTER_BANK synQmf, /*!< Handle of Qmf Synthesis Bank */ 280 FIXP_DBL **QmfBufferReal, /*!< Pointer to real subband slots */ 281 FIXP_DBL **QmfBufferImag, /*!< Pointer to imag subband slots */ 282 const QMF_SCALE_FACTOR *scaleFactor, /*!< Scale factors of QMF data */ 283 const int ov_len, /*!< Length of band overlap */ 284 INT_PCM *timeOut, /*!< Time signal */ 285 const INT stride, /*!< Stride factor of audio data */ 286 FIXP_DBL *pWorkBuffer /*!< pointer to temporary working buffer. It must be 287 aligned */ 288 ); 289 #if SAMPLE_BITS == 16 290 291 void qmfSynthesisFiltering( 292 HANDLE_QMF_FILTER_BANK synQmf, /*!< Handle of Qmf Synthesis Bank */ 293 FIXP_DBL **QmfBufferReal, /*!< Pointer to real subband slots */ 294 FIXP_DBL **QmfBufferImag, /*!< Pointer to imag subband slots */ 295 const QMF_SCALE_FACTOR *scaleFactor, /*!< Scale factors of QMF data */ 296 const int ov_len, /*!< Length of band overlap */ 297 LONG *timeOut, /*!< Time signal */ 298 const int timeOut_e, /*!< Target exponent for timeOut */ 299 FIXP_DBL *pWorkBuffer /*!< pointer to temporary working buffer */ 300 ); 301 #endif 302 303 void qmfSynthesisFilteringSlot(HANDLE_QMF_FILTER_BANK synQmf, 304 const FIXP_DBL *realSlot, 305 const FIXP_DBL *imagSlot, 306 const int scaleFactorLowBand, 307 const int scaleFactorHighBand, INT_PCM *timeOut, 308 const int timeOut_e, FIXP_DBL *pWorkBuffer); 309 #if SAMPLE_BITS == 16 310 311 void qmfSynthesisFilteringSlot(HANDLE_QMF_FILTER_BANK synQmf, 312 const FIXP_DBL *realSlot, 313 const FIXP_DBL *imagSlot, 314 const int scaleFactorLowBand, 315 const int scaleFactorHighBand, LONG *timeOut, 316 const int timeOut_e, FIXP_DBL *pWorkBuffer); 317 #endif 318 319 void qmfChangeOutScalefactor( 320 HANDLE_QMF_FILTER_BANK synQmf, /*!< Handle of Qmf Synthesis Bank */ 321 int outScalefactor /*!< New scaling factor for output data */ 322 ); 323 324 int qmfGetOutScalefactor( 325 HANDLE_QMF_FILTER_BANK synQmf /*!< Handle of Qmf Synthesis Bank */ 326 ); 327 328 void qmfChangeOutGain( 329 HANDLE_QMF_FILTER_BANK synQmf, /*!< Handle of Qmf Synthesis Bank */ 330 FIXP_DBL outputGain, /*!< New gain for output data (mantissa) */ 331 int outputGainScale /*!< New gain for output data (exponent) */ 332 ); 333 334 #endif /*ifndef QMF_H */ 335