Home | History | Annotate | Download | only in src
      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 
     21    PacketVideo Corp.
     22    MP3 Decoder Library
     23 
     24    Filename: pvmp3_mpeg2_get_scale_data.cpp
     25 
     26      Date: 09/21/2007
     27 
     28 ------------------------------------------------------------------------------
     29  REVISION HISTORY
     30 
     31 
     32  Description:
     33 
     34 ------------------------------------------------------------------------------
     35  INPUT AND OUTPUT DEFINITIONS
     36 
     37 Input
     38     mp3SideInfo     *si,                    side information
     39     int32           gr,                     granule
     40     int32           ch,                     channel
     41     mp3Header       *info,                  mp3 header information
     42     uint32          *scalefac_buffer,
     43     uint32          *scalefac_IIP_buffer,
     44     tbits           *pMainData               bit stream Data
     45 
     46  Returns
     47 
     48     uint32          *scalefac_buffer,       acquired scale band data
     49     uint32          *scalefac_IIP_buffer,   auxiliary scale data
     50 
     51 
     52 ------------------------------------------------------------------------------
     53  FUNCTION DESCRIPTION
     54 
     55     get scale data for mpeg2 layer III LSF extension
     56 
     57 ------------------------------------------------------------------------------
     58  REQUIREMENTS
     59 
     60 
     61 ------------------------------------------------------------------------------
     62  REFERENCES
     63 
     64  [1] ISO MPEG Audio Subgroup Software Simulation Group (1996)
     65      ISO 13818-3 MPEG-2 Audio Decoder - Lower Sampling Frequency Extension
     66 
     67 ------------------------------------------------------------------------------
     68  PSEUDO-CODE
     69 
     70 ------------------------------------------------------------------------------
     71 */
     72 
     73 
     74 /*----------------------------------------------------------------------------
     75 ; INCLUDES
     76 ----------------------------------------------------------------------------*/
     77 
     78 #include "pvmp3_mpeg2_get_scale_data.h"
     79 #include "pvmp3_getbits.h"
     80 
     81 
     82 /*----------------------------------------------------------------------------
     83 ; MACROS
     84 ; Define module specific macros here
     85 ----------------------------------------------------------------------------*/
     86 
     87 
     88 /*----------------------------------------------------------------------------
     89 ; DEFINES
     90 ; Include all pre-processor statements here. Include conditional
     91 ; compile variables also.
     92 ----------------------------------------------------------------------------*/
     93 
     94 /*----------------------------------------------------------------------------
     95 ; LOCAL FUNCTION DEFINITIONS
     96 ; Function Prototype declaration
     97 ----------------------------------------------------------------------------*/
     98 
     99 /*----------------------------------------------------------------------------
    100 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
    101 ; Variable declaration - defined here and used outside this module
    102 ----------------------------------------------------------------------------*/
    103 
    104 const uint32 nr_of_sfb_block[6][3][4] =
    105 {   {{ 6,  5, 5, 5}, {  9,  9,  9, 9}, { 6,  9,  9, 9}},
    106     {{ 6,  5, 7, 3}, {  9,  9, 12, 6}, { 6,  9, 12, 6}},
    107     {{11, 10, 0, 0}, { 18, 18,  0, 0}, {15, 18,  0, 0}},
    108     {{ 7,  7, 7, 0}, { 12, 12, 12, 0}, { 6, 15, 12, 0}},
    109     {{ 6,  6, 6, 3}, { 12,  9,  9, 6}, { 6, 12,  9, 6}},
    110     {{ 8,  8, 5, 0}, { 15, 12,  9, 0}, { 6, 18,  9, 0}}
    111 };
    112 
    113 /*----------------------------------------------------------------------------
    114 ; EXTERNAL FUNCTION REFERENCES
    115 ; Declare functions defined elsewhere and referenced in this module
    116 ----------------------------------------------------------------------------*/
    117 
    118 /*----------------------------------------------------------------------------
    119 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
    120 ; Declare variables used in this module but defined elsewhere
    121 ----------------------------------------------------------------------------*/
    122 
    123 /*----------------------------------------------------------------------------
    124 ; FUNCTION CODE
    125 ----------------------------------------------------------------------------*/
    126 
    127 void pvmp3_mpeg2_get_scale_data(mp3SideInfo *si,
    128                                 int32        gr,
    129                                 int32        ch,
    130                                 mp3Header   *info,
    131                                 uint32      *scalefac_buffer,
    132                                 uint32      *scalefac_IIP_buffer,
    133                                 tmp3Bits    *pMainData)
    134 {
    135     int16 i;
    136     int16 j;
    137     int16 k;
    138     int16 blocktypenumber = 0;
    139     int16 blocknumber = 0;
    140 
    141     granuleInfo *gr_info = &(si->ch[ch].gran[gr]);
    142     uint32 scalefac_comp, int_scalefac_comp, new_slen[4];
    143 
    144     scalefac_comp =  gr_info->scalefac_compress;
    145 
    146 
    147 
    148     if ((((info->mode_ext &1)) && (ch == 1)))
    149     {
    150         /*   intensity_scale = scalefac_comp %2; */
    151         int_scalefac_comp = scalefac_comp >> 1;
    152 
    153         if (int_scalefac_comp  < 180)
    154         {
    155             new_slen[0] = int_scalefac_comp  / 36;
    156             new_slen[1] = (int_scalefac_comp % 36) / 6;
    157             new_slen[2] = int_scalefac_comp % 6;
    158             blocknumber = 3;
    159         }
    160         else if (int_scalefac_comp  < 244)
    161         {
    162             int_scalefac_comp -= 180;
    163             new_slen[0] = (int_scalefac_comp & 63) >> 4;
    164             new_slen[1] = (int_scalefac_comp & 15) >> 2;
    165             new_slen[2] =  int_scalefac_comp &  3;
    166             blocknumber = 4;
    167         }
    168         else if (int_scalefac_comp  <= 255)
    169         {
    170             int_scalefac_comp -= 244;
    171             new_slen[0] = (int_scalefac_comp) / 3;
    172             new_slen[1] = (int_scalefac_comp) % 3;
    173             new_slen[2] = 0;
    174             blocknumber = 5;
    175         }
    176         new_slen[3] = 0;
    177         si->ch[ch].gran[gr].preflag = 0;
    178     }
    179     else
    180     {
    181         if (scalefac_comp < 400)
    182         {
    183             new_slen[0] = (scalefac_comp >> 4) / 5;
    184             new_slen[1] = (scalefac_comp >> 4) % 5;
    185             new_slen[2] = (scalefac_comp & 15) >> 2 ;
    186             new_slen[3] = (scalefac_comp & 3);
    187             si->ch[ch].gran[gr].preflag = 0;
    188 
    189             blocknumber = 0;
    190         }
    191         else if (scalefac_comp  < 500)
    192         {
    193             scalefac_comp -= 400;
    194             new_slen[0] = (scalefac_comp >> 2) / 5;
    195             new_slen[1] = (scalefac_comp >> 2) % 5;
    196             new_slen[2] = scalefac_comp  & 3;
    197             new_slen[3] = 0;
    198             si->ch[ch].gran[gr].preflag = 0;
    199             blocknumber = 1;
    200         }
    201         else if (scalefac_comp  < 512)
    202         {
    203             scalefac_comp -= 500;
    204             new_slen[0] = scalefac_comp / 3;
    205             new_slen[1] = scalefac_comp % 3;
    206             new_slen[2] = 0 ;
    207             new_slen[3] = 0;
    208             si->ch[ch].gran[gr].preflag = 1;
    209             blocknumber = 2;
    210         }
    211     }
    212 
    213     if (gr_info->block_type == 2)
    214     {
    215         if (gr_info->mixed_block_flag)
    216         {
    217             blocktypenumber = 2;
    218         }
    219         else
    220         {
    221             blocktypenumber = 1;
    222         }
    223     }
    224 
    225     k = 0;
    226     for (i = 0; i < 4; i++)
    227     {
    228         if (new_slen[i])
    229         {
    230             for (j = 0; j < (int16)nr_of_sfb_block[blocknumber][blocktypenumber][i]; j++)
    231             {
    232                 scalefac_buffer[k] =  getNbits(pMainData, new_slen[i]);
    233                 scalefac_IIP_buffer[k] = (1L << new_slen[i]) - 1;
    234                 k++;
    235             }
    236         }
    237         else
    238         {
    239             for (j = 0; j < (int16)nr_of_sfb_block[blocknumber][blocktypenumber][i]; j++)
    240             {
    241                 scalefac_buffer[k]     = 0;
    242                 scalefac_IIP_buffer[k] = 0;
    243                 k++;
    244             }
    245         }
    246     }
    247 }
    248