Home | History | Annotate | Download | only in src
      1 
      2 /* -----------------------------------------------------------------------------------------------------------
      3 Software License for The Fraunhofer FDK AAC Codec Library for Android
      4 
      5  Copyright  1995 - 2013 Fraunhofer-Gesellschaft zur Frderung der angewandten Forschung e.V.
      6   All rights reserved.
      7 
      8  1.    INTRODUCTION
      9 The Fraunhofer FDK AAC Codec Library for Android ("FDK AAC Codec") is software that implements
     10 the MPEG Advanced Audio Coding ("AAC") encoding and decoding scheme for digital audio.
     11 This FDK AAC Codec software is intended to be used on a wide variety of Android devices.
     12 
     13 AAC's HE-AAC and HE-AAC v2 versions are regarded as today's most efficient general perceptual
     14 audio codecs. AAC-ELD is considered the best-performing full-bandwidth communications codec by
     15 independent studies and is widely deployed. AAC has been standardized by ISO and IEC as part
     16 of the MPEG specifications.
     17 
     18 Patent licenses for necessary patent claims for the FDK AAC Codec (including those of Fraunhofer)
     19 may be obtained through Via Licensing (www.vialicensing.com) or through the respective patent owners
     20 individually for the purpose of encoding or decoding bit streams in products that are compliant with
     21 the ISO/IEC MPEG audio standards. Please note that most manufacturers of Android devices already license
     22 these patent claims through Via Licensing or directly from the patent owners, and therefore FDK AAC Codec
     23 software may already be covered under those patent licenses when it is used for those licensed purposes only.
     24 
     25 Commercially-licensed AAC software libraries, including floating-point versions with enhanced sound quality,
     26 are also available from Fraunhofer. Users are encouraged to check the Fraunhofer website for additional
     27 applications information and documentation.
     28 
     29 2.    COPYRIGHT LICENSE
     30 
     31 Redistribution and use in source and binary forms, with or without modification, are permitted without
     32 payment of copyright license fees provided that you satisfy the following conditions:
     33 
     34 You must retain the complete text of this software license in redistributions of the FDK AAC Codec or
     35 your modifications thereto in source code form.
     36 
     37 You must retain the complete text of this software license in the documentation and/or other materials
     38 provided with redistributions of the FDK AAC Codec or your modifications thereto in binary form.
     39 You must make available free of charge copies of the complete source code of the FDK AAC Codec and your
     40 modifications thereto to recipients of copies in binary form.
     41 
     42 The name of Fraunhofer may not be used to endorse or promote products derived from this library without
     43 prior written permission.
     44 
     45 You may not charge copyright license fees for anyone to use, copy or distribute the FDK AAC Codec
     46 software or your modifications thereto.
     47 
     48 Your modified versions of the FDK AAC Codec must carry prominent notices stating that you changed the software
     49 and the date of any change. For modified versions of the FDK AAC Codec, the term
     50 "Fraunhofer FDK AAC Codec Library for Android" must be replaced by the term
     51 "Third-Party Modified Version of the Fraunhofer FDK AAC Codec Library for Android."
     52 
     53 3.    NO PATENT LICENSE
     54 
     55 NO EXPRESS OR IMPLIED LICENSES TO ANY PATENT CLAIMS, including without limitation the patents of Fraunhofer,
     56 ARE GRANTED BY THIS SOFTWARE LICENSE. Fraunhofer provides no warranty of patent non-infringement with
     57 respect to this software.
     58 
     59 You may use this FDK AAC Codec software or modifications thereto only for purposes that are authorized
     60 by appropriate patent licenses.
     61 
     62 4.    DISCLAIMER
     63 
     64 This FDK AAC Codec software is provided by Fraunhofer on behalf of the copyright holders and contributors
     65 "AS IS" and WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, including but not limited to the implied warranties
     66 of merchantability and fitness for a particular purpose. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
     67 CONTRIBUTORS BE LIABLE for any direct, indirect, incidental, special, exemplary, or consequential damages,
     68 including but not limited to procurement of substitute goods or services; loss of use, data, or profits,
     69 or business interruption, however caused and on any theory of liability, whether in contract, strict
     70 liability, or tort (including negligence), arising in any way out of the use of this software, even if
     71 advised of the possibility of such damage.
     72 
     73 5.    CONTACT INFORMATION
     74 
     75 Fraunhofer Institute for Integrated Circuits IIS
     76 Attention: Audio and Multimedia Departments - FDK AAC LL
     77 Am Wolfsmantel 33
     78 91058 Erlangen, Germany
     79 
     80 www.iis.fraunhofer.de/amm
     81 amm-info (at) iis.fraunhofer.de
     82 ----------------------------------------------------------------------------------------------------------- */
     83 
     84 /*****************************  MPEG-4 AAC Decoder  ***************************
     85 
     86    Author(s):   Robert Weidner (DSP Solutions)
     87    Description: HCR Decoder: Common defines and structures; defines for
     88                 switching error-generator, -detector, and -concealment;
     89 
     90 *******************************************************************************/
     91 
     92 #ifndef _AACDEC_HCR_TYPES_H_
     93 #define _AACDEC_HCR_TYPES_H_
     94 
     95 
     96 
     97 #include "FDK_bitstream.h"
     98 #include "overlapadd.h"
     99 
    100 /* ------------------------------------------------ */
    101 /* ------------------------------------------------ */
    102 
    103 #define  LINES_PER_UNIT                4
    104 
    105 /* ------------------------------------------------ */
    106 /* ------------------------------------------------ */
    107 /* ----------- basic HCR configuration ------------ */
    108 
    109 
    110  #define  MAX_SFB_HCR                 (((1024/8) / LINES_PER_UNIT) * 8)  /* (8 * 16) is not enough because sfbs are split in units for blocktype short */
    111  #define  NUMBER_OF_UNIT_GROUPS       (LINES_PER_UNIT * 8)
    112  #define  LINES_PER_UNIT_GROUP        (1024 / NUMBER_OF_UNIT_GROUPS)     /* 15 16 30 32 */
    113 
    114 
    115 /* ------------------------------------------------ */
    116 /* ------------------------------------------------ */
    117 /* ------------------------------------------------ */
    118 
    119 #define  FROM_LEFT_TO_RIGHT            0
    120 #define  FROM_RIGHT_TO_LEFT            1
    121 
    122 #define  MAX_CB_PAIRS                  23
    123 #define  MAX_HCR_SETS                  14
    124 
    125 #define  ESCAPE_VALUE                  16
    126 #define  POSITION_OF_FLAG_A            21
    127 #define  POSITION_OF_FLAG_B            20
    128 
    129 #define  MAX_CB                        32     /* last used CB is cb #31 when VCB11 is used */
    130 
    131 #define  MAX_CB_CHECK                  32     /* support for VCB11 available -- is more general, could therefore used in both cases */
    132 
    133 #define  NUMBER_OF_BIT_IN_WORD         32
    134 
    135 /* log */
    136 #define  THIRTYTWO_LOG_DIV_TWO_LOG     5
    137 #define  EIGHT_LOG_DIV_TWO_LOG         3
    138 #define  FOUR_LOG_DIV_TWO_LOG          2
    139 
    140 /* borders */
    141 #define  CPE_TOP_LENGTH                12288
    142 #define  SCE_TOP_LENGTH                6144
    143 #define  LEN_OF_LONGEST_CW_TOP_LENGTH  49
    144 
    145 /* qsc's of high level */
    146 #define  Q_VALUE_INVALID               8192   /* mark a invalid line with this value (to be concealed later on) */
    147 #define  HCR_DIRAC                     500    /* a line of high level */
    148 
    149 /* masks */
    150 #define  MASK_LEFT                     0xFFF000
    151 #define  MASK_RIGHT                    0xFFF
    152 #define  CLR_BIT_10                    0x3FF
    153 #define  TEST_BIT_10                   0x400
    154 
    155 #define  LEFT_OFFSET                   12
    156 
    157 /* when set HCR is replaced by a dummy-module which just fills the outputbuffer with a dirac sequence */
    158 /* use this if HCR is suspected to write in other modules -- if error is stell there, HCR is innocent */
    159 #define USE_HCR_DUMMY                     0
    160 
    161 
    162 /* ------------------------------ */
    163 /* -    insert HCR errors       - */
    164 /* ------------------------------ */
    165 
    166   /* modify input lengths -- high protected */
    167 #define ERROR_LORSD                       0  /* offset: error if different from zero */
    168 #define ERROR_LOLC                        0  /* offset: error if different from zero */
    169 
    170   /* segments are earlier empty as expected when decoding PCWs */
    171 #define ERROR_PCW_BODY                    0  /* set a positive values to trigger the error (make segments earlyer appear to be empty) */
    172 #define ERROR_PCW_BODY_SIGN               0  /* set a positive values to trigger the error (make segments earlyer appear to be empty) */
    173 #define ERROR_PCW_BODY_SIGN_ESC           0  /* set a positive values to trigger the error (make segments earlyer appear to be empty) */
    174 
    175   /* pretend there are too many bits decoded (enlarge length of codeword) at PCWs -- use a positive value */
    176 #define ERROR_PCW_BODY_ONLY_TOO_LONG      0  /* set a positive values to trigger the error */
    177 #define ERROR_PCW_BODY_SIGN_TOO_LONG      0  /* set a positive values to trigger the error */
    178 #define ERROR_PCW_BODY_SIGN_ESC_TOO_LONG  0  /* set a positive values to trigger the error */
    179 
    180   /* modify HCR bitstream block */
    181 #define ERROR_GENERATOR_BIT_STREAM_HCR    0  /* modify every <MODULO_DIVISOR_HCR>-bit when reading from bitstream */ /* !!! BEWARE!!! if RVLC is active, also RVLC data at ESC2 will be modified !!! */
    182 #define MODULO_DIVISOR_HCR               30
    183 
    184 
    185 /* ------------------------------ */
    186 /* -    detect HCR errors       - */
    187 /* ------------------------------ */
    188   /* check input data */
    189 #define CHECK_VALID_HCR_INPUT             1  /* it is highly recommended to check input data */
    190 
    191   /* during decoding */
    192 #define CHECK_SEGMENTATION_IMMEDIATELY    1  /* the 2 or 4 lines of a detected PCW-decoding-error is marked */
    193 
    194 #define CHECK_SEGMENTATION_FINAL          1  /* all the segments are checked -- therefore -- if this check passes, its a kind of evidence that the
    195                                                 decoded PCWs and non-PCWs are fine */
    196 
    197 #define DETECT_TOO_LONG_CW_READS          1  /* if a codeword is decoded there exists a border for the number of bits, which are allowed to read for this
    198                                                 codeword. This border is the minimum of the length of the longest codeword (for the currently used
    199                                                 codebook) and the separately transmitted 'lengthOfLongestCodeword' in this frame and channel. The number
    200                                                 of decoded bits is counted (for PCWs only -- there it makes really sense in my opinion). If this number
    201                                                 exceeds the border (derived as minimum -- see above), a error is detected. */
    202 
    203 #define STATE_MACHINE_ERROR_CHECK         1  /* test if the number of remaining bits in a segment is _below_ zero. If there are no errors the lowest
    204                                                 allowed value for remainingBitsInSegment is zero. This check also could be set to zero (save runtime) */
    205   /* other */
    206 #define VALID_LAV_ERROR_TRIGGER           1  /* when set to '1', avoid setting the LAV-Flag in errorLog due to a previous-line-marking (at PCW decoder). A little
    207                                                 more runtime is needed then when writing values out into output-buffer. */
    208 
    209 #define HCR_LISTEN_TO_MUTED_LINES         0  /* listen to the "error-concealment" for testing */
    210 
    211 /* ------------------------------ */
    212 /* -    conceal HCR errors      - */
    213 /* ------------------------------ */
    214 
    215 #define HCR_ERROR_CONCEALMENT             1  /* if set to '1', HCR _mutes_ the erred quantized spectral coefficients */
    216 
    217 
    218 // ------------------------------------------------------------------------------------------------------------------
    219 //                                         errorLog: A word of 32 bits used for logging possible errors within HCR
    220 //                                                   in case of distorted bitstreams. Table of all known errors:
    221 // ------------------------------------------------------------------------------------------------------------------------
    222                                                            // bit  fatal  location    meaning
    223                                                            // ----+-----+-----------+--------------------------------------
    224 #define SEGMENT_OVERRIDE_ERR_PCW_BODY           0x80000000 //  31   no    PCW-Dec     During PCW decoding it is checked after every PCW if there are too many bits decoded (immediate check).
    225 #define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN      0x40000000 //  30   no    PCW-Dec     During PCW decoding it is checked after every PCW if there are too many bits decoded (immediate check).
    226 #define SEGMENT_OVERRIDE_ERR_PCW_BODY_SIGN_ESC  0x20000000 //  29   no    PCW-Dec     During PCW decoding it is checked after every PCW if there are too many bits decoded (immediate check).
    227 #define EXTENDED_SORTED_COUNTER_OVERFLOW        0x10000000 //  28   yes   Init-Dec    Error during extending sideinfo (neither a PCW nor a nonPCW was decoded so far)
    228                                              // 0x08000000 //  27                     reserved
    229                                              // 0x04000000 //  26                     reserved
    230                                              // 0x02000000 //  25                     reserved
    231                                              // 0x01000000 //  24                     reserved
    232                                              // 0x00800000 //  23                     reserved
    233                                              // 0x00400000 //  22                     reserved
    234                                              // 0x00200000 //  21                     reserved
    235                                              // 0x00100000 //  20                     reserved
    236 
    237                                            /* special errors */
    238 #define TOO_MANY_PCW_BODY_BITS_DECODED          0x00080000 //  19   yes   PCW-Dec     During PCW-body-decoding too many bits have been read from bitstream -- advice: skip non-PCW decoding
    239 #define TOO_MANY_PCW_BODY_SIGN_BITS_DECODED     0x00040000 //  18   yes   PCW-Dec     During PCW-body-sign-decoding too many bits have been read from bitstream -- advice: skip non-PCW decoding
    240 #define TOO_MANY_PCW_BODY_SIGN_ESC_BITS_DECODED 0x00020000 //  17   yes   PCW-Dec     During PCW-body-sign-esc-decoding too many bits have been read from bitstream -- advice: skip non-PCW decoding
    241 
    242 
    243                                              // 0x00010000 //  16                     reserved
    244 #define STATE_ERROR_BODY_ONLY                   0x00008000 //  15   no    NonPCW-Dec  State machine returned with error
    245 #define STATE_ERROR_BODY_SIGN__BODY             0x00004000 //  14   no    NonPCW-Dec  State machine returned with error
    246 #define STATE_ERROR_BODY_SIGN__SIGN             0x00002000 //  13   no    NonPCW-Dec  State machine returned with error
    247 #define STATE_ERROR_BODY_SIGN_ESC__BODY         0x00001000 //  12   no    NonPCW-Dec  State machine returned with error
    248 #define STATE_ERROR_BODY_SIGN_ESC__SIGN         0x00000800 //  11   no    NonPCW-Dec  State machine returned with error
    249 #define STATE_ERROR_BODY_SIGN_ESC__ESC_PREFIX   0x00000400 //  10   no    NonPCW-Dec  State machine returned with error
    250 #define STATE_ERROR_BODY_SIGN_ESC__ESC_WORD     0x00000200 //   9   no    NonPCW-Dec  State machine returned with error
    251 #define HCR_SI_LENGTHS_FAILURE                  0x00000100 //   8   yes   Init-Dec    LengthOfLongestCodeword must not be less than lenghtOfReorderedSpectralData
    252 #define NUM_SECT_OUT_OF_RANGE_SHORT_BLOCK       0x00000080 //   7   yes   Init-Dec    The number of sections is not within the allowed range (short block)
    253 #define NUM_SECT_OUT_OF_RANGE_LONG_BLOCK        0x00000040 //   6   yes   Init-Dec    The number of sections is not within the allowed range (long block)
    254 #define LINE_IN_SECT_OUT_OF_RANGE_SHORT_BLOCK   0x00000020 //   5   yes   Init-Dec    The number of lines per section is not within the allowed range (short block)
    255 #define CB_OUT_OF_RANGE_SHORT_BLOCK             0x00000010 //   4   yes   Init-Dec    The codebook is not within the allowed range (short block)
    256 #define LINE_IN_SECT_OUT_OF_RANGE_LONG_BLOCK    0x00000008 //   3   yes   Init-Dec    The number of lines per section is not within the allowed range (long block)
    257 #define CB_OUT_OF_RANGE_LONG_BLOCK              0x00000004 //   2   yes   Init-Dec    The codebook is not within the allowed range (long block)
    258 #define LAV_VIOLATION                           0x00000002 //   1   no    Final       The absolute value of at least one decoded line was too high for the according codebook.
    259 #define BIT_IN_SEGMENTATION_ERROR               0x00000001 //   0   no    Final       After PCW and non-PWC-decoding at least one segment is not zero (global check).
    260 
    261                                               /*----------*/
    262 #define HCR_FATAL_PCW_ERROR_MASK                0x100E01FC
    263 
    264 
    265 typedef enum {
    266   PCW_BODY,
    267   PCW_BODY_SIGN,
    268   PCW_BODY_SIGN_ESC
    269 } PCW_TYPE;
    270 
    271 
    272 /* interface Decoder <---> HCR */
    273 typedef struct {
    274   UINT          errorLog;
    275   SPECTRAL_PTR  pQuantizedSpectralCoefficientsBase;
    276   int           quantizedSpectralCoefficientsIdx;
    277   SHORT         lengthOfReorderedSpectralData;
    278   SHORT         numSection;
    279   SHORT        *pNumLineInSect;
    280   USHORT        bitstreamIndex;
    281   SCHAR         lengthOfLongestCodeword;
    282   UCHAR        *pCodebook;
    283 } HCR_INPUT_OUTPUT;
    284 
    285 typedef struct {
    286   const UCHAR *pMinOfCbPair;
    287   const UCHAR *pMaxOfCbPair;
    288 } HCR_CB_PAIRS;
    289 
    290 typedef struct{
    291   const USHORT *pLargestAbsVal;
    292   const UCHAR  *pMaxCwLength;
    293   const UCHAR  *pCbDimension;
    294   const UCHAR  *pCbDimShift;
    295   const UCHAR  *pCbSign;
    296   const UCHAR  *pCbPriority;
    297 } HCR_TABLE_INFO;
    298 
    299 typedef struct{
    300   UINT      numSegment;
    301   UINT      pSegmentBitfield[((1024>>1)/NUMBER_OF_BIT_IN_WORD+1)];
    302   UINT      pCodewordBitfield[((1024>>1)/NUMBER_OF_BIT_IN_WORD+1)];
    303   UINT      segmentOffset;
    304   FIXP_DBL  pTempValues[1024];
    305   USHORT    pLeftStartOfSegment[1024>>1];
    306   USHORT    pRightStartOfSegment[1024>>1];
    307   SCHAR     pRemainingBitsInSegment[1024>>1];
    308   UCHAR     readDirection;
    309   UCHAR     numWordForBitfield;
    310   USHORT    pNumBitValidInLastWord;
    311 } HCR_SEGMENT_INFO;
    312 
    313 typedef struct{
    314 
    315   UINT    numCodeword;
    316   UINT    numSortedSection;
    317   USHORT  pNumCodewordInSection[MAX_SFB_HCR];
    318   USHORT  pNumSortedCodewordInSection[MAX_SFB_HCR];
    319   USHORT  pNumExtendedSortedCodewordInSection[MAX_SFB_HCR+MAX_HCR_SETS];
    320   int     numExtendedSortedCodewordInSectionIdx;
    321   USHORT  pNumExtendedSortedSectionsInSets[MAX_HCR_SETS];
    322   int     numExtendedSortedSectionsInSetsIdx;
    323   USHORT  pReorderOffset[MAX_SFB_HCR];
    324   UCHAR   pSortedCodebook[MAX_SFB_HCR];
    325 
    326   UCHAR   pExtendedSortedCodebook[MAX_SFB_HCR+MAX_HCR_SETS];
    327   int     extendedSortedCodebookIdx;
    328 #if DETECT_TOO_LONG_CW_READS
    329   UCHAR   pMaxLenOfCbInExtSrtSec[MAX_SFB_HCR+MAX_HCR_SETS];
    330   int     maxLenOfCbInExtSrtSecIdx;
    331 #endif
    332   UCHAR   pCodebookSwitch[MAX_SFB_HCR];
    333 } HCR_SECTION_INFO;
    334 
    335 typedef UINT (*STATEFUNC)(HANDLE_FDK_BITSTREAM, void*);
    336 
    337 typedef struct{
    338   /* worst-case and 1024/4 non-PCWs exist in worst-case */
    339   FIXP_DBL  *pResultBase;                           /* Base address for spectral data output target buffer */
    340   UINT       iNode[1024>>2];           /* Helper indices for code books */
    341   USHORT     iResultPointer[1024>>2];  /* Helper indices for accessing pResultBase */
    342   UINT       pEscapeSequenceInfo[1024>>2];
    343   UINT       codewordOffset;
    344   STATEFUNC  pState;
    345   UCHAR      pCodebook[1024>>2];
    346   UCHAR      pCntSign[1024>>2];
    347   /* this array holds the states coded as integer values within the range [0,1,..,7] */
    348   SCHAR      pSta[1024>>2];
    349 } HCR_NON_PCW_SIDEINFO;
    350 
    351 typedef struct{
    352   HCR_INPUT_OUTPUT      decInOut;
    353   HCR_CB_PAIRS          cbPairs;
    354   HCR_TABLE_INFO        tableInfo;
    355   HCR_SEGMENT_INFO      segmentInfo;
    356   HCR_SECTION_INFO      sectionInfo;
    357   HCR_NON_PCW_SIDEINFO  nonPcwSideinfo;
    358 
    359   INT                   globalHcrType;
    360 } CErHcrInfo;
    361 
    362 
    363 typedef  CErHcrInfo  *H_HCR_INFO;
    364 
    365 
    366 #endif /* _AACDEC_HCR_TYPES_H_ */
    367