1 /* ----------------------------------------------------------------------------- 2 Software License for The Fraunhofer FDK AAC Codec Library for Android 3 4 © Copyright 1995 - 2018 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): M. Lohwasser 98 99 Description: auto-correlation functions 100 101 *******************************************************************************/ 102 103 #include "autocorr2nd.h" 104 105 /* If the accumulator does not provide enough overflow bits, 106 products have to be shifted down in the autocorrelation below. */ 107 #define SHIFT_FACTOR (5) 108 #define SHIFT >> (SHIFT_FACTOR) 109 110 /*! 111 * 112 * \brief Calculate second order autocorrelation using 2 accumulators 113 * 114 */ 115 #if !defined(FUNCTION_autoCorr2nd_real) 116 INT autoCorr2nd_real( 117 ACORR_COEFS *ac, /*!< Pointer to autocorrelation coeffs */ 118 const FIXP_DBL *reBuffer, /*!< Pointer to to real part of input samples */ 119 const int len /*!< Number input samples */ 120 ) { 121 int j, autoCorrScaling, mScale; 122 123 FIXP_DBL accu1, accu2, accu3, accu4, accu5; 124 125 const FIXP_DBL *pReBuf; 126 127 const FIXP_DBL *realBuf = reBuffer; 128 129 /* 130 r11r,r22r 131 r01r,r12r 132 r02r 133 */ 134 pReBuf = realBuf - 2; 135 accu5 = ((fMultDiv2(pReBuf[0], pReBuf[2]) + fMultDiv2(pReBuf[1], pReBuf[3])) 136 SHIFT); 137 pReBuf++; 138 139 /* len must be even */ 140 accu1 = fPow2Div2(pReBuf[0]) SHIFT; 141 accu3 = fMultDiv2(pReBuf[0], pReBuf[1]) SHIFT; 142 pReBuf++; 143 144 for (j = (len - 2) >> 1; j != 0; j--, pReBuf += 2) { 145 accu1 += ((fPow2Div2(pReBuf[0]) + fPow2Div2(pReBuf[1])) SHIFT); 146 147 accu3 += ((fMultDiv2(pReBuf[0], pReBuf[1]) + 148 fMultDiv2(pReBuf[1], pReBuf[2])) SHIFT); 149 150 accu5 += ((fMultDiv2(pReBuf[0], pReBuf[2]) + 151 fMultDiv2(pReBuf[1], pReBuf[3])) SHIFT); 152 } 153 154 accu2 = (fPow2Div2(realBuf[-2]) SHIFT); 155 accu2 += accu1; 156 157 accu1 += (fPow2Div2(realBuf[len - 2]) SHIFT); 158 159 accu4 = (fMultDiv2(realBuf[-1], realBuf[-2]) SHIFT); 160 accu4 += accu3; 161 162 accu3 += (fMultDiv2(realBuf[len - 1], realBuf[len - 2]) SHIFT); 163 164 mScale = CntLeadingZeros( 165 (accu1 | accu2 | fAbs(accu3) | fAbs(accu4) | fAbs(accu5))) - 166 1; 167 autoCorrScaling = mScale - 1 - SHIFT_FACTOR; /* -1 because of fMultDiv2*/ 168 169 /* Scale to common scale factor */ 170 ac->r11r = accu1 << mScale; 171 ac->r22r = accu2 << mScale; 172 ac->r01r = accu3 << mScale; 173 ac->r12r = accu4 << mScale; 174 ac->r02r = accu5 << mScale; 175 176 ac->det = (fMultDiv2(ac->r11r, ac->r22r) - fMultDiv2(ac->r12r, ac->r12r)); 177 mScale = CountLeadingBits(fAbs(ac->det)); 178 179 ac->det <<= mScale; 180 ac->det_scale = mScale - 1; 181 182 return autoCorrScaling; 183 } 184 #endif 185 186 #if !defined(FUNCTION_autoCorr2nd_cplx) 187 INT autoCorr2nd_cplx( 188 ACORR_COEFS *ac, /*!< Pointer to autocorrelation coeffs */ 189 const FIXP_DBL *reBuffer, /*!< Pointer to real part of input samples */ 190 const FIXP_DBL *imBuffer, /*!< Pointer to imag part of input samples */ 191 const int len /*!< Number of input samples (should be smaller than 128) */ 192 ) { 193 int j, autoCorrScaling, mScale, len_scale; 194 195 FIXP_DBL accu0, accu1, accu2, accu3, accu4, accu5, accu6, accu7, accu8; 196 197 const FIXP_DBL *pReBuf, *pImBuf; 198 199 const FIXP_DBL *realBuf = reBuffer; 200 const FIXP_DBL *imagBuf = imBuffer; 201 202 (len > 64) ? (len_scale = 6) : (len_scale = 5); 203 /* 204 r00r, 205 r11r,r22r 206 r01r,r12r 207 r01i,r12i 208 r02r,r02i 209 */ 210 accu1 = accu3 = accu5 = accu7 = accu8 = FL2FXCONST_DBL(0.0f); 211 212 pReBuf = realBuf - 2, pImBuf = imagBuf - 2; 213 accu7 += 214 ((fMultDiv2(pReBuf[2], pReBuf[0]) + fMultDiv2(pImBuf[2], pImBuf[0])) >> 215 len_scale); 216 accu8 += 217 ((fMultDiv2(pImBuf[2], pReBuf[0]) - fMultDiv2(pReBuf[2], pImBuf[0])) >> 218 len_scale); 219 220 pReBuf = realBuf - 1, pImBuf = imagBuf - 1; 221 for (j = (len - 1); j != 0; j--, pReBuf++, pImBuf++) { 222 accu1 += ((fPow2Div2(pReBuf[0]) + fPow2Div2(pImBuf[0])) >> len_scale); 223 accu3 += 224 ((fMultDiv2(pReBuf[0], pReBuf[1]) + fMultDiv2(pImBuf[0], pImBuf[1])) >> 225 len_scale); 226 accu5 += 227 ((fMultDiv2(pImBuf[1], pReBuf[0]) - fMultDiv2(pReBuf[1], pImBuf[0])) >> 228 len_scale); 229 accu7 += 230 ((fMultDiv2(pReBuf[2], pReBuf[0]) + fMultDiv2(pImBuf[2], pImBuf[0])) >> 231 len_scale); 232 accu8 += 233 ((fMultDiv2(pImBuf[2], pReBuf[0]) - fMultDiv2(pReBuf[2], pImBuf[0])) >> 234 len_scale); 235 } 236 237 accu2 = ((fPow2Div2(realBuf[-2]) + fPow2Div2(imagBuf[-2])) >> len_scale); 238 accu2 += accu1; 239 240 accu1 += ((fPow2Div2(realBuf[len - 2]) + fPow2Div2(imagBuf[len - 2])) >> 241 len_scale); 242 accu0 = ((fPow2Div2(realBuf[len - 1]) + fPow2Div2(imagBuf[len - 1])) >> 243 len_scale) - 244 ((fPow2Div2(realBuf[-1]) + fPow2Div2(imagBuf[-1])) >> len_scale); 245 accu0 += accu1; 246 247 accu4 = ((fMultDiv2(realBuf[-1], realBuf[-2]) + 248 fMultDiv2(imagBuf[-1], imagBuf[-2])) >> 249 len_scale); 250 accu4 += accu3; 251 252 accu3 += ((fMultDiv2(realBuf[len - 1], realBuf[len - 2]) + 253 fMultDiv2(imagBuf[len - 1], imagBuf[len - 2])) >> 254 len_scale); 255 256 accu6 = ((fMultDiv2(imagBuf[-1], realBuf[-2]) - 257 fMultDiv2(realBuf[-1], imagBuf[-2])) >> 258 len_scale); 259 accu6 += accu5; 260 261 accu5 += ((fMultDiv2(imagBuf[len - 1], realBuf[len - 2]) - 262 fMultDiv2(realBuf[len - 1], imagBuf[len - 2])) >> 263 len_scale); 264 265 mScale = 266 CntLeadingZeros((accu0 | accu1 | accu2 | fAbs(accu3) | fAbs(accu4) | 267 fAbs(accu5) | fAbs(accu6) | fAbs(accu7) | fAbs(accu8))) - 268 1; 269 autoCorrScaling = mScale - 1 - len_scale; /* -1 because of fMultDiv2*/ 270 271 /* Scale to common scale factor */ 272 ac->r00r = (FIXP_DBL)accu0 << mScale; 273 ac->r11r = (FIXP_DBL)accu1 << mScale; 274 ac->r22r = (FIXP_DBL)accu2 << mScale; 275 ac->r01r = (FIXP_DBL)accu3 << mScale; 276 ac->r12r = (FIXP_DBL)accu4 << mScale; 277 ac->r01i = (FIXP_DBL)accu5 << mScale; 278 ac->r12i = (FIXP_DBL)accu6 << mScale; 279 ac->r02r = (FIXP_DBL)accu7 << mScale; 280 ac->r02i = (FIXP_DBL)accu8 << mScale; 281 282 ac->det = 283 (fMultDiv2(ac->r11r, ac->r22r) >> 1) - 284 ((fMultDiv2(ac->r12r, ac->r12r) + fMultDiv2(ac->r12i, ac->r12i)) >> 1); 285 mScale = CntLeadingZeros(fAbs(ac->det)) - 1; 286 287 ac->det <<= mScale; 288 ac->det_scale = mScale - 2; 289 290 return autoCorrScaling; 291 } 292 293 #endif /* FUNCTION_autoCorr2nd_cplx */ 294