ps_syntax.c

00001 /*
00002 ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
00003 ** Copyright (C) 2003-2005 M. Bakker, Ahead Software AG, http://www.nero.com
00004 **  
00005 ** This program is free software; you can redistribute it and/or modify
00006 ** it under the terms of the GNU General Public License as published by
00007 ** the Free Software Foundation; either version 2 of the License, or
00008 ** (at your option) any later version.
00009 ** 
00010 ** This program is distributed in the hope that it will be useful,
00011 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 ** GNU General Public License for more details.
00014 ** 
00015 ** You should have received a copy of the GNU General Public License
00016 ** along with this program; if not, write to the Free Software 
00017 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00018 **
00019 ** Any non-GPL usage of this software or parts of this software is strictly
00020 ** forbidden.
00021 **
00022 ** Software using this code must display the following message visibly in the
00023 ** software:
00024 ** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Ahead Software, www.nero.com"
00025 ** in, for example, the about-box or help/startup screen.
00026 **
00027 ** Commercial non-GPL licensing of this software is possible.
00028 ** For more info contact Ahead Software through [email protected].
00029 **
00030 ** $Id: ps_syntax.c,v 1.2 2005/11/01 21:41:43 gabest Exp $
00031 **/
00032 
00033 #include "common.h"
00034 
00035 #ifdef PS_DEC
00036 
00037 #include "bits.h"
00038 #include "ps_dec.h"
00039 
00040 /* type definitaions */
00041 typedef const int8_t (*ps_huff_tab)[2];
00042 
00043 /* static data tables */
00044 static const uint8_t nr_iid_par_tab[] = {
00045     10, 20, 34, 10, 20, 34, 0, 0
00046 };
00047 static const uint8_t nr_ipdopd_par_tab[] = {
00048     5, 11, 17, 5, 11, 17, 0, 0
00049 };
00050 static const uint8_t nr_icc_par_tab[] = {
00051     10, 20, 34, 10, 20, 34, 0, 0
00052 };
00053 static const uint8_t num_env_tab[][4] = {
00054     { 0, 1, 2, 4 },
00055     { 1, 2, 3, 4 }
00056 };
00057 
00058 /* binary lookup huffman tables */
00059 static const int8_t f_huff_iid_def[][2] = {
00060     { /*0*/ -31, 1 },             /* index 0: 1 bits: x */
00061     { 2, 3 },                     /* index 1: 2 bits: 1x */
00062     { /*1*/ -30, /*-1*/ -32 },    /* index 2: 3 bits: 10x */
00063     { 4, 5 },                     /* index 3: 3 bits: 11x */
00064     { /*2*/ -29, /*-2*/ -33 },    /* index 4: 4 bits: 110x */
00065     { 6, 7 },                     /* index 5: 4 bits: 111x */
00066     { /*3*/ -28, /*-3*/ -34 },    /* index 6: 5 bits: 1110x */
00067     { 8, 9 },                     /* index 7: 5 bits: 1111x */
00068     { /*-4*/ -35, /*4*/ -27 },    /* index 8: 6 bits: 11110x */
00069     { /*5*/ -26, 10 },            /* index 9: 6 bits: 11111x */
00070     { /*-5*/ -36, 11 },           /* index 10: 7 bits: 111111x */
00071     { /*6*/ -25, 12 },            /* index 11: 8 bits: 1111111x */
00072     { /*-6*/ -37, 13 },           /* index 12: 9 bits: 11111111x */
00073     { /*-7*/ -38, 14 },           /* index 13: 10 bits: 111111111x */
00074     { /*7*/ -24, 15 },            /* index 14: 11 bits: 1111111111x */
00075     { 16, 17 },                   /* index 15: 12 bits: 11111111111x */
00076     { /*8*/ -23, /*-8*/ -39 },    /* index 16: 13 bits: 111111111110x */
00077     { 18, 19 },                   /* index 17: 13 bits: 111111111111x */
00078     { /*9*/ -22, /*10*/ -21 },    /* index 18: 14 bits: 1111111111110x */
00079     { 20, 21 },                   /* index 19: 14 bits: 1111111111111x */
00080     { /*-9*/ -40, /*11*/ -20 },   /* index 20: 15 bits: 11111111111110x */
00081     { 22, 23 },                   /* index 21: 15 bits: 11111111111111x */
00082     { /*-10*/ -41, 24 },          /* index 22: 16 bits: 111111111111110x */
00083     { 25, 26 },                   /* index 23: 16 bits: 111111111111111x */
00084     { /*-11*/ -42, /*-14*/ -45 }, /* index 24: 17 bits: 1111111111111101x */
00085     { /*-13*/ -44, /*-12*/ -43 }, /* index 25: 17 bits: 1111111111111110x */
00086     { /*12*/ -19, 27 },           /* index 26: 17 bits: 1111111111111111x */
00087     { /*13*/ -18, /*14*/ -17 }    /* index 27: 18 bits: 11111111111111111x */
00088 };
00089 
00090 static const int8_t t_huff_iid_def[][2] = {
00091     { /*0*/ -31, 1 },             /* index 0: 1 bits: x */
00092     { /*-1*/ -32, 2 },            /* index 1: 2 bits: 1x */
00093     { /*1*/ -30, 3 },             /* index 2: 3 bits: 11x */
00094     { /*-2*/ -33, 4 },            /* index 3: 4 bits: 111x */
00095     { /*2*/ -29, 5 },             /* index 4: 5 bits: 1111x */
00096     { /*-3*/ -34, 6 },            /* index 5: 6 bits: 11111x */
00097     { /*3*/ -28, 7 },             /* index 6: 7 bits: 111111x */
00098     { /*-4*/ -35, 8 },            /* index 7: 8 bits: 1111111x */
00099     { /*4*/ -27, 9 },             /* index 8: 9 bits: 11111111x */
00100     { /*-5*/ -36, 10 },           /* index 9: 10 bits: 111111111x */
00101     { /*5*/ -26, 11 },            /* index 10: 11 bits: 1111111111x */
00102     { /*-6*/ -37, 12 },           /* index 11: 12 bits: 11111111111x */
00103     { /*6*/ -25, 13 },            /* index 12: 13 bits: 111111111111x */
00104     { /*7*/ -24, 14 },            /* index 13: 14 bits: 1111111111111x */
00105     { /*-7*/ -38, 15 },           /* index 14: 15 bits: 11111111111111x */
00106     { 16, 17 },                   /* index 15: 16 bits: 111111111111111x */
00107     { /*8*/ -23, /*-8*/ -39 },    /* index 16: 17 bits: 1111111111111110x */
00108     { 18, 19 },                   /* index 17: 17 bits: 1111111111111111x */
00109     { 20, 21 },                   /* index 18: 18 bits: 11111111111111110x */
00110     { 22, 23 },                   /* index 19: 18 bits: 11111111111111111x */
00111     { /*9*/ -22, /*-14*/ -45 },   /* index 20: 19 bits: 111111111111111100x */
00112     { /*-13*/ -44, /*-12*/ -43 }, /* index 21: 19 bits: 111111111111111101x */
00113     { 24, 25 },                   /* index 22: 19 bits: 111111111111111110x */
00114     { 26, 27 },                   /* index 23: 19 bits: 111111111111111111x */
00115     { /*-11*/ -42, /*-10*/ -41 }, /* index 24: 20 bits: 1111111111111111100x */
00116     { /*-9*/ -40, /*10*/ -21 },   /* index 25: 20 bits: 1111111111111111101x */
00117     { /*11*/ -20, /*12*/ -19 },   /* index 26: 20 bits: 1111111111111111110x */
00118     { /*13*/ -18, /*14*/ -17 }    /* index 27: 20 bits: 1111111111111111111x */
00119 };
00120 
00121 static const int8_t f_huff_iid_fine[][2] = {
00122     { 1, /*0*/ -31 },             /* index 0: 1 bits: x */
00123     { 2, 3 },                     /* index 1: 2 bits: 0x */
00124     { 4, /*-1*/ -32 },            /* index 2: 3 bits: 00x */
00125     { /*1*/ -30, 5 },             /* index 3: 3 bits: 01x */
00126     { /*-2*/ -33, /*2*/ -29 },    /* index 4: 4 bits: 000x */
00127     { 6, 7 },                     /* index 5: 4 bits: 011x */
00128     { /*-3*/ -34, /*3*/ -28 },    /* index 6: 5 bits: 0110x */
00129     { 8, 9 },                     /* index 7: 5 bits: 0111x */
00130     { /*-4*/ -35, /*4*/ -27 },    /* index 8: 6 bits: 01110x */
00131     { 10, 11 },                   /* index 9: 6 bits: 01111x */
00132     { /*-5*/ -36, /*5*/ -26 },    /* index 10: 7 bits: 011110x */
00133     { 12, 13 },                   /* index 11: 7 bits: 011111x */
00134     { /*-6*/ -37, /*6*/ -25 },    /* index 12: 8 bits: 0111110x */
00135     { 14, 15 },                   /* index 13: 8 bits: 0111111x */
00136     { /*7*/ -24, 16 },            /* index 14: 9 bits: 01111110x */
00137     { 17, 18 },                   /* index 15: 9 bits: 01111111x */
00138     { 19, /*-8*/ -39 },           /* index 16: 10 bits: 011111101x */
00139     { /*8*/ -23, 20 },            /* index 17: 10 bits: 011111110x */
00140     { 21, /*-7*/ -38 },           /* index 18: 10 bits: 011111111x */
00141     { /*10*/ -21, 22 },           /* index 19: 11 bits: 0111111010x */
00142     { 23, /*-9*/ -40 },           /* index 20: 11 bits: 0111111101x */
00143     { /*9*/ -22, 24 },            /* index 21: 11 bits: 0111111110x */
00144     { /*-11*/ -42, /*11*/ -20 },  /* index 22: 12 bits: 01111110101x */
00145     { 25, 26 },                   /* index 23: 12 bits: 01111111010x */
00146     { 27, /*-10*/ -41 },          /* index 24: 12 bits: 01111111101x */
00147     { 28, /*-12*/ -43 },          /* index 25: 13 bits: 011111110100x */
00148     { /*12*/ -19, 29 },           /* index 26: 13 bits: 011111110101x */
00149     { 30, 31 },                   /* index 27: 13 bits: 011111111010x */
00150     { 32, /*-14*/ -45 },          /* index 28: 14 bits: 0111111101000x */
00151     { /*14*/ -17, 33 },           /* index 29: 14 bits: 0111111101011x */
00152     { 34, /*-13*/ -44 },          /* index 30: 14 bits: 0111111110100x */
00153     { /*13*/ -18, 35 },           /* index 31: 14 bits: 0111111110101x */
00154     { 36, 37 },                   /* index 32: 15 bits: 01111111010000x */
00155     { 38, /*-15*/ -46 },          /* index 33: 15 bits: 01111111010111x */
00156     { /*15*/ -16, 39 },           /* index 34: 15 bits: 01111111101000x */
00157     { 40, 41 },                   /* index 35: 15 bits: 01111111101011x */
00158     { 42, 43 },                   /* index 36: 16 bits: 011111110100000x */
00159     { /*-17*/ -48, /*17*/ -14 },  /* index 37: 16 bits: 011111110100001x */
00160     { 44, 45 },                   /* index 38: 16 bits: 011111110101110x */
00161     { 46, 47 },                   /* index 39: 16 bits: 011111111010001x */
00162     { 48, 49 },                   /* index 40: 16 bits: 011111111010110x */
00163     { /*-16*/ -47, /*16*/ -15 },  /* index 41: 16 bits: 011111111010111x */
00164     { /*-21*/ -52, /*21*/ -10 },  /* index 42: 17 bits: 0111111101000000x */
00165     { /*-19*/ -50, /*19*/ -12 },  /* index 43: 17 bits: 0111111101000001x */
00166     { /*-18*/ -49, /*18*/ -13 },  /* index 44: 17 bits: 0111111101011100x */
00167     { 50, 51 },                   /* index 45: 17 bits: 0111111101011101x */
00168     { 52, 53 },                   /* index 46: 17 bits: 0111111110100010x */
00169     { 54, 55 },                   /* index 47: 17 bits: 0111111110100011x */
00170     { 56, 57 },                   /* index 48: 17 bits: 0111111110101100x */
00171     { 58, 59 },                   /* index 49: 17 bits: 0111111110101101x */
00172     { /*-26*/ -57, /*-25*/ -56 }, /* index 50: 18 bits: 01111111010111010x */
00173     { /*-28*/ -59, /*-27*/ -58 }, /* index 51: 18 bits: 01111111010111011x */
00174     { /*-22*/ -53, /*22*/ -9 },   /* index 52: 18 bits: 01111111101000100x */
00175     { /*-24*/ -55, /*-23*/ -54 }, /* index 53: 18 bits: 01111111101000101x */
00176     { /*25*/ -6, /*26*/ -5 },     /* index 54: 18 bits: 01111111101000110x */
00177     { /*23*/ -8, /*24*/ -7 },     /* index 55: 18 bits: 01111111101000111x */
00178     { /*29*/ -2, /*30*/ -1 },     /* index 56: 18 bits: 01111111101011000x */
00179     { /*27*/ -4, /*28*/ -3 },     /* index 57: 18 bits: 01111111101011001x */
00180     { /*-30*/ -61, /*-29*/ -60 }, /* index 58: 18 bits: 01111111101011010x */
00181     { /*-20*/ -51, /*20*/ -11 }   /* index 59: 18 bits: 01111111101011011x */
00182 };
00183 
00184 static const int8_t t_huff_iid_fine[][2] = {
00185     { 1, /*0*/ -31 },             /* index 0: 1 bits: x */
00186     { /*1*/ -30, 2 },             /* index 1: 2 bits: 0x */
00187     { 3, /*-1*/ -32 },            /* index 2: 3 bits: 01x */
00188     { 4, 5 },                     /* index 3: 4 bits: 010x */
00189     { 6, 7 },                     /* index 4: 5 bits: 0100x */
00190     { /*-2*/ -33, /*2*/ -29 },    /* index 5: 5 bits: 0101x */
00191     { 8, /*-3*/ -34 },            /* index 6: 6 bits: 01000x */
00192     { /*3*/ -28, 9 },             /* index 7: 6 bits: 01001x */
00193     { /*-4*/ -35, /*4*/ -27 },    /* index 8: 7 bits: 010000x */
00194     { 10, 11 },                   /* index 9: 7 bits: 010011x */
00195     { /*5*/ -26, 12 },            /* index 10: 8 bits: 0100110x */
00196     { 13, 14 },                   /* index 11: 8 bits: 0100111x */
00197     { /*-6*/ -37, /*6*/ -25 },    /* index 12: 9 bits: 01001101x */
00198     { 15, 16 },                   /* index 13: 9 bits: 01001110x */
00199     { 17, /*-5*/ -36 },           /* index 14: 9 bits: 01001111x */
00200     { 18, /*-7*/ -38 },           /* index 15: 10 bits: 010011100x */
00201     { /*7*/ -24, 19 },            /* index 16: 10 bits: 010011101x */
00202     { 20, 21 },                   /* index 17: 10 bits: 010011110x */
00203     { /*9*/ -22, 22 },            /* index 18: 11 bits: 0100111000x */
00204     { 23, 24 },                   /* index 19: 11 bits: 0100111011x */
00205     { /*-8*/ -39, /*8*/ -23 },    /* index 20: 11 bits: 0100111100x */
00206     { 25, 26 },                   /* index 21: 11 bits: 0100111101x */
00207     { /*11*/ -20, 27 },           /* index 22: 12 bits: 01001110001x */
00208     { 28, 29 },                   /* index 23: 12 bits: 01001110110x */
00209     { /*-10*/ -41, /*10*/ -21 },  /* index 24: 12 bits: 01001110111x */
00210     { 30, 31 },                   /* index 25: 12 bits: 01001111010x */
00211     { 32, /*-9*/ -40 },           /* index 26: 12 bits: 01001111011x */
00212     { 33, /*-13*/ -44 },          /* index 27: 13 bits: 010011100011x */
00213     { /*13*/ -18, 34 },           /* index 28: 13 bits: 010011101100x */
00214     { 35, 36 },                   /* index 29: 13 bits: 010011101101x */
00215     { 37, /*-12*/ -43 },          /* index 30: 13 bits: 010011110100x */
00216     { /*12*/ -19, 38 },           /* index 31: 13 bits: 010011110101x */
00217     { 39, /*-11*/ -42 },          /* index 32: 13 bits: 010011110110x */
00218     { 40, 41 },                   /* index 33: 14 bits: 0100111000110x */
00219     { 42, 43 },                   /* index 34: 14 bits: 0100111011001x */
00220     { 44, 45 },                   /* index 35: 14 bits: 0100111011010x */
00221     { 46, /*-15*/ -46 },          /* index 36: 14 bits: 0100111011011x */
00222     { /*15*/ -16, 47 },           /* index 37: 14 bits: 0100111101000x */
00223     { /*-14*/ -45, /*14*/ -17 },  /* index 38: 14 bits: 0100111101011x */
00224     { 48, 49 },                   /* index 39: 14 bits: 0100111101100x */
00225     { /*-21*/ -52, /*-20*/ -51 }, /* index 40: 15 bits: 01001110001100x */
00226     { /*18*/ -13, /*19*/ -12 },   /* index 41: 15 bits: 01001110001101x */
00227     { /*-19*/ -50, /*-18*/ -49 }, /* index 42: 15 bits: 01001110110010x */
00228     { 50, 51 },                   /* index 43: 15 bits: 01001110110011x */
00229     { 52, 53 },                   /* index 44: 15 bits: 01001110110100x */
00230     { 54, 55 },                   /* index 45: 15 bits: 01001110110101x */
00231     { 56, /*-17*/ -48 },          /* index 46: 15 bits: 01001110110110x */
00232     { /*17*/ -14, 57 },           /* index 47: 15 bits: 01001111010001x */
00233     { 58, /*-16*/ -47 },          /* index 48: 15 bits: 01001111011000x */
00234     { /*16*/ -15, 59 },           /* index 49: 15 bits: 01001111011001x */
00235     { /*-26*/ -57, /*26*/ -5 },   /* index 50: 16 bits: 010011101100110x */
00236     { /*-28*/ -59, /*-27*/ -58 }, /* index 51: 16 bits: 010011101100111x */
00237     { /*29*/ -2, /*30*/ -1 },     /* index 52: 16 bits: 010011101101000x */
00238     { /*27*/ -4, /*28*/ -3 },     /* index 53: 16 bits: 010011101101001x */
00239     { /*-30*/ -61, /*-29*/ -60 }, /* index 54: 16 bits: 010011101101010x */
00240     { /*-25*/ -56, /*25*/ -6 },   /* index 55: 16 bits: 010011101101011x */
00241     { /*-24*/ -55, /*24*/ -7 },   /* index 56: 16 bits: 010011101101100x */
00242     { /*-23*/ -54, /*23*/ -8 },   /* index 57: 16 bits: 010011110100011x */
00243     { /*-22*/ -53, /*22*/ -9 },   /* index 58: 16 bits: 010011110110000x */
00244     { /*20*/ -11, /*21*/ -10 }    /* index 59: 16 bits: 010011110110011x */
00245 };
00246 
00247 static const int8_t f_huff_icc[][2] = {
00248     { /*0*/ -31, 1 },            /* index 0: 1 bits: x */
00249     { /*1*/ -30, 2 },            /* index 1: 2 bits: 1x */
00250     { /*-1*/ -32, 3 },           /* index 2: 3 bits: 11x */
00251     { /*2*/ -29, 4 },            /* index 3: 4 bits: 111x */
00252     { /*-2*/ -33, 5 },           /* index 4: 5 bits: 1111x */
00253     { /*3*/ -28, 6 },            /* index 5: 6 bits: 11111x */
00254     { /*-3*/ -34, 7 },           /* index 6: 7 bits: 111111x */
00255     { /*4*/ -27, 8 },            /* index 7: 8 bits: 1111111x */
00256     { /*5*/ -26, 9 },            /* index 8: 9 bits: 11111111x */
00257     { /*-4*/ -35, 10 },          /* index 9: 10 bits: 111111111x */
00258     { /*6*/ -25, 11 },           /* index 10: 11 bits: 1111111111x */
00259     { /*-5*/ -36, 12 },          /* index 11: 12 bits: 11111111111x */
00260     { /*7*/ -24, 13 },           /* index 12: 13 bits: 111111111111x */
00261     { /*-6*/ -37, /*-7*/ -38 }   /* index 13: 14 bits: 1111111111111x */
00262 };
00263 
00264 static const int8_t t_huff_icc[][2] = {
00265     { /*0*/ -31, 1 },            /* index 0: 1 bits: x */
00266     { /*1*/ -30, 2 },            /* index 1: 2 bits: 1x */
00267     { /*-1*/ -32, 3 },           /* index 2: 3 bits: 11x */
00268     { /*2*/ -29, 4 },            /* index 3: 4 bits: 111x */
00269     { /*-2*/ -33, 5 },           /* index 4: 5 bits: 1111x */
00270     { /*3*/ -28, 6 },            /* index 5: 6 bits: 11111x */
00271     { /*-3*/ -34, 7 },           /* index 6: 7 bits: 111111x */
00272     { /*4*/ -27, 8 },            /* index 7: 8 bits: 1111111x */
00273     { /*-4*/ -35, 9 },           /* index 8: 9 bits: 11111111x */
00274     { /*5*/ -26, 10 },           /* index 9: 10 bits: 111111111x */
00275     { /*-5*/ -36, 11 },          /* index 10: 11 bits: 1111111111x */
00276     { /*6*/ -25, 12 },           /* index 11: 12 bits: 11111111111x */
00277     { /*-6*/ -37, 13 },          /* index 12: 13 bits: 111111111111x */
00278     { /*-7*/ -38, /*7*/ -24 }    /* index 13: 14 bits: 1111111111111x */
00279 };
00280 
00281 static const int8_t f_huff_ipd[][2] = {
00282     { 1, /*0*/ -31 },         /* index 0: 1 bits: x */
00283     { 2, 3 },                 /* index 1: 2 bits: 0x */
00284     { /*1*/ -30, 4 },         /* index 2: 3 bits: 00x */
00285     { 5, 6 },                 /* index 3: 3 bits: 01x */
00286     { /*4*/ -27, /*5*/ -26 }, /* index 4: 4 bits: 001x */
00287     { /*3*/ -28, /*6*/ -25 }, /* index 5: 4 bits: 010x */
00288     { /*2*/ -29, /*7*/ -24 }  /* index 6: 4 bits: 011x */
00289 };
00290 
00291 static const int8_t t_huff_ipd[][2] = {
00292     { 1, /*0*/ -31 },         /* index 0: 1 bits: x */
00293     { 2, 3 },                 /* index 1: 2 bits: 0x */
00294     { 4, 5 },                 /* index 2: 3 bits: 00x */
00295     { /*1*/ -30, /*7*/ -24 }, /* index 3: 3 bits: 01x */
00296     { /*5*/ -26, 6 },         /* index 4: 4 bits: 000x */
00297     { /*2*/ -29, /*6*/ -25 }, /* index 5: 4 bits: 001x */
00298     { /*4*/ -27, /*3*/ -28 }  /* index 6: 5 bits: 0001x */
00299 };
00300 
00301 static const int8_t f_huff_opd[][2] = {
00302     { 1, /*0*/ -31 },         /* index 0: 1 bits: x */
00303     { 2, 3 },                 /* index 1: 2 bits: 0x */
00304     { /*7*/ -24, /*1*/ -30 }, /* index 2: 3 bits: 00x */
00305     { 4, 5 },                 /* index 3: 3 bits: 01x */
00306     { /*3*/ -28, /*6*/ -25 }, /* index 4: 4 bits: 010x */
00307     { /*2*/ -29, 6 },         /* index 5: 4 bits: 011x */
00308     { /*5*/ -26, /*4*/ -27 }  /* index 6: 5 bits: 0111x */
00309 };
00310 
00311 static const int8_t t_huff_opd[][2] = {
00312     { 1, /*0*/ -31 },         /* index 0: 1 bits: x */
00313     { 2, 3 },                 /* index 1: 2 bits: 0x */
00314     { 4, 5 },                 /* index 2: 3 bits: 00x */
00315     { /*1*/ -30, /*7*/ -24 }, /* index 3: 3 bits: 01x */
00316     { /*5*/ -26, /*2*/ -29 }, /* index 4: 4 bits: 000x */
00317     { /*6*/ -25, 6 },         /* index 5: 4 bits: 001x */
00318     { /*4*/ -27, /*3*/ -28 }  /* index 6: 5 bits: 0011x */
00319 };
00320 
00321 /* static function declarations */
00322 static uint16_t ps_extension(ps_info *ps, bitfile *ld,
00323                              const uint8_t ps_extension_id,
00324                              const uint16_t num_bits_left);
00325 static void huff_data(bitfile *ld, const uint8_t dt, const uint8_t nr_par,
00326                       ps_huff_tab t_huff, ps_huff_tab f_huff, int8_t *par);
00327 static INLINE int8_t ps_huff_dec(bitfile *ld, ps_huff_tab t_huff);
00328 
00329 
00330 uint16_t ps_data(ps_info *ps, bitfile *ld, uint8_t *header)
00331 {
00332     uint8_t tmp, n;
00333     uint16_t bits = (uint16_t)faad_get_processed_bits(ld);
00334 
00335     *header = 0;
00336 
00337     /* check for new PS header */
00338     if (faad_get1bit(ld
00339         DEBUGVAR(1,1000,"ps_data(): enable_ps_header")))
00340     {
00341         *header = 1;
00342 
00343         ps->header_read = 1;
00344 
00345         ps->use34hybrid_bands = 0;
00346 
00347         /* Inter-channel Intensity Difference (IID) parameters enabled */
00348         ps->enable_iid = (uint8_t)faad_get1bit(ld
00349             DEBUGVAR(1,1001,"ps_data(): enable_iid"));
00350 
00351         if (ps->enable_iid)
00352         {
00353             ps->iid_mode = (uint8_t)faad_getbits(ld, 3
00354                 DEBUGVAR(1,1002,"ps_data(): iid_mode"));
00355 
00356             ps->nr_iid_par = nr_iid_par_tab[ps->iid_mode];
00357             ps->nr_ipdopd_par = nr_ipdopd_par_tab[ps->iid_mode];
00358 
00359             if (ps->iid_mode == 2 || ps->iid_mode == 5)
00360                 ps->use34hybrid_bands = 1;
00361 
00362             /* IPD freq res equal to IID freq res */
00363             ps->ipd_mode = ps->iid_mode;
00364         }
00365 
00366         /* Inter-channel Coherence (ICC) parameters enabled */
00367         ps->enable_icc = (uint8_t)faad_get1bit(ld
00368             DEBUGVAR(1,1003,"ps_data(): enable_icc"));
00369 
00370         if (ps->enable_icc)
00371         {
00372             ps->icc_mode = (uint8_t)faad_getbits(ld, 3
00373                 DEBUGVAR(1,1004,"ps_data(): icc_mode"));
00374 
00375             ps->nr_icc_par = nr_icc_par_tab[ps->icc_mode];
00376 
00377             if (ps->icc_mode == 2 || ps->icc_mode == 5)
00378                 ps->use34hybrid_bands = 1;
00379         }
00380 
00381         /* PS extension layer enabled */
00382         ps->enable_ext = (uint8_t)faad_get1bit(ld
00383             DEBUGVAR(1,1005,"ps_data(): enable_ext"));
00384     }
00385 
00386     /* we are here, but no header has been read yet */
00387     if (ps->header_read == 0)
00388         return 1;
00389 
00390     ps->frame_class = (uint8_t)faad_get1bit(ld
00391         DEBUGVAR(1,1006,"ps_data(): frame_class"));
00392     tmp = (uint8_t)faad_getbits(ld, 2
00393         DEBUGVAR(1,1007,"ps_data(): num_env_idx"));
00394 
00395     ps->num_env = num_env_tab[ps->frame_class][tmp];
00396 
00397     if (ps->frame_class)
00398     {
00399         for (n = 1; n < ps->num_env+1; n++)
00400         {
00401             ps->border_position[n] = (uint8_t)faad_getbits(ld, 5
00402                 DEBUGVAR(1,1008,"ps_data(): border_position"));
00403         }
00404     }
00405 
00406     if (ps->enable_iid)
00407     {
00408         for (n = 0; n < ps->num_env; n++)
00409         {
00410             ps->iid_dt[n] = (uint8_t)faad_get1bit(ld
00411                 DEBUGVAR(1,1009,"ps_data(): iid_dt"));
00412 
00413             /* iid_data */
00414             if (ps->iid_mode < 3)
00415             {
00416                 huff_data(ld, ps->iid_dt[n], ps->nr_iid_par, t_huff_iid_def,
00417                     f_huff_iid_def, ps->iid_index[n]);
00418             } else {
00419                 huff_data(ld, ps->iid_dt[n], ps->nr_iid_par, t_huff_iid_fine,
00420                     f_huff_iid_fine, ps->iid_index[n]);
00421             }
00422         }
00423     }
00424 
00425     if (ps->enable_icc)
00426     {
00427         for (n = 0; n < ps->num_env; n++)
00428         {
00429             ps->icc_dt[n] = (uint8_t)faad_get1bit(ld
00430                 DEBUGVAR(1,1010,"ps_data(): icc_dt"));
00431 
00432             /* icc_data */
00433             huff_data(ld, ps->icc_dt[n], ps->nr_icc_par, t_huff_icc,
00434                 f_huff_icc, ps->icc_index[n]);
00435         }
00436     }
00437 
00438     if (ps->enable_ext)
00439     {
00440         uint16_t num_bits_left;
00441         uint16_t cnt = (uint16_t)faad_getbits(ld, 4
00442             DEBUGVAR(1,1011,"ps_data(): ps_extension_size"));
00443         if (cnt == 15)
00444         {
00445             cnt += (uint16_t)faad_getbits(ld, 8
00446                 DEBUGVAR(1,1012,"ps_data(): esc_count"));
00447         }
00448 
00449         num_bits_left = 8 * cnt;
00450         while (num_bits_left > 7)
00451         {
00452             uint8_t ps_extension_id = (uint8_t)faad_getbits(ld, 2
00453                 DEBUGVAR(1,1013,"ps_data(): ps_extension_size"));
00454 
00455             num_bits_left -= 2;
00456             num_bits_left -= ps_extension(ps, ld, ps_extension_id, num_bits_left);
00457         }
00458 
00459         faad_getbits(ld, num_bits_left
00460             DEBUGVAR(1,1014,"ps_data(): fill_bits"));
00461     }
00462 
00463     bits = (uint16_t)faad_get_processed_bits(ld) - bits;
00464 
00465     ps->ps_data_available = 1;
00466 
00467     return bits;
00468 }
00469 
00470 static uint16_t ps_extension(ps_info *ps, bitfile *ld,
00471                              const uint8_t ps_extension_id,
00472                              const uint16_t num_bits_left)
00473 {
00474     uint8_t n;
00475     uint16_t bits = (uint16_t)faad_get_processed_bits(ld);
00476 
00477     if (ps_extension_id == 0)
00478     {
00479         ps->enable_ipdopd = (uint8_t)faad_get1bit(ld
00480             DEBUGVAR(1,1015,"ps_extension(): enable_ipdopd"));
00481 
00482         if (ps->enable_ipdopd)
00483         {
00484             for (n = 0; n < ps->num_env; n++)
00485             {
00486                 ps->ipd_dt[n] = (uint8_t)faad_get1bit(ld
00487                     DEBUGVAR(1,1016,"ps_extension(): ipd_dt"));
00488 
00489                 /* ipd_data */
00490                 huff_data(ld, ps->ipd_dt[n], ps->nr_ipdopd_par, t_huff_ipd,
00491                     f_huff_ipd, ps->ipd_index[n]);
00492 
00493                 ps->opd_dt[n] = (uint8_t)faad_get1bit(ld
00494                     DEBUGVAR(1,1017,"ps_extension(): opd_dt"));
00495 
00496                 /* opd_data */
00497                 huff_data(ld, ps->opd_dt[n], ps->nr_ipdopd_par, t_huff_opd,
00498                     f_huff_opd, ps->opd_index[n]);
00499             }
00500         }
00501         faad_get1bit(ld
00502             DEBUGVAR(1,1018,"ps_extension(): reserved_ps"));
00503     }
00504 
00505     /* return number of bits read */
00506     bits = (uint16_t)faad_get_processed_bits(ld) - bits;
00507 
00508     return bits;
00509 }
00510 
00511 /* read huffman data coded in either the frequency or the time direction */
00512 static void huff_data(bitfile *ld, const uint8_t dt, const uint8_t nr_par,
00513                       ps_huff_tab t_huff, ps_huff_tab f_huff, int8_t *par)
00514 {
00515     uint8_t n;
00516 
00517     if (dt)
00518     {
00519         /* coded in time direction */
00520         for (n = 0; n < nr_par; n++)
00521         {
00522             par[n] = ps_huff_dec(ld, t_huff);
00523         }
00524     } else {
00525         /* coded in frequency direction */
00526         par[0] = ps_huff_dec(ld, f_huff);
00527 
00528         for (n = 1; n < nr_par; n++)
00529         {
00530             par[n] = ps_huff_dec(ld, f_huff);
00531         }
00532     }
00533 }
00534 
00535 /* binary search huffman decoding */
00536 static INLINE int8_t ps_huff_dec(bitfile *ld, ps_huff_tab t_huff)
00537 {
00538     uint8_t bit;
00539     int16_t index = 0;
00540 
00541     while (index >= 0)
00542     {
00543         bit = (uint8_t)faad_get1bit(ld);
00544         index = t_huff[index][bit];
00545     }
00546 
00547     return index + 31;
00548 }
00549 
00550 #endif

Generated on Tue Dec 13 14:47:42 2005 for guliverkli by  doxygen 1.4.5