Home | History | Annotate | Download | only in aacdec
      1 /* ------------------------------------------------------------------
      2  * Copyright (C) 1998-2009 PacketVideo
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
     13  * express or implied.
     14  * See the License for the specific language governing permissions
     15  * and limitations under the License.
     16  * -------------------------------------------------------------------
     17  */
     18 /*
     19 
     20  Pathname: PVMP4AudioDecoderInitLibrary.c
     21 
     22 
     23 ------------------------------------------------------------------------------
     24  REVISION HISTORY
     25 
     26  Description:  Copied from aac_decode_frame
     27 
     28  Description:  Clean up.
     29 
     30  Description:  Update per review comments
     31 
     32  Description:  Add frame_length, fix mistake in pseudo-code.
     33                Change frame_length to frameLength, to matcht the API,
     34                look more professional, etc.
     35 
     36  Description:
     37  (1) Added #include of "e_ProgConfigConst.h"
     38      Previously, this function was relying on another include file
     39      to include "e_ProgConfigConst.h"
     40 
     41  (2) Updated the copyright header.
     42 
     43  Description:
     44  (1) Modified to initialize pointers for shared memory techniques.
     45 
     46  Description: Since memory will be allocated continuously, it is initialized
     47               in one spot
     48 
     49  Description: Added field aacPlusUpsamplingFactor (default == 1) to have a
     50               common interface for all AAC variations
     51 
     52  Description: Added PVMP4AudioDecoderDisableAacPlus to disable sbr decoding
     53 
     54  Who:                                   Date: MM/DD/YYYY
     55  Description:
     56 
     57 ------------------------------------------------------------------------------
     58  INPUT AND OUTPUT DEFINITIONS
     59 
     60  Inputs:
     61     pExt = pointer to the external application-program interface (API)
     62            structure that a client program uses to communicate information
     63            with this library. Among the items in this structure is a pointer
     64            to the input and output buffers, data for handling the input buffer
     65            and output information. Look in PVMP4AudioDecoder_API.h for all the
     66            fields to this structure. Data type pointer to a
     67            tPVMP4AudioDecoderExternal structure.
     68 
     69    pMem =  pointer to allocated memory, of the size returned by the function
     70            PVMP4AudioDecoderGetMemRequirements. This is a void pointer for
     71            two reasons:
     72            1) So the external program does not need all of the header files
     73               for all of the fields in the structure tDec_Int_File
     74            2) To hide data and the implementation of the program. Even knowing
     75               how data is stored can help in reverse engineering software.
     76 
     77  Local Stores/Buffers/Pointers Needed: None
     78 
     79  Global Stores/Buffers/Pointers Needed: None
     80 
     81  Outputs:
     82     status = 0 (SUCCESS). Presently there is no error checking in this
     83     function.
     84 
     85  Pointers and Buffers Modified: None
     86 
     87  Local Stores Modified: None
     88 
     89  Global Stores Modified: None
     90 
     91 ------------------------------------------------------------------------------
     92  FUNCTION DESCRIPTION
     93 
     94  Initializes the internal memory for the MP4 Audio Decoder library.
     95  Also sets relevant values for the external interface structure, clears
     96  the bit rate, channel count, sampling rate, and number of used buffer
     97  elements.
     98 
     99 ------------------------------------------------------------------------------
    100  REQUIREMENTS
    101 
    102 
    103 ------------------------------------------------------------------------------
    104  REFERENCES
    105 
    106  (1) MPEG-2 NBC Audio Decoder
    107    "This software module was originally developed by AT&T, Dolby
    108    Laboratories, Fraunhofer Gesellschaft IIS in the course of development
    109    of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and
    110    3. This software module is an implementation of a part of one or more
    111    MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4
    112    Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio
    113    standards free license to this software module or modifications thereof
    114    for use in hardware or software products claiming conformance to the
    115    MPEG-2 NBC/MPEG-4 Audio  standards. Those intending to use this software
    116    module in hardware or software products are advised that this use may
    117    infringe existing patents. The original developer of this software
    118    module and his/her company, the subsequent editors and their companies,
    119    and ISO/IEC have no liability for use of this software module or
    120    modifications thereof in an implementation. Copyright is not released
    121    for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original
    122    developer retains full right to use the code for his/her own purpose,
    123    assign or donate the code to a third party and to inhibit third party
    124    from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products.
    125    This copyright notice must be included in all copies or derivative
    126    works."
    127    Copyright(c)1996.
    128 ------------------------------------------------------------------------------
    129  PSEUDO-CODE
    130 
    131     pVars = pMem;
    132 
    133     CALL pv_memset(
    134            to = pVars,
    135            c  = 0,
    136            n  = sizeof(tDec_Int_File))
    137     MODIFYING(*pVars = 0)
    138     RETURNING(nothing)
    139 
    140     pVars->current_program = -1
    141     pVars->mc_info.sampling_rate_idx = Fs_44
    142     pVars->frameLength = LONG_WINDOW
    143 
    144 
    145     pVars->winmap[ONLY_LONG_SEQUENCE]   = &pVars->longFrameInfo;
    146     pVars->winmap[LONG_START_SEQUENCE]  = &pVars->longFrameInfo;
    147     pVars->winmap[EIGHT_SHORT_SEQUENCE] = &pVars->shortFrameInfo;
    148     pVars->winmap[LONG_STOP_SEQUENCE]   = &pVars->longFrameInfo;
    149 
    150     CALL infoinit(
    151         samp_rate_indx = pVars->mc_info.sampling_rate_idx,
    152         ppWin_seq_info = pVars->winmap,
    153         pSfbwidth128   = pVars->SFBWidth128)
    154     MODIFYING(ppWinSeq_info)
    155     MODIFYING(pSfbwidth128)
    156     RETURNING(nothing)
    157 
    158     pExt->bitRate = 0;
    159     pExt->encodedChannels = 0;
    160     pExt->samplingRate = 0;
    161     pExt->inputBufferUsedLength = 0;
    162 
    163     MODIFY(pExt)
    164     MODIFY(pMem)
    165     RETURN(SUCCESS)
    166 
    167 ------------------------------------------------------------------------------
    168  RESOURCES USED
    169    When the code is written for a specific target processor the
    170      the resources used should be documented below.
    171 
    172  STACK USAGE: [stack count for this module] + [variable to represent
    173           stack usage for each subroutine called]
    174 
    175      where: [stack usage variable] = stack usage for [subroutine
    176          name] (see [filename].ext)
    177 
    178  DATA MEMORY USED: x words
    179 
    180  PROGRAM MEMORY USED: x words
    181 
    182  CLOCK CYCLES: [cycle count equation for this module] + [variable
    183            used to represent cycle count for each subroutine
    184            called]
    185 
    186      where: [cycle count variable] = cycle count for [subroutine
    187         name] (see [filename].ext)
    188 
    189 ------------------------------------------------------------------------------
    190 */
    191 
    192 
    193 /*----------------------------------------------------------------------------
    194 ; INCLUDES
    195 ----------------------------------------------------------------------------*/
    196 
    197 #include "pv_audio_type_defs.h"
    198 #include "s_tdec_int_file.h"
    199 #include "e_progconfigconst.h"
    200 
    201 #include "huffman.h"               /* For the definition of infoinit        */
    202 #include "aac_mem_funcs.h"         /* For pv_memset                         */
    203 #include "pvmp4audiodecoder_api.h" /* Where this function is declared       */
    204 #include "s_tdec_int_chan.h"
    205 #include "sfb.h"                   /* samp_rate_info[] is declared here     */
    206 
    207 /*----------------------------------------------------------------------------
    208 ; MACROS
    209 ; Define module specific macros here
    210 ----------------------------------------------------------------------------*/
    211 
    212 /*----------------------------------------------------------------------------
    213 ; DEFINES
    214 ; Include all pre-processor statements here. Include conditional
    215 ; compile variables also.
    216 ----------------------------------------------------------------------------*/
    217 
    218 /*----------------------------------------------------------------------------
    219 ; LOCAL FUNCTION DEFINITIONS
    220 ; Function Prototype declaration
    221 ----------------------------------------------------------------------------*/
    222 
    223 /*----------------------------------------------------------------------------
    224 ; LOCAL VARIABLE DEFINITIONS
    225 ; Variable declaration - defined here and used outside this module
    226 ----------------------------------------------------------------------------*/
    227 
    228 /*----------------------------------------------------------------------------
    229 ; EXTERNAL FUNCTION REFERENCES
    230 ; Declare functions defined elsewhere and referenced in this module
    231 ----------------------------------------------------------------------------*/
    232 
    233 /*----------------------------------------------------------------------------
    234 ; EXTERNAL VARIABLES REFERENCES
    235 ; Declare variables used in this module but defined elsewhere
    236 ----------------------------------------------------------------------------*/
    237 
    238 /*----------------------------------------------------------------------------
    239 ; FUNCTION CODE
    240 ----------------------------------------------------------------------------*/
    241 OSCL_EXPORT_REF Int PVMP4AudioDecoderInitLibrary(
    242     tPVMP4AudioDecoderExternal  *pExt,
    243     void                        *pMem)
    244 {
    245     tDec_Int_File *pVars;
    246 
    247     pVars = (tDec_Int_File *)pMem;
    248 
    249     /*
    250      * Initialize all memory. The pointers to channel memory will be
    251      * set to zero also.
    252      */
    253     pv_memset(
    254         pVars,
    255         0,
    256         sizeof(tDec_Int_File));
    257 
    258     /*
    259      * Pick default values for the library.
    260      */
    261     pVars->perChan[0].fxpCoef = pVars->fxpCoef[0];
    262     pVars->perChan[1].fxpCoef = pVars->fxpCoef[1];
    263 
    264     /* Here, the "shared memory" pointer is set to point
    265      * at the 1024th element of fxpCoef, because those spaces
    266      * in memory are not used until the filterbank is called.
    267      *
    268      * Therefore, any variables that are only used before
    269      * the filterbank can occupy this same space in memory.
    270      */
    271 
    272     pVars->perChan[0].pShareWfxpCoef = (per_chan_share_w_fxpCoef *)
    273                                        & (pVars->perChan[0].fxpCoef[1024]);
    274 
    275     pVars->perChan[1].pShareWfxpCoef = (per_chan_share_w_fxpCoef *)
    276                                        & (pVars->perChan[1].fxpCoef[1024]);
    277 
    278     /*
    279      * This next line informs the function get_prog_config that no
    280      * configuration has been found thus far, so it is a default
    281      * configuration.
    282      */
    283 
    284     pVars->current_program = -1;
    285     pVars->mc_info.sampling_rate_idx = Fs_44; /* Fs_44 = 4, 44.1kHz */
    286 
    287     /*
    288      * In the future, the frame length will change with MP4 file format.
    289      * Presently this variable is used to simply the unit test for
    290      * the function PVMP4AudioDecodeFrame() .. otherwise the test would
    291      * have to pass around 1024 length arrays.
    292      */
    293     pVars->frameLength = LONG_WINDOW; /* 1024*/
    294 
    295     /*
    296      * The window types ONLY_LONG_SEQUENCE, LONG_START_SEQUENCE, and
    297      * LONG_STOP_SEQUENCE share the same information. The only difference
    298      * between the windows is accounted for in the "filterbank", in
    299      * the function trans4m_freq_2_time_fxp()
    300      */
    301 
    302     pVars->winmap[ONLY_LONG_SEQUENCE]   /* 0 */ = &pVars->longFrameInfo;
    303     pVars->winmap[LONG_START_SEQUENCE]  /* 1 */ = &pVars->longFrameInfo;
    304     pVars->winmap[EIGHT_SHORT_SEQUENCE] /* 2 */ = &pVars->shortFrameInfo;
    305     pVars->winmap[LONG_STOP_SEQUENCE]   /* 3 */ = &pVars->longFrameInfo;
    306 
    307     infoinit(
    308         pVars->mc_info.sampling_rate_idx,
    309         (FrameInfo   **)pVars->winmap,
    310         pVars->SFBWidth128);
    311 
    312 
    313     /*
    314      * Clear out external output values. These values are set later at the end
    315      * of PVMP4AudioDecodeFrames()
    316      */
    317     pExt->bitRate = 0;
    318     pExt->encodedChannels = 0;
    319     pExt->samplingRate = 0;
    320     pExt->aacPlusUpsamplingFactor = 1;  /*  Default for regular AAC */
    321     pVars->aacPlusEnabled = pExt->aacPlusEnabled;
    322 
    323 
    324 #if defined(AAC_PLUS)
    325     pVars->sbrDecoderData.setStreamType = 1;        /* Enable Lock for AAC stream type setting  */
    326 #endif
    327 
    328     /*
    329      * Initialize input buffer variable.
    330      */
    331 
    332     pExt->inputBufferUsedLength = 0;
    333 
    334     return (MP4AUDEC_SUCCESS);
    335 
    336 }  /* PVMP4AudioDecoderInitLibrary */
    337 
    338 
    339 /*
    340 ------------------------------------------------------------------------------
    341  INPUT AND OUTPUT DEFINITIONS
    342 
    343  Inputs:
    344     pExt = pointer to the external application-program interface (API)
    345            structure that a client program uses to communicate information
    346            with this library. Among the items in this structure is a pointer
    347            to the input and output buffers, data for handling the input buffer
    348            and output information. Look in PVMP4AudioDecoder_API.h for all the
    349            fields to this structure. Data type pointer to a
    350            tPVMP4AudioDecoderExternal structure.
    351 
    352    pMem =  pointer to allocated memory, of the size returned by the function
    353            PVMP4AudioDecoderGetMemRequirements. This is a void pointer for
    354            two reasons:
    355            1) So the external program does not need all of the header files
    356               for all of the fields in the structure tDec_Int_File
    357            2) To hide data and the implementation of the program. Even knowing
    358               how data is stored can help in reverse engineering software.
    359 
    360  Local Stores/Buffers/Pointers Needed: None
    361 
    362  Global Stores/Buffers/Pointers Needed: None
    363 
    364  Outputs:
    365     status = 0 (SUCCESS). Presently there is no error checking in this
    366     function.
    367 
    368  Pointers and Buffers Modified: None
    369 
    370  Local Stores Modified: None
    371 
    372  Global Stores Modified: None
    373 
    374 ------------------------------------------------------------------------------
    375  FUNCTION DESCRIPTION
    376 
    377  Disable SBR decoding functionality and set parameters accordingly
    378 
    379 ------------------------------------------------------------------------------
    380  REQUIREMENTS
    381 
    382 
    383 ----------------------------------------------------------------------------
    384 ; FUNCTION CODE
    385 ----------------------------------------------------------------------------*/
    386 
    387 
    388 OSCL_EXPORT_REF void PVMP4AudioDecoderDisableAacPlus(
    389     tPVMP4AudioDecoderExternal  *pExt,
    390     void                        *pMem)
    391 {
    392     tDec_Int_File *pVars;
    393 
    394     pVars = (tDec_Int_File *)pMem;
    395 
    396     if ((pVars->aacPlusEnabled == true) && (pExt->aacPlusEnabled == true))
    397     {
    398         // disable only when makes sense
    399         pVars->aacPlusEnabled = false;
    400         pExt->aacPlusEnabled = false;
    401 
    402 #if defined(AAC_PLUS)
    403         pVars->mc_info.upsamplingFactor = 1;
    404         pVars->mc_info.psPresentFlag  = 0;
    405         pVars->mc_info.sbrPresentFlag = 0;
    406         pVars->prog_config.sampling_rate_idx += 3;
    407         pVars->sbrDecoderData.SbrChannel[0].syncState = SBR_NOT_INITIALIZED;
    408         pVars->sbrDecoderData.SbrChannel[1].syncState = SBR_NOT_INITIALIZED;
    409 
    410 
    411         pExt->samplingRate = samp_rate_info[pVars->prog_config.sampling_rate_idx].samp_rate;
    412         pExt->aacPlusUpsamplingFactor = 1;
    413 #endif
    414     }
    415 }  /* PVMP4AudioDecoderDisableAacPlus */
    416 
    417 
    418 
    419