Home | History | Annotate | Download | only in include
      1 /* -----------------------------------------------------------------------------
      2 Software License for The Fraunhofer FDK AAC Codec Library for Android
      3 
      4  Copyright  1995 - 2018 Fraunhofer-Gesellschaft zur Frderung 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 (at) 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 
    120 #define FIXP_QSS FIXP_DBL
    121 #define QSS_BITS DFRACT_BITS
    122 
    123 /* Flags for QMF intialization */
    124 /* Low Power mode flag */
    125 #define QMF_FLAG_LP 1
    126 /* Filter is not symmetric. This flag is set internally in the QMF
    127  * initialization as required. */
    128 /* DO NOT PASS THIS FLAG TO qmfInitAnalysisFilterBank or
    129  * qmfInitSynthesisFilterBank */
    130 #define QMF_FLAG_NONSYMMETRIC 2
    131 /* Complex Low Delay Filter Bank (or std symmetric filter bank) */
    132 #define QMF_FLAG_CLDFB 4
    133 /* Flag indicating that the states should be kept. */
    134 #define QMF_FLAG_KEEP_STATES 8
    135 /* Complex Low Delay Filter Bank used in MPEG Surround Encoder */
    136 #define QMF_FLAG_MPSLDFB 16
    137 /* Complex Low Delay Filter Bank used in MPEG Surround Encoder allows a
    138  * optimized calculation of the modulation in qmfForwardModulationHQ() */
    139 #define QMF_FLAG_MPSLDFB_OPTIMIZE_MODULATION 32
    140 /* Flag to indicate HE-AAC down-sampled SBR mode (decoder) -> adapt analysis
    141  * post twiddling */
    142 #define QMF_FLAG_DOWNSAMPLED 64
    143 
    144 #define QMF_MAX_SYNTHESIS_BANDS (64)
    145 
    146 /*!
    147  * \brief Algorithmic scaling in sbrForwardModulation()
    148  *
    149  * The scaling in sbrForwardModulation() is caused by:
    150  *
    151  *   \li 1 R_SHIFT in sbrForwardModulation()
    152  *   \li 5/6 R_SHIFT in dct3() if using 32/64 Bands
    153  *   \li 1 omitted gain of 2.0 in qmfForwardModulation()
    154  */
    155 #define ALGORITHMIC_SCALING_IN_ANALYSIS_FILTERBANK 7
    156 
    157 /*!
    158  * \brief Algorithmic scaling in cplxSynthesisQmfFiltering()
    159  *
    160  * The scaling in cplxSynthesisQmfFiltering() is caused by:
    161  *
    162  *   \li  5/6 R_SHIFT in dct2() if using 32/64 Bands
    163  *   \li  1 omitted gain of 2.0 in qmfInverseModulation()
    164  *   \li -6 division by 64 in synthesis filterbank
    165  *   \li x bits external influence
    166  */
    167 #define ALGORITHMIC_SCALING_IN_SYNTHESIS_FILTERBANK 1
    168 
    169 typedef struct {
    170   int lb_scale;    /*!< Scale of low band area                   */
    171   int ov_lb_scale; /*!< Scale of adjusted overlap low band area  */
    172   int hb_scale;    /*!< Scale of high band area                  */
    173   int ov_hb_scale; /*!< Scale of adjusted overlap high band area */
    174 } QMF_SCALE_FACTOR;
    175 
    176 struct QMF_FILTER_BANK {
    177   const FIXP_PFT *p_filter; /*!< Pointer to filter coefficients */
    178 
    179   void *FilterStates;    /*!< Pointer to buffer of filter states
    180                               FIXP_PCM in analyse and
    181                               FIXP_DBL in synthesis filter */
    182   int FilterSize;        /*!< Size of prototype filter. */
    183   const FIXP_QTW *t_cos; /*!< Modulation tables. */
    184   const FIXP_QTW *t_sin;
    185   int filterScale; /*!< filter scale */
    186 
    187   int no_channels; /*!< Total number of channels (subbands) */
    188   int no_col;      /*!< Number of time slots       */
    189   int lsb;         /*!< Top of low subbands */
    190   int usb;         /*!< Top of high subbands */
    191 
    192   int synScalefactor; /*!< Scale factor of synthesis qmf (syn only) */
    193   int outScalefactor; /*!< Scale factor of output data (syn only) */
    194   FIXP_DBL outGain_m; /*!< Mantissa of gain output data (syn only) (init with
    195                          0x80000000 to ignore) */
    196   int outGain_e;      /*!< Exponent of gain output data (syn only) */
    197 
    198   UINT flags;     /*!< flags */
    199   UCHAR p_stride; /*!< Stride Factor of polyphase filters */
    200 };
    201 
    202 typedef struct QMF_FILTER_BANK *HANDLE_QMF_FILTER_BANK;
    203 
    204 void qmfAnalysisFiltering(
    205     HANDLE_QMF_FILTER_BANK anaQmf, /*!< Handle of Qmf Analysis Bank   */
    206     FIXP_DBL **qmfReal,            /*!< Pointer to real subband slots */
    207     FIXP_DBL **qmfImag,            /*!< Pointer to imag subband slots */
    208     QMF_SCALE_FACTOR *scaleFactor, /*!< Scale factors of QMF data     */
    209     const LONG *timeIn,            /*!< Time signal */
    210     const int timeIn_e,            /*!< Exponent of audio data        */
    211     const int stride,              /*!< Stride factor of audio data   */
    212     FIXP_DBL *pWorkBuffer          /*!< pointer to temporary working buffer */
    213 );
    214 
    215 void qmfAnalysisFiltering(
    216     HANDLE_QMF_FILTER_BANK anaQmf, /*!< Handle of Qmf Analysis Bank   */
    217     FIXP_DBL **qmfReal,            /*!< Pointer to real subband slots */
    218     FIXP_DBL **qmfImag,            /*!< Pointer to imag subband slots */
    219     QMF_SCALE_FACTOR *scaleFactor, /*!< Scale factors of QMF data     */
    220     const INT_PCM *timeIn,         /*!< Time signal */
    221     const int timeIn_e,            /*!< Exponent of audio data        */
    222     const int stride,              /*!< Stride factor of audio data   */
    223     FIXP_DBL *pWorkBuffer          /*!< pointer to temporal working buffer */
    224 );
    225 
    226 void qmfSynthesisFiltering(
    227     HANDLE_QMF_FILTER_BANK synQmf,       /*!< Handle of Qmf Synthesis Bank  */
    228     FIXP_DBL **QmfBufferReal,            /*!< Pointer to real subband slots */
    229     FIXP_DBL **QmfBufferImag,            /*!< Pointer to imag subband slots */
    230     const QMF_SCALE_FACTOR *scaleFactor, /*!< Scale factors of QMF data     */
    231     const int ov_len,                    /*!< Length of band overlap        */
    232     INT_PCM *timeOut,                    /*!< Time signal */
    233     const INT stride,                    /*!< Stride factor of audio data   */
    234     FIXP_DBL *pWorkBuffer /*!< pointer to temporary working buffer. It must be
    235                              aligned */
    236 );
    237 
    238 int qmfInitAnalysisFilterBank(
    239     HANDLE_QMF_FILTER_BANK h_Qmf, /*!< QMF Handle */
    240     FIXP_QAS *pFilterStates,      /*!< Pointer to filter state buffer */
    241     int noCols,                   /*!< Number of time slots  */
    242     int lsb,                      /*!< Number of lower bands */
    243     int usb,                      /*!< Number of upper bands */
    244     int no_channels,              /*!< Number of critically sampled bands */
    245     int flags);                   /*!< Flags */
    246 
    247 void qmfAnalysisFilteringSlot(
    248     HANDLE_QMF_FILTER_BANK anaQmf, /*!< Handle of Qmf Synthesis Bank  */
    249     FIXP_DBL *qmfReal,             /*!< Low and High band, real */
    250     FIXP_DBL *qmfImag,             /*!< Low and High band, imag */
    251     const LONG *timeIn,            /*!< Pointer to input */
    252     const int stride,              /*!< stride factor of input */
    253     FIXP_DBL *pWorkBuffer          /*!< pointer to temporary working buffer */
    254 );
    255 
    256 void qmfAnalysisFilteringSlot(
    257     HANDLE_QMF_FILTER_BANK anaQmf, /*!< Handle of Qmf Synthesis Bank  */
    258     FIXP_DBL *qmfReal,             /*!< Low and High band, real */
    259     FIXP_DBL *qmfImag,             /*!< Low and High band, imag */
    260     const INT_PCM *timeIn,         /*!< Pointer to input */
    261     const int stride,              /*!< stride factor of input */
    262     FIXP_DBL *pWorkBuffer          /*!< pointer to temporal working buffer */
    263 );
    264 int qmfInitSynthesisFilterBank(
    265     HANDLE_QMF_FILTER_BANK h_Qmf, /*!< QMF Handle */
    266     FIXP_QSS *pFilterStates,      /*!< Pointer to filter state buffer */
    267     int noCols,                   /*!< Number of time slots  */
    268     int lsb,                      /*!< Number of lower bands */
    269     int usb,                      /*!< Number of upper bands */
    270     int no_channels,              /*!< Number of critically sampled bands */
    271     int flags);                   /*!< Flags */
    272 
    273 void qmfSynthesisFilteringSlot(HANDLE_QMF_FILTER_BANK synQmf,
    274                                const FIXP_DBL *realSlot,
    275                                const FIXP_DBL *imagSlot,
    276                                const int scaleFactorLowBand,
    277                                const int scaleFactorHighBand, INT_PCM *timeOut,
    278                                const int timeOut_e, FIXP_DBL *pWorkBuffer);
    279 
    280 void qmfChangeOutScalefactor(
    281     HANDLE_QMF_FILTER_BANK synQmf, /*!< Handle of Qmf Synthesis Bank */
    282     int outScalefactor             /*!< New scaling factor for output data */
    283 );
    284 
    285 int qmfGetOutScalefactor(
    286     HANDLE_QMF_FILTER_BANK synQmf /*!< Handle of Qmf Synthesis Bank */
    287 );
    288 
    289 void qmfChangeOutGain(
    290     HANDLE_QMF_FILTER_BANK synQmf, /*!< Handle of Qmf Synthesis Bank */
    291     FIXP_DBL outputGain,           /*!< New gain for output data (mantissa) */
    292     int outputGainScale            /*!< New gain for output data (exponent) */
    293 );
    294 void qmfSynPrototypeFirSlot(
    295     HANDLE_QMF_FILTER_BANK qmf,
    296     FIXP_DBL *RESTRICT realSlot, /*!< Input: Pointer to real Slot */
    297     FIXP_DBL *RESTRICT imagSlot, /*!< Input: Pointer to imag Slot */
    298     INT_PCM *RESTRICT timeOut,   /*!< Time domain data */
    299     const int timeOut_e);
    300 
    301 #endif /*ifndef QMF_H       */
    302