- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# sbr_tf_grid.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 Mpeg4AAClicense@nero.com.
    00029 **
    00030 ** $Id: sbr_tf_grid.c,v 1.3 2005/11/01 21:41:43 gabest Exp $
    00031 **/
    00032
    00033 /* Time/Frequency grid */
    00034
    00035 #include "common.h"
    00036 #include "structs.h"
    00037
    00038 #ifdef SBR_DEC
    00039
    00040 #include <stdlib.h>
    00041
    00042 #include "sbr_syntax.h"
    00043 #include "sbr_tf_grid.h"
    00044
    00045
    00046 /* static function declarations */
    00047 #if 0
    00048 static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l);
    00049 static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l);
    00050 #endif
    00051 static uint8_t middleBorder(sbr_info *sbr, uint8_t ch);
    00052
    00053
    00054 /* function constructs new time border vector */
    00055 /* first build into temp vector to be able to use previous vector on error */
    00056 uint8_t envelope_time_border_vector(sbr_info *sbr, uint8_t ch)
    00057 {
    00058     uint8_t l, border, temp;
    00059     uint8_t t_E_temp[6] = {0};
    00060
    00061     t_E_temp[0] = sbr->rate * sbr->abs_bord_lead[ch];
    00062     t_E_temp[sbr->L_E[ch]] = sbr->rate * sbr->abs_bord_trail[ch];
    00063
    00064     switch (sbr->bs_frame_class[ch])
    00065     {
    00066     case FIXFIX:
    00067         switch (sbr->L_E[ch])
    00068         {
    00069         case 4:
    00070             temp = (int) (sbr->numTimeSlots / 4);
    00071             t_E_temp[3] = sbr->rate * 3 * temp;
    00072             t_E_temp[2] = sbr->rate * 2 * temp;
    00073             t_E_temp[1] = sbr->rate * temp;
    00074             break;
    00075         case 2:
    00076             t_E_temp[1] = sbr->rate * (int) (sbr->numTimeSlots / 2);
    00077             break;
    00078         default:
    00079             break;
    00080         }
    00081         break;
    00082
    00083     case FIXVAR:
    00084         if (sbr->L_E[ch] > 1)
    00085         {
    00086             int8_t i = sbr->L_E[ch];
    00087             border = sbr->abs_bord_trail[ch];
    00088
    00089             for (l = 0; l < (sbr->L_E[ch] - 1); l++)
    00090             {
    00091                 if (border < sbr->bs_rel_bord[ch][l])
    00092                     return 1;
    00093
    00094                 border -= sbr->bs_rel_bord[ch][l];
    00095                 t_E_temp[--i] = sbr->rate * border;
    00096             }
    00097         }
    00098         break;
    00099
    00100     case VARFIX:
    00101         if (sbr->L_E[ch] > 1)
    00102         {
    00103             int8_t i = 1;
    00104             border = sbr->abs_bord_lead[ch];
    00105
    00106             for (l = 0; l < (sbr->L_E[ch] - 1); l++)
    00107             {
    00108                 border += sbr->bs_rel_bord[ch][l];
    00109
    00110                 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
    00111                     return 1;
    00112
    00113                 t_E_temp[i++] = sbr->rate * border;
    00114             }
    00115         }
    00116         break;
    00117
    00118     case VARVAR:
    00119         if (sbr->bs_num_rel_0[ch])
    00120         {
    00121             int8_t i = 1;
    00122             border = sbr->abs_bord_lead[ch];
    00123
    00124             for (l = 0; l < sbr->bs_num_rel_0[ch]; l++)
    00125             {
    00126                 border += sbr->bs_rel_bord_0[ch][l];
    00127
    00128                 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
    00129                     return 1;
    00130
    00131                 t_E_temp[i++] = sbr->rate * border;
    00132             }
    00133         }
    00134
    00135         if (sbr->bs_num_rel_1[ch])
    00136         {
    00137             int8_t i = sbr->L_E[ch];
    00138             border = sbr->abs_bord_trail[ch];
    00139
    00140             for (l = 0; l < sbr->bs_num_rel_1[ch]; l++)
    00141             {
    00142                 if (border < sbr->bs_rel_bord_1[ch][l])
    00143                     return 1;
    00144
    00145                 border -= sbr->bs_rel_bord_1[ch][l];
    00146                 t_E_temp[--i] = sbr->rate * border;
    00147             }
    00148         }
    00149         break;
    00150     }
    00151
    00152     /* no error occured, we can safely use this t_E vector */
    00153     for (l = 0; l < 6; l++)
    00154     {
    00155         sbr->t_E[ch][l] = t_E_temp[l];
    00156     }
    00157
    00158     return 0;
    00159 }
    00160
    00161 void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch)
    00162 {
    00163     sbr->t_Q[ch][0] = sbr->t_E[ch][0];
    00164
    00165     if (sbr->L_E[ch] == 1)
    00166     {
    00167         sbr->t_Q[ch][1] = sbr->t_E[ch][1];
    00168         sbr->t_Q[ch][2] = 0;
    00169     } else {
    00170         uint8_t index = middleBorder(sbr, ch);
    00171         sbr->t_Q[ch][1] = sbr->t_E[ch][index];
    00172         sbr->t_Q[ch][2] = sbr->t_E[ch][sbr->L_E[ch]];
    00173     }
    00174 }
    00175
    00176 #if 0
    00177 static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l)
    00178 {
    00179     uint8_t i;
    00180     int16_t acc = 0;
    00181
    00182     switch (sbr->bs_frame_class[ch])
    00183     {
    00184     case FIXFIX:
    00185         return sbr->numTimeSlots/sbr->L_E[ch];
    00186     case FIXVAR:
    00187         return 0;
    00188     case VARFIX:
    00189         for (i = 0; i < l; i++)
    00190         {
    00191             acc += sbr->bs_rel_bord[ch][i];
    00192         }
    00193         return acc;
    00194     case VARVAR:
    00195         for (i = 0; i < l; i++)
    00196         {
    00197             acc += sbr->bs_rel_bord_0[ch][i];
    00198         }
    00199         return acc;
    00200     }
    00201
    00202     return 0;
    00203 }
    00204
    00205 static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l)
    00206 {
    00207     uint8_t i;
    00208     int16_t acc = 0;
    00209
    00210     switch (sbr->bs_frame_class[ch])
    00211     {
    00212     case FIXFIX:
    00213     case VARFIX:
    00214         return 0;
    00215     case FIXVAR:
    00216         for (i = 0; i < l; i++)
    00217         {
    00218             acc += sbr->bs_rel_bord[ch][i];
    00219         }
    00220         return acc;
    00221     case VARVAR:
    00222         for (i = 0; i < l; i++)
    00223         {
    00224             acc += sbr->bs_rel_bord_1[ch][i];
    00225         }
    00226         return acc;
    00227     }
    00228
    00229     return 0;
    00230 }
    00231 #endif
    00232
    00233 static uint8_t middleBorder(sbr_info *sbr, uint8_t ch)
    00234 {
    00235     int8_t retval = 0;
    00236
    00237     switch (sbr->bs_frame_class[ch])
    00238     {
    00239     case FIXFIX:
    00240         retval = sbr->L_E[ch]/2;
    00241         break;
    00242     case VARFIX:
    00243         if (sbr->bs_pointer[ch] == 0)
    00244             retval = 1;
    00245         else if (sbr->bs_pointer[ch] == 1)
    00246             retval = sbr->L_E[ch] - 1;
    00247         else
    00248             retval = sbr->bs_pointer[ch] - 1;
    00249         break;
    00250     case FIXVAR:
    00251     case VARVAR:
    00252         if (sbr->bs_pointer[ch] > 1)
    00253             retval = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
    00254         else
    00255             retval = sbr->L_E[ch] - 1;
    00256         break;
    00257     }
    00258
    00259     return (retval > 0) ? retval : 0;
    00260 }
    00261
    00262
    00263 #endif