Home | History | Annotate | Download | only in include
      1 /* -----------------------------------------------------------------------------
      2 Software License for The Fraunhofer FDK AAC Codec Library for Android
      3 
      4  Copyright  1995 - 2019 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: Scaling operations
    100 
    101 *******************************************************************************/
    102 
    103 #ifndef SCALE_H
    104 #define SCALE_H
    105 
    106 #include "common_fix.h"
    107 #include "genericStds.h"
    108 #include "fixminmax.h"
    109 
    110 #define SCALE_INLINE
    111 
    112 #if defined(__arm__)
    113 #include "arm/scale_arm.h"
    114 
    115 #elif defined(__mips__)
    116 #include "mips/scale_mips.h"
    117 
    118 #endif
    119 
    120 void scaleValues(FIXP_SGL *vector, INT len, INT scalefactor);
    121 void scaleValues(FIXP_DBL *vector, INT len, INT scalefactor);
    122 void scaleValues(FIXP_DBL *dst, const FIXP_DBL *src, INT len, INT scalefactor);
    123 #if (SAMPLE_BITS == 16)
    124 void scaleValues(FIXP_PCM *dst, const FIXP_DBL *src, INT len, INT scalefactor);
    125 #endif
    126 void scaleValues(FIXP_SGL *dst, const FIXP_SGL *src, INT len, INT scalefactor);
    127 void scaleCplxValues(FIXP_DBL *r_dst, FIXP_DBL *i_dst, const FIXP_DBL *r_src,
    128                      const FIXP_DBL *i_src, INT len, INT scalefactor);
    129 void scaleValuesWithFactor(FIXP_DBL *vector, FIXP_DBL factor, INT len,
    130                            INT scalefactor);
    131 void scaleValuesSaturate(FIXP_DBL *vector, INT len, INT scalefactor);
    132 void scaleValuesSaturate(FIXP_DBL *dst, FIXP_DBL *src, INT len,
    133                          INT scalefactor);
    134 void scaleValuesSaturate(FIXP_SGL *dst, FIXP_DBL *src, INT len,
    135                          INT scalefactor);
    136 void scaleValuesSaturate(INT_PCM *dst, FIXP_DBL *src, INT len, INT scalefactor);
    137 void scaleValuesSaturate(FIXP_SGL *vector, INT len, INT scalefactor);
    138 void scaleValuesSaturate(FIXP_SGL *dst, FIXP_SGL *src, INT len,
    139                          INT scalefactor);
    140 void scaleValuesSaturate(INT_PCM *dst, INT_PCM *src, INT len, INT scalefactor);
    141 INT getScalefactorShort(const SHORT *vector, INT len);
    142 INT getScalefactorPCM(const INT_PCM *vector, INT len, INT stride);
    143 INT getScalefactor(const FIXP_DBL *vector, INT len);
    144 INT getScalefactor(const FIXP_SGL *vector, INT len);
    145 
    146 #ifndef FUNCTION_scaleValue
    147 /*!
    148  *
    149  *  \brief Multiply input by \f$ 2^{scalefactor} \f$
    150  *
    151  *  \return Scaled input
    152  *
    153  */
    154 #define FUNCTION_scaleValue
    155 inline FIXP_DBL scaleValue(const FIXP_DBL value, /*!< Value */
    156                            INT scalefactor       /*!< Scalefactor */
    157 ) {
    158   if (scalefactor > 0)
    159     return (value << scalefactor);
    160   else
    161     return (value >> (-scalefactor));
    162 }
    163 inline FIXP_SGL scaleValue(const FIXP_SGL value, /*!< Value */
    164                            INT scalefactor       /*!< Scalefactor */
    165 ) {
    166   if (scalefactor > 0)
    167     return (value << scalefactor);
    168   else
    169     return (value >> (-scalefactor));
    170 }
    171 #endif
    172 
    173 #ifndef FUNCTION_scaleValueSaturate
    174 /*!
    175  *
    176  *  \brief Multiply input by \f$ 2^{scalefactor} \f$
    177  *  \param value The value to be scaled.
    178  *  \param the shift amount
    179  *  \return \f$ value * 2^scalefactor \f$
    180  *
    181  */
    182 #define FUNCTION_scaleValueSaturate
    183 inline FIXP_DBL scaleValueSaturate(const FIXP_DBL value,
    184                                    INT scalefactor /* in range -31 ... +31 */
    185 ) {
    186   int headroom = fixnormz_D(
    187       (INT)value ^ (INT)((value >> 31))); /* headroom in range 1...32 */
    188   if (scalefactor >= 0) {
    189     /* shift left: saturate in case of headroom less/equal scalefactor */
    190     if (headroom <= scalefactor) {
    191       if (value > (FIXP_DBL)0)
    192         return (FIXP_DBL)MAXVAL_DBL; /* 0x7FFF.FFFF */
    193       else
    194         return (FIXP_DBL)MINVAL_DBL + (FIXP_DBL)1; /* 0x8000.0001 */
    195     } else {
    196       return fMax((value << scalefactor), (FIXP_DBL)MINVAL_DBL + (FIXP_DBL)1);
    197     }
    198   } else {
    199     scalefactor = -scalefactor;
    200     /* shift right: clear in case of 32-headroom greater/equal -scalefactor */
    201     if ((DFRACT_BITS - headroom) <= scalefactor) {
    202       return (FIXP_DBL)0;
    203     } else {
    204       return fMax((value >> scalefactor), (FIXP_DBL)MINVAL_DBL + (FIXP_DBL)1);
    205     }
    206   }
    207 }
    208 #endif
    209 
    210 #ifndef FUNCTION_scaleValueInPlace
    211 /*!
    212  *
    213  *  \brief Multiply input by \f$ 2^{scalefactor} \f$ in place
    214  *
    215  *  \return void
    216  *
    217  */
    218 #define FUNCTION_scaleValueInPlace
    219 inline void scaleValueInPlace(FIXP_DBL *value, /*!< Value */
    220                               INT scalefactor  /*!< Scalefactor */
    221 ) {
    222   INT newscale;
    223   /* Note: The assignment inside the if conditional allows combining a load with
    224    * the compare to zero (on ARM and maybe others) */
    225   if ((newscale = (scalefactor)) >= 0) {
    226     *(value) <<= newscale;
    227   } else {
    228     *(value) >>= -newscale;
    229   }
    230 }
    231 #endif
    232 
    233   /*!
    234    *
    235    *  \brief  Scale input value by 2^{scale} and saturate output to 2^{dBits-1}
    236    *  \return scaled and saturated value
    237    *
    238    *  This macro scales src value right or left and applies saturation to
    239    * (2^dBits)-1 maxima output.
    240    */
    241 
    242 #ifndef SATURATE_RIGHT_SHIFT
    243 #define SATURATE_RIGHT_SHIFT(src, scale, dBits)                            \
    244   ((((LONG)(src) >> (scale)) > (LONG)(((1U) << ((dBits)-1)) - 1))          \
    245        ? (LONG)(((1U) << ((dBits)-1)) - 1)                                 \
    246        : (((LONG)(src) >> (scale)) < ~((LONG)(((1U) << ((dBits)-1)) - 1))) \
    247              ? ~((LONG)(((1U) << ((dBits)-1)) - 1))                        \
    248              : ((LONG)(src) >> (scale)))
    249 #endif
    250 
    251 #ifndef SATURATE_LEFT_SHIFT
    252 #define SATURATE_LEFT_SHIFT(src, scale, dBits)                           \
    253   (((LONG)(src) > ((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale)))        \
    254        ? (LONG)(((1U) << ((dBits)-1)) - 1)                               \
    255        : ((LONG)(src) < ~((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale))) \
    256              ? ~((LONG)(((1U) << ((dBits)-1)) - 1))                      \
    257              : ((LONG)(src) << (scale)))
    258 #endif
    259 
    260 #ifndef SATURATE_SHIFT
    261 #define SATURATE_SHIFT(src, scale, dBits)                        \
    262   (((scale) < 0) ? SATURATE_LEFT_SHIFT((src), -(scale), (dBits)) \
    263                  : SATURATE_RIGHT_SHIFT((src), (scale), (dBits)))
    264 #endif
    265 
    266 /*
    267  * Alternative shift and saturate left, saturates to -0.99999 instead of -1.0000
    268  * to avoid problems when inverting the sign of the result.
    269  */
    270 #ifndef SATURATE_LEFT_SHIFT_ALT
    271 #define SATURATE_LEFT_SHIFT_ALT(src, scale, dBits)                        \
    272   (((LONG)(src) > ((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale)))         \
    273        ? (LONG)(((1U) << ((dBits)-1)) - 1)                                \
    274        : ((LONG)(src) <= ~((LONG)(((1U) << ((dBits)-1)) - 1) >> (scale))) \
    275              ? ~((LONG)(((1U) << ((dBits)-1)) - 2))                       \
    276              : ((LONG)(src) << (scale)))
    277 #endif
    278 
    279 #ifndef SATURATE_RIGHT_SHIFT_ALT
    280 #define SATURATE_RIGHT_SHIFT_ALT(src, scale, dBits)                        \
    281   ((((LONG)(src) >> (scale)) > (LONG)(((1U) << ((dBits)-1)) - 1))          \
    282        ? (LONG)(((1U) << ((dBits)-1)) - 1)                                 \
    283        : (((LONG)(src) >> (scale)) < ~((LONG)(((1U) << ((dBits)-1)) - 2))) \
    284              ? ~((LONG)(((1U) << ((dBits)-1)) - 2))                        \
    285              : ((LONG)(src) >> (scale)))
    286 #endif
    287 
    288 #ifndef SATURATE_INT_PCM_RIGHT_SHIFT
    289 #define SATURATE_INT_PCM_RIGHT_SHIFT(src, scale) \
    290   SATURATE_RIGHT_SHIFT(src, scale, SAMPLE_BITS)
    291 #endif
    292 
    293 #ifndef SATURATE_INT_PCM_LEFT_SHIFT
    294 #define SATURATE_INT_PCM_LEFT_SHIFT(src, scale) \
    295   SATURATE_LEFT_SHIFT(src, scale, SAMPLE_BITS)
    296 #endif
    297 
    298 #endif /* #ifndef SCALE_H */
    299