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  INPUT AND OUTPUT DEFINITIONS
     21 
     22  Inputs:
     23     pInputStream = pointer to a BITS structure that holds information
     24                    regarding the input stream.
     25 
     26  Local Stores/Buffers/Pointers Needed:
     27     None
     28 
     29  Global Stores/Buffers/Pointers Needed:
     30     None
     31 
     32  Outputs:
     33     None
     34 
     35  Pointers and Buffers Modified:
     36     pInputStream->usedBits is rounded up to a number that represents the next
     37     byte boundary.
     38 
     39  Local Stores Modified:
     40     None
     41 
     42  Global Stores Modified:
     43     None
     44 
     45 ------------------------------------------------------------------------------
     46  FUNCTION DESCRIPTION
     47 
     48  Makes the input stream structure pointed to align to the next byte boundary.
     49  If it is already at a byte boundary it is left alone.
     50 
     51 ------------------------------------------------------------------------------
     52  REQUIREMENTS
     53 
     54   This function shall not use global or static variables.
     55 
     56 ------------------------------------------------------------------------------
     57  REFERENCES
     58 
     59  (1) MPEG-2 NBC Audio Decoder
     60    "This software module was originally developed by AT&T, Dolby
     61    Laboratories, Fraunhofer Gesellschaft IIS in the course of development
     62    of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and
     63    3. This software module is an implementation of a part of one or more
     64    MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4
     65    Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio
     66    standards free license to this software module or modifications thereof
     67    for use in hardware or software products claiming conformance to the
     68    MPEG-2 NBC/MPEG-4 Audio  standards. Those intending to use this software
     69    module in hardware or software products are advised that this use may
     70    infringe existing patents. The original developer of this software
     71    module and his/her company, the subsequent editors and their companies,
     72    and ISO/IEC have no liability for use of this software module or
     73    modifications thereof in an implementation. Copyright is not released
     74    for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original
     75    developer retains full right to use the code for his/her own purpose,
     76    assign or donate the code to a third party and to inhibit third party
     77    from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products.
     78    This copyright notice must be included in all copies or derivative
     79    works."
     80    Copyright(c)1996.
     81 
     82 ------------------------------------------------------------------------------
     83  PSEUDO-CODE
     84 
     85 void byte_align(
     86     BITS  *pInputStream)
     87 
     88     MODIFYING(pInputStream->usedBits = pInputStream->usedBits +
     89                 (pInputStream->usedBits + 7) % 8)
     90 
     91     RETURN(nothing)
     92 
     93 ------------------------------------------------------------------------------
     94  RESOURCES USED
     95 
     96  STACK USAGE:
     97 
     98      where:
     99 
    100  DATA MEMORY USED: x words
    101 
    102  PROGRAM MEMORY USED: x words
    103 
    104  CLOCK CYCLES:
    105 
    106 ------------------------------------------------------------------------------
    107 */
    108 
    109 
    110 /*----------------------------------------------------------------------------
    111 ; INCLUDES
    112 ----------------------------------------------------------------------------*/
    113 
    114 
    115 
    116 #include "pv_audio_type_defs.h"
    117 #include "s_bits.h"
    118 #include "ibstream.h"
    119 
    120 /*----------------------------------------------------------------------------
    121 ; MACROS
    122 ; Define module specific macros here
    123 ----------------------------------------------------------------------------*/
    124 
    125 /*----------------------------------------------------------------------------
    126 ; DEFINES
    127 ; Include all pre-processor statements here. Include conditional
    128 ; compile variables also.
    129 ----------------------------------------------------------------------------*/
    130 
    131 /*
    132  * A negative number was used for this mask so that it works on both
    133  * 16-bit or 32-bit machines. The mask must be cast to unsigned int to
    134  * work with TI compiler, ver 1.80.
    135  */
    136 #define BYTE_ALIGN_MASK    ((UInt)(-8))
    137 
    138 #define BYTE_ALIGN_ROUNDUP  7
    139 
    140 /*----------------------------------------------------------------------------
    141 ; LOCAL FUNCTION DEFINITIONS
    142 ; Function Prototype declaration
    143 ----------------------------------------------------------------------------*/
    144 
    145 /*----------------------------------------------------------------------------
    146 ; LOCAL VARIABLE DEFINITIONS
    147 ; Variable declaration - defined here and used outside this module
    148 ----------------------------------------------------------------------------*/
    149 
    150 /*----------------------------------------------------------------------------
    151 ; EXTERNAL FUNCTION REFERENCES
    152 ; Declare functions defined elsewhere and referenced in this module
    153 ----------------------------------------------------------------------------*/
    154 
    155 /*----------------------------------------------------------------------------
    156 ; EXTERNAL VARIABLES REFERENCES
    157 ; Declare variables used in this module but defined elsewhere
    158 ----------------------------------------------------------------------------*/
    159 
    160 /*----------------------------------------------------------------------------
    161 ; FUNCTION CODE
    162 ----------------------------------------------------------------------------*/
    163 void byte_align(
    164     BITS  *pInputStream)
    165 {
    166     /*
    167      * Round up to the next byte by adding 7 and masking off with
    168      * FFF8 or FFFFFFF8. The masking operation is a faster way to
    169      * perform modulo arithmetic if the number is a power of 2.
    170      *
    171      * This code is the same as
    172      * pInputStream->usedBits += (pInputStream->usedBits + 7) % 8
    173      */
    174     pInputStream->usedBits += BYTE_ALIGN_ROUNDUP;
    175     pInputStream->usedBits &= BYTE_ALIGN_MASK;
    176 
    177     return;
    178 }
    179 
    180