Home | History | Annotate | Download | only in src
      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 /**************************** AAC decoder library ******************************
     96 
     97    Author(s):   Matthias Hildenbrand
     98 
     99    Description: USAC ACELP frame decoder
    100 
    101 *******************************************************************************/
    102 
    103 #ifndef USACDEC_ACELP_H
    104 #define USACDEC_ACELP_H
    105 
    106 #include "common_fix.h"
    107 #include "FDK_bitstream.h"
    108 #include "usacdec_const.h"
    109 #include "usacdec_rom.h"
    110 
    111 //#define ENHANCED_TCX_TD_CONCEAL_ENABLE
    112 
    113 /** Structure which holds the ACELP internal persistent memory */
    114 typedef struct {
    115   FIXP_DBL old_exc_mem[PIT_MAX_MAX + L_INTERPOL];
    116   FIXP_DBL old_syn_mem[M_LP_FILTER_ORDER]; /* synthesis filter states */
    117   FIXP_SGL A[M_LP_FILTER_ORDER];
    118   INT A_exp;
    119   FIXP_DBL gc_threshold;
    120   FIXP_DBL de_emph_mem;
    121   FIXP_SGL past_gpit;
    122   FIXP_DBL past_gcode;
    123   USHORT old_T0;
    124   UCHAR old_T0_frac;
    125   FIXP_DBL deemph_mem_wsyn;
    126   FIXP_DBL wsyn_rms;
    127   SHORT seed_ace;
    128 } CAcelpStaticMem;
    129 
    130 /** Structure which holds the parameter data needed to decode one ACELP frame.
    131  */
    132 typedef struct {
    133   UCHAR
    134   acelp_core_mode;   /**< mean excitation energy index for whole ACELP frame
    135                       */
    136   UCHAR mean_energy; /**< acelp core mode for whole ACELP frame */
    137   USHORT T0[NB_SUBFR];
    138   UCHAR T0_frac[NB_SUBFR];
    139   UCHAR ltp_filtering_flag[NB_SUBFR]; /**< controlls whether LTP postfilter is
    140                                          active for each ACELP subframe */
    141   SHORT icb_index[NB_SUBFR]
    142                  [8]; /**< innovative codebook index for each ACELP subframe */
    143   UCHAR gains[NB_SUBFR]; /**< gain index for each ACELP subframe */
    144 } CAcelpChannelData;
    145 
    146 /**
    147  * \brief Read the acelp_coding() bitstream part.
    148  * \param[in] hBs bitstream handle to read data from.
    149  * \param[out] acelpData pointer to structure to store the parsed data of one
    150  * ACELP frame.
    151  * \param[in] acelp_core_mode the ACELP core mode index.
    152  * \param[in] coreCoderFrameLength length of core coder frame (1024|768)
    153  */
    154 INT CLpd_AcelpRead(HANDLE_FDK_BITSTREAM hBs, CAcelpChannelData *acelpData,
    155                    INT acelp_core_mode, INT i_offset, INT coreCoderFrameLength);
    156 /**
    157  * \brief Initialization of memory before one LPD frame is decoded
    158  * \param[out] synth_buf synthesis buffer to be initialized, exponent = SF_SYNTH
    159  * \param[in] old_synth past synthesis of previous LPD frame, exponent =
    160  * SF_SYNTH
    161  * \param[out] synth_buf_fb fullband synthesis buffer to be initialized,
    162  * exponent = SF_SYNTH
    163  * \param[in] old_synth_fb past fullband synthesis of previous LPD frame,
    164  * exponent = SF_SYNTH
    165  * \param[out] pitch vector where decoded pitch lag values are stored
    166  * \param[in] old_T_pf past pitch lag values of previous LPD frame
    167  * \param[in] samplingRate sampling rate for pitch lag offset calculation
    168  * \param[out] i_offset pitch lag offset for the decoding of the pitch lag
    169  * \param[in] coreCoderFrameLength length of core coder frame (1024|768)
    170  */
    171 void Acelp_PreProcessing(FIXP_DBL *synth_buf, FIXP_DBL *old_synth, INT *pitch,
    172                          INT *old_T_pf, FIXP_DBL *pit_gain,
    173                          FIXP_DBL *old_gain_pf, INT samplingRate, INT *i_offset,
    174                          INT coreCoderFrameLength, INT synSfd,
    175                          INT nbSubfrSuperfr);
    176 
    177 /**
    178  * \brief Save tail of buffers for the initialization of the next LPD frame
    179  * \param[in] synth_buf synthesis of current LPD frame, exponent = SF_SYNTH
    180  * \param[out] old_synth memory where tail of fullband synth_buf is stored,
    181  * exponent = SF_SYNTH
    182  * \param[in] synth_buf_fb fullband synthesis of current LPD frame, exponent =
    183  * SF_SYNTH
    184  * \param[out] old_synth_fb memory where tail of fullband synth_buf is stored,
    185  * exponent = SF_SYNTH
    186  * \param[in] pitch decoded pitch lag values of current LPD frame
    187  * \param[out] old_T_pf memory where last SYN_SFD pitch lag values are stored
    188  */
    189 void Acelp_PostProcessing(FIXP_DBL *synth_buf, FIXP_DBL *old_synth, INT *pitch,
    190                           INT *old_T_pf, INT coreCoderFrameLength, INT synSfd,
    191                           INT nbSubfrSuperfr);
    192 
    193 /**
    194  * \brief Decode one ACELP frame (three or four ACELP subframes with 64 samples
    195  * each)
    196  * \param[in,out] acelp_mem pointer to ACELP memory structure
    197  * \param[in] i_offset pitch lag offset
    198  * \param[in] lsp_old LPC filter in LSP domain corresponding to previous frame
    199  * \param[in] lsp_new LPC filter in LSP domain corresponding to current frame
    200  * \param[in] stab_fac stability factor constrained by 0<=stab_fac<=1.0,
    201  * exponent = SF_STAB
    202  * \param[in] acelpData pointer to struct with data which is needed for decoding
    203  * one ACELP frame
    204  * \param[out] synth ACELP output signal
    205  * \param[out] pT four decoded pitch lag values
    206  * \param[in] coreCoderFrameLength length of core coder frame (1024|768)
    207  */
    208 void CLpd_AcelpDecode(CAcelpStaticMem *acelp_mem, INT i_offset,
    209                       const FIXP_LPC lsp_old[M_LP_FILTER_ORDER],
    210                       const FIXP_LPC lsp_new[M_LP_FILTER_ORDER],
    211                       FIXP_SGL stab_fac, CAcelpChannelData *acelpData,
    212                       INT numLostSubframes, int lastLpcLost, int frameCnt,
    213                       FIXP_DBL synth[], int pT[], FIXP_DBL *pit_gain,
    214                       INT coreCoderFrameLength);
    215 
    216 /**
    217  * \brief Reset ACELP internal memory.
    218  * \param[out] acelp_mem pointer to ACELP memory structure
    219  */
    220 void CLpd_AcelpReset(CAcelpStaticMem *acelp_mem);
    221 
    222 /**
    223  * \brief Initialize ACELP internal memory in case of FAC before ACELP decoder
    224  * is called
    225  * \param[in] synth points to end+1 of past valid synthesis signal, exponent =
    226  * SF_SYNTH
    227  * \param[in] last_lpd_mode last lpd mode
    228  * \param[in] last_last_lpd_mode lpd mode before last_lpd_mode
    229  * \param[in] A_new LP synthesis filter coeffs corresponding to last frame,
    230  * exponent = SF_A_COEFFS
    231  * \param[in] A_old LP synthesis filter coeffs corresponding to the frame before
    232  * last frame, exponent = SF_A_COEFFS
    233  * \param[in,out] acelp_mem pointer to ACELP memory structure
    234  * \param[in] coreCoderFrameLength length of core coder frame (1024|768)
    235  */
    236 void CLpd_AcelpPrepareInternalMem(const FIXP_DBL *synth, UCHAR last_lpd_mode,
    237                                   UCHAR last_last_lpd_mode,
    238                                   const FIXP_LPC *A_new, const INT A_new_exp,
    239                                   const FIXP_LPC *A_old, const INT A_old_exp,
    240                                   CAcelpStaticMem *acelp_mem,
    241                                   INT coreCoderFrameLength, INT clearOldExc,
    242                                   UCHAR lpd_mode);
    243 
    244 /**
    245  * \brief Calculate zero input response (zir) of the acelp synthesis filter
    246  * \param[in] A LP synthesis filter coefficients, exponent = SF_A_COEFFS
    247  * \param[in,out] acelp_mem pointer to ACELP memory structure
    248  * \param[in] length length of zir
    249  * \param[out] zir pointer to zir output buffer, exponent = SF_SYNTH
    250  */
    251 void CLpd_Acelp_Zir(const FIXP_LPC A[], const INT A_exp,
    252                     CAcelpStaticMem *acelp_mem, const INT length,
    253                     FIXP_DBL zir[], int doDeemph);
    254 
    255 /**
    256  * \brief Borrow static excitation memory from ACELP decoder
    257  * \param[in] acelp_mem pointer to ACELP memory structure
    258  * \param[in] length number of requested FIXP_DBL values
    259  * \return pointer to requested memory
    260  *
    261  * The caller has to take care not to overwrite valid memory areas.
    262  * During TCX/FAC calculations and before CLpd_AcelpPrepareInternalMem() is
    263  * called, the following memory size is available:
    264  * - 256 samples in case of ACELP -> TCX20 -> ACELP transition
    265  * - PIT_MAX_MAX+L_INTERPOL samples in all other cases
    266  */
    267 FIXP_DBL *CLpd_ACELP_GetFreeExcMem(CAcelpStaticMem *acelp_mem, INT length);
    268 
    269 void CLpd_TcxTDConceal(CAcelpStaticMem *acelp_mem, SHORT *pitch,
    270                        const FIXP_LPC lsp_old[M_LP_FILTER_ORDER],
    271                        const FIXP_LPC lsp_new[M_LP_FILTER_ORDER],
    272                        const FIXP_SGL stab_fac, INT numLostSubframes,
    273                        FIXP_DBL synth[], INT coreCoderFrameLength,
    274                        UCHAR last_tcx_noise_factor);
    275 
    276 inline SHORT E_UTIL_random(SHORT *seed) {
    277   *seed = (SHORT)((((LONG)*seed * (LONG)31821) >> 1) + (LONG)13849);
    278   return (*seed);
    279 }
    280 
    281 #endif /* USACDEC_ACELP_H */
    282