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: ./src/deinterleave.c
     21 
     22 ------------------------------------------------------------------------------
     23  REVISION HISTORY
     24 
     25  Description:  Modified from original shareware code
     26 
     27  Description: (1) Modified with new template, rename variables
     28               (2) Removed for-loop to calculate win_inc, win_inc = SN2 (128)
     29               (3) Replaced for-loop with memcpy
     30               (4) Converted Int16 -> Int
     31 
     32  Description: Modified per review comments
     33 
     34  Who:                       Date:
     35  Description:
     36 
     37 ------------------------------------------------------------------------------
     38  INPUT AND OUTPUT DEFINITIONS
     39 
     40  Inputs:
     41     interleaved   = input array that contains interleaved coefficients
     42                     Data Type Int
     43 
     44     deinterleaved = output array that will be updated with de-interleaved
     45                     coefficients of input array. Data Type Int
     46 
     47     pFrameInfo = pointer to structure that holds information of current
     48                  frame. Data Type FrameInfo
     49 
     50  Local Stores/Buffers/Pointers Needed:
     51     None
     52 
     53  Global Stores/Buffers/Pointers Needed:
     54     None
     55 
     56  Outputs:
     57     None
     58 
     59  Pointers and Buffers Modified:
     60     deinterleaved  contents updated with de-interleaved coefficients from
     61                    the input array: interleaved
     62 
     63  Local Stores Modified:
     64     None
     65 
     66  Global Stores Modified:
     67     None
     68 
     69 ------------------------------------------------------------------------------
     70  FUNCTION DESCRIPTION
     71 
     72  This function performs the deinterleaving across all short windows in
     73  each group
     74 
     75 ------------------------------------------------------------------------------
     76  REQUIREMENTS
     77 
     78  This function should replace the contents of pDeinterleaved with the
     79  de-interleaved 1024 coefficients of one frame
     80 
     81 ------------------------------------------------------------------------------
     82  REFERENCES
     83 
     84  (1) MPEG-2 NBC Audio Decoder
     85    "This software module was originally developed by AT&T, Dolby
     86    Laboratories, Fraunhofer Gesellschaft IIS in the course of development
     87    of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and
     88    3. This software module is an implementation of a part of one or more
     89    MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4
     90    Audio standard. ISO/IEC  gives users of the MPEG-2 NBC/MPEG-4 Audio
     91    standards free license to this software module or modifications thereof
     92    for use in hardware or software products claiming conformance to the
     93    MPEG-2 NBC/MPEG-4 Audio  standards. Those intending to use this software
     94    module in hardware or software products are advised that this use may
     95    infringe existing patents. The original developer of this software
     96    module and his/her company, the subsequent editors and their companies,
     97    and ISO/IEC have no liability for use of this software module or
     98    modifications thereof in an implementation. Copyright is not released
     99    for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original
    100    developer retains full right to use the code for his/her own purpose,
    101    assign or donate the code to a third party and to inhibit third party
    102    from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products.
    103    This copyright notice must be included in all copies or derivative
    104    works."
    105    Copyright(c)1996.
    106 
    107  (2) ISO/IEC 14496-3: 1999(E)
    108     Subpart 4           p78     quant_to_spec
    109 
    110 ------------------------------------------------------------------------------
    111  PSEUDO-CODE
    112 
    113     pInterleaved   = interleaved;
    114     pDeinterleaved = deinterleaved;
    115 
    116     pSfbPerWin  = pFrameInfo->sfb_per_win;
    117     ngroups     = pFrameInfo->num_groups;
    118     pGroupLen   = pFrameInfo->group_len;
    119 
    120     pGroup = pDeinterleaved;
    121 
    122     FOR (group = ngroups; group > 0; group--)
    123 
    124         pSfbWidth   = pFrameInfo->sfb_width_128;
    125         sfb_inc = 0;
    126         pStart = pInterleaved;
    127 
    128         FOR (sfb = pSfbPerWin[ngroups-group]; sfb > 0; sfb--)
    129 
    130             pWin = pGroup;
    131 
    132             FOR (win = pGroupLen[ngroups-group]; win > 0; win--)
    133 
    134                 pDeinterleaved = pWin + sfb_inc;
    135 
    136                 pv_memcpy(
    137                      pDeinterleaved,
    138                      pInterleaved,
    139                     *pSfbWidth*sizeof(*pInterleaved));
    140 
    141                 pInterleaved += *pSfbWidth;
    142 
    143                 pWin += SN2;
    144 
    145             ENDFOR (win)
    146 
    147             sfb_inc += *pSfbWidth++;
    148 
    149         ENDFOR (sfb)
    150 
    151     pGroup += (pInterleaved - pStart);
    152 
    153     ENDFOR (group)
    154 
    155 ------------------------------------------------------------------------------
    156  RESOURCES USED
    157    When the code is written for a specific target processor the
    158      the resources used should be documented below.
    159 
    160  STACK USAGE: [stack count for this module] + [variable to represent
    161           stack usage for each subroutine called]
    162 
    163      where: [stack usage variable] = stack usage for [subroutine
    164          name] (see [filename].ext)
    165 
    166  DATA MEMORY USED: x words
    167 
    168  PROGRAM MEMORY USED: x words
    169 
    170  CLOCK CYCLES: [cycle count equation for this module] + [variable
    171            used to represent cycle count for each subroutine
    172            called]
    173 
    174      where: [cycle count variable] = cycle count for [subroutine
    175         name] (see [filename].ext)
    176 
    177 ------------------------------------------------------------------------------
    178 */
    179 
    180 
    181 /*----------------------------------------------------------------------------
    182 ; INCLUDES
    183 ----------------------------------------------------------------------------*/
    184 #include    "pv_audio_type_defs.h"
    185 #include    "huffman.h"
    186 #include    "aac_mem_funcs.h"
    187 
    188 /*----------------------------------------------------------------------------
    189 ; MACROS
    190 ; Define module specific macros here
    191 ----------------------------------------------------------------------------*/
    192 
    193 /*----------------------------------------------------------------------------
    194 ; DEFINES
    195 ; Include all pre-processor statements here. Include conditional
    196 ; compile variables also.
    197 ----------------------------------------------------------------------------*/
    198 
    199 /*----------------------------------------------------------------------------
    200 ; LOCAL FUNCTION DEFINITIONS
    201 ; Function Prototype declaration
    202 ----------------------------------------------------------------------------*/
    203 
    204 /*----------------------------------------------------------------------------
    205 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    206 ; Variable declaration - defined here and used outside this module
    207 ----------------------------------------------------------------------------*/
    208 
    209 /*----------------------------------------------------------------------------
    210 ; EXTERNAL FUNCTION REFERENCES
    211 ; Declare functions defined elsewhere and referenced in this module
    212 ----------------------------------------------------------------------------*/
    213 
    214 /*----------------------------------------------------------------------------
    215 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    216 ; Declare variables used in this module but defined elsewhere
    217 ----------------------------------------------------------------------------*/
    218 
    219 /*----------------------------------------------------------------------------
    220 ; FUNCTION CODE
    221 ----------------------------------------------------------------------------*/
    222 void deinterleave(
    223     Int16        interleaved[],
    224     Int16        deinterleaved[],
    225     FrameInfo   *pFrameInfo)
    226 {
    227 
    228     Int      group;  /* group index */
    229     Int      sfb;    /* scalefactor band index */
    230     Int      win;    /* window index */
    231     Int16    *pGroup;
    232     Int16    *pWin;
    233     Int16    *pStart;
    234     Int16    *pInterleaved;
    235     Int16    *pDeinterleaved;
    236     Int      sfb_inc;
    237 
    238     Int      ngroups;
    239     Int     *pGroupLen;
    240     Int     *pSfbPerWin;
    241     Int     *pSfbWidth;
    242 
    243     pInterleaved   = interleaved;
    244     pDeinterleaved = deinterleaved;
    245 
    246     pSfbPerWin  = pFrameInfo->sfb_per_win;
    247     ngroups     = pFrameInfo->num_groups;
    248     pGroupLen   = pFrameInfo->group_len;
    249 
    250     pGroup = pDeinterleaved;
    251 
    252     for (group = ngroups; group > 0; group--)
    253     {
    254         pSfbWidth   = pFrameInfo->sfb_width_128;
    255         sfb_inc = 0;
    256         pStart = pInterleaved;
    257 
    258         /* Perform the deinterleaving across all windows in a group */
    259 
    260         for (sfb = pSfbPerWin[ngroups-group]; sfb > 0; sfb--)
    261         {
    262             pWin = pGroup;
    263 
    264             for (win = pGroupLen[ngroups-group]; win > 0; win--)
    265             {
    266                 pDeinterleaved = pWin + sfb_inc;
    267 
    268                 pv_memcpy(
    269                     pDeinterleaved,
    270                     pInterleaved,
    271                     *pSfbWidth*sizeof(*pInterleaved));
    272 
    273                 pInterleaved += *pSfbWidth;
    274 
    275                 pWin += SN2;
    276 
    277             } /* for (win) */
    278 
    279             sfb_inc += *pSfbWidth++;
    280 
    281         } /* for (sfb) */
    282 
    283         pGroup += (pInterleaved - pStart);
    284 
    285     } /* for (group) */
    286 
    287 } /* deinterleave */
    288