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 encoder library ******************************
     96 
     97    Author(s):   M.Werner
     98 
     99    Description: MS stereo processing
    100 
    101 *******************************************************************************/
    102 
    103 #include "ms_stereo.h"
    104 
    105 #include "psy_const.h"
    106 
    107 /* static const float scaleMinThres = 1.0f; */ /* 0.75f for 3db boost */
    108 
    109 void FDKaacEnc_MsStereoProcessing(PSY_DATA *RESTRICT psyData[(2)],
    110                                   PSY_OUT_CHANNEL *psyOutChannel[2],
    111                                   const INT *isBook, INT *msDigest, /* output */
    112                                   INT *msMask,                      /* output */
    113                                   const INT allowMS, const INT sfbCnt,
    114                                   const INT sfbPerGroup,
    115                                   const INT maxSfbPerGroup,
    116                                   const INT *sfbOffset) {
    117   FIXP_DBL *sfbEnergyLeft =
    118       psyData[0]->sfbEnergy.Long; /* modified where msMask==1 */
    119   FIXP_DBL *sfbEnergyRight =
    120       psyData[1]->sfbEnergy.Long; /* modified where msMask==1 */
    121   const FIXP_DBL *sfbEnergyMid = psyData[0]->sfbEnergyMS.Long;
    122   const FIXP_DBL *sfbEnergySide = psyData[1]->sfbEnergyMS.Long;
    123   FIXP_DBL *sfbThresholdLeft =
    124       psyData[0]->sfbThreshold.Long; /* modified where msMask==1 */
    125   FIXP_DBL *sfbThresholdRight =
    126       psyData[1]->sfbThreshold.Long; /* modified where msMask==1 */
    127 
    128   FIXP_DBL *sfbSpreadEnLeft = psyData[0]->sfbSpreadEnergy.Long;
    129   FIXP_DBL *sfbSpreadEnRight = psyData[1]->sfbSpreadEnergy.Long;
    130 
    131   FIXP_DBL *sfbEnergyLeftLdData =
    132       psyOutChannel[0]->sfbEnergyLdData; /* modified where msMask==1 */
    133   FIXP_DBL *sfbEnergyRightLdData =
    134       psyOutChannel[1]->sfbEnergyLdData; /* modified where msMask==1 */
    135   FIXP_DBL *sfbEnergyMidLdData = psyData[0]->sfbEnergyMSLdData;
    136   FIXP_DBL *sfbEnergySideLdData = psyData[1]->sfbEnergyMSLdData;
    137   FIXP_DBL *sfbThresholdLeftLdData =
    138       psyOutChannel[0]->sfbThresholdLdData; /* modified where msMask==1 */
    139   FIXP_DBL *sfbThresholdRightLdData =
    140       psyOutChannel[1]->sfbThresholdLdData; /* modified where msMask==1 */
    141 
    142   FIXP_DBL *mdctSpectrumLeft =
    143       psyData[0]->mdctSpectrum; /* modified where msMask==1 */
    144   FIXP_DBL *mdctSpectrumRight =
    145       psyData[1]->mdctSpectrum; /* modified where msMask==1 */
    146 
    147   INT sfb, sfboffs, j; /* loop counters         */
    148   FIXP_DBL pnlrLdData, pnmsLdData;
    149   FIXP_DBL minThresholdLdData;
    150   FIXP_DBL minThreshold;
    151   INT useMS;
    152 
    153   INT msMaskTrueSomewhere = 0; /* to determine msDigest */
    154   INT numMsMaskFalse =
    155       0; /* number of non-intensity bands where L/R coding is used */
    156 
    157   for (sfb = 0; sfb < sfbCnt; sfb += sfbPerGroup) {
    158     for (sfboffs = 0; sfboffs < maxSfbPerGroup; sfboffs++) {
    159       if ((isBook == NULL) ? 1 : (isBook[sfb + sfboffs] == 0)) {
    160         FIXP_DBL tmp;
    161 
    162         /*
    163                   minThreshold=min(sfbThresholdLeft[sfb+sfboffs],
    164            sfbThresholdRight[sfb+sfboffs])*scaleMinThres; pnlr =
    165            (sfbThresholdLeft[sfb+sfboffs]/
    166                          max(sfbEnergyLeft[sfb+sfboffs],sfbThresholdLeft[sfb+sfboffs]))*
    167                          (sfbThresholdRight[sfb+sfboffs]/
    168                          max(sfbEnergyRight[sfb+sfboffs],sfbThresholdRight[sfb+sfboffs]));
    169                   pnms =
    170            (minThreshold/max(sfbEnergyMid[sfb+sfboffs],minThreshold))*
    171                          (minThreshold/max(sfbEnergySide[sfb+sfboffs],minThreshold));
    172                   useMS = (pnms > pnlr);
    173         */
    174 
    175         /* we assume that scaleMinThres == 1.0f and we can drop it */
    176         minThresholdLdData = fixMin(sfbThresholdLeftLdData[sfb + sfboffs],
    177                                     sfbThresholdRightLdData[sfb + sfboffs]);
    178 
    179         /* pnlrLdData = sfbThresholdLeftLdData[sfb+sfboffs] -
    180                       max(sfbEnergyLeftLdData[sfb+sfboffs],
    181            sfbThresholdLeftLdData[sfb+sfboffs]) +
    182                       sfbThresholdRightLdData[sfb+sfboffs] -
    183                       max(sfbEnergyRightLdData[sfb+sfboffs],
    184            sfbThresholdRightLdData[sfb+sfboffs]); */
    185         tmp = fixMax(sfbEnergyLeftLdData[sfb + sfboffs],
    186                      sfbThresholdLeftLdData[sfb + sfboffs]);
    187         pnlrLdData = (sfbThresholdLeftLdData[sfb + sfboffs] >> 1) - (tmp >> 1);
    188         pnlrLdData = pnlrLdData + (sfbThresholdRightLdData[sfb + sfboffs] >> 1);
    189         tmp = fixMax(sfbEnergyRightLdData[sfb + sfboffs],
    190                      sfbThresholdRightLdData[sfb + sfboffs]);
    191         pnlrLdData = pnlrLdData - (tmp >> 1);
    192 
    193         /* pnmsLdData = minThresholdLdData -
    194            max(sfbEnergyMidLdData[sfb+sfboffs], minThresholdLdData) +
    195                       minThresholdLdData - max(sfbEnergySideLdData[sfb+sfboffs],
    196            minThresholdLdData); */
    197         tmp = fixMax(sfbEnergyMidLdData[sfb + sfboffs], minThresholdLdData);
    198         pnmsLdData = minThresholdLdData - (tmp >> 1);
    199         tmp = fixMax(sfbEnergySideLdData[sfb + sfboffs], minThresholdLdData);
    200         pnmsLdData = pnmsLdData - (tmp >> 1);
    201         useMS = ((allowMS != 0) && (pnmsLdData > pnlrLdData)) ? 1 : 0;
    202 
    203         if (useMS) {
    204           msMask[sfb + sfboffs] = 1;
    205           msMaskTrueSomewhere = 1;
    206           for (j = sfbOffset[sfb + sfboffs]; j < sfbOffset[sfb + sfboffs + 1];
    207                j++) {
    208             FIXP_DBL specL, specR;
    209             specL = mdctSpectrumLeft[j] >> 1;
    210             specR = mdctSpectrumRight[j] >> 1;
    211             mdctSpectrumLeft[j] = specL + specR;
    212             mdctSpectrumRight[j] = specL - specR;
    213           }
    214           minThreshold = fixMin(sfbThresholdLeft[sfb + sfboffs],
    215                                 sfbThresholdRight[sfb + sfboffs]);
    216           sfbThresholdLeft[sfb + sfboffs] = sfbThresholdRight[sfb + sfboffs] =
    217               minThreshold;
    218           sfbThresholdLeftLdData[sfb + sfboffs] =
    219               sfbThresholdRightLdData[sfb + sfboffs] = minThresholdLdData;
    220           sfbEnergyLeft[sfb + sfboffs] = sfbEnergyMid[sfb + sfboffs];
    221           sfbEnergyRight[sfb + sfboffs] = sfbEnergySide[sfb + sfboffs];
    222           sfbEnergyLeftLdData[sfb + sfboffs] =
    223               sfbEnergyMidLdData[sfb + sfboffs];
    224           sfbEnergyRightLdData[sfb + sfboffs] =
    225               sfbEnergySideLdData[sfb + sfboffs];
    226 
    227           sfbSpreadEnLeft[sfb + sfboffs] = sfbSpreadEnRight[sfb + sfboffs] =
    228               fixMin(sfbSpreadEnLeft[sfb + sfboffs],
    229                      sfbSpreadEnRight[sfb + sfboffs]) >>
    230               1;
    231 
    232         } else {
    233           msMask[sfb + sfboffs] = 0;
    234           numMsMaskFalse++;
    235         } /* useMS */
    236       }   /* isBook */
    237       else {
    238         /* keep mDigest from IS module */
    239         if (msMask[sfb + sfboffs]) {
    240           msMaskTrueSomewhere = 1;
    241         }
    242         /* prohibit MS_MASK_ALL in combination with IS */
    243         numMsMaskFalse = 9;
    244       } /* isBook */
    245     }   /* sfboffs */
    246   }     /* sfb */
    247 
    248   if (msMaskTrueSomewhere == 1) {
    249     if ((numMsMaskFalse == 0) ||
    250         ((numMsMaskFalse < maxSfbPerGroup) && (numMsMaskFalse < 9))) {
    251       *msDigest = SI_MS_MASK_ALL;
    252       /* loop through M/S bands; if msMask==0, set it to 1 and apply M/S */
    253       for (sfb = 0; sfb < sfbCnt; sfb += sfbPerGroup) {
    254         for (sfboffs = 0; sfboffs < maxSfbPerGroup; sfboffs++) {
    255           if (((isBook == NULL) ? 1 : (isBook[sfb + sfboffs] == 0)) &&
    256               (msMask[sfb + sfboffs] == 0)) {
    257             msMask[sfb + sfboffs] = 1;
    258             /* apply M/S coding */
    259             for (j = sfbOffset[sfb + sfboffs]; j < sfbOffset[sfb + sfboffs + 1];
    260                  j++) {
    261               FIXP_DBL specL, specR;
    262               specL = mdctSpectrumLeft[j] >> 1;
    263               specR = mdctSpectrumRight[j] >> 1;
    264               mdctSpectrumLeft[j] = specL + specR;
    265               mdctSpectrumRight[j] = specL - specR;
    266             }
    267             minThreshold = fixMin(sfbThresholdLeft[sfb + sfboffs],
    268                                   sfbThresholdRight[sfb + sfboffs]);
    269             sfbThresholdLeft[sfb + sfboffs] = sfbThresholdRight[sfb + sfboffs] =
    270                 minThreshold;
    271             minThresholdLdData = fixMin(sfbThresholdLeftLdData[sfb + sfboffs],
    272                                         sfbThresholdRightLdData[sfb + sfboffs]);
    273             sfbThresholdLeftLdData[sfb + sfboffs] =
    274                 sfbThresholdRightLdData[sfb + sfboffs] = minThresholdLdData;
    275             sfbEnergyLeft[sfb + sfboffs] = sfbEnergyMid[sfb + sfboffs];
    276             sfbEnergyRight[sfb + sfboffs] = sfbEnergySide[sfb + sfboffs];
    277             sfbEnergyLeftLdData[sfb + sfboffs] =
    278                 sfbEnergyMidLdData[sfb + sfboffs];
    279             sfbEnergyRightLdData[sfb + sfboffs] =
    280                 sfbEnergySideLdData[sfb + sfboffs];
    281 
    282             sfbSpreadEnLeft[sfb + sfboffs] = sfbSpreadEnRight[sfb + sfboffs] =
    283                 fixMin(sfbSpreadEnLeft[sfb + sfboffs],
    284                        sfbSpreadEnRight[sfb + sfboffs]) >>
    285                 1;
    286           }
    287         }
    288       }
    289     } else {
    290       *msDigest = SI_MS_MASK_SOME;
    291     }
    292   } else {
    293     *msDigest = SI_MS_MASK_NONE;
    294   }
    295 }
    296