sbr_tf_grid.c
上传用户:wstnjxml
上传日期:2014-04-03
资源大小:7248k
文件大小:6k
源码类别:

Windows CE

开发平台:

C/C++

  1. /*
  2. ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
  3. ** Copyright (C) 2003-2004 M. Bakker, Ahead Software AG, http://www.nero.com
  4. **  
  5. ** This program is free software; you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation; either version 2 of the License, or
  8. ** (at your option) any later version.
  9. ** 
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13. ** GNU General Public License for more details.
  14. ** 
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program; if not, write to the Free Software 
  17. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  18. **
  19. ** Any non-GPL usage of this software or parts of this software is strictly
  20. ** forbidden.
  21. **
  22. ** Commercial non-GPL licensing of this software is possible.
  23. ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
  24. **
  25. ** $Id: sbr_tf_grid.c,v 1.15 2004/09/04 14:56:28 menno Exp $
  26. **/
  27. /* Time/Frequency grid */
  28. #include "common.h"
  29. #include "structs.h"
  30. #ifdef SBR_DEC
  31. #include <stdlib.h>
  32. #include "sbr_syntax.h"
  33. #include "sbr_tf_grid.h"
  34. /* static function declarations */
  35. #if 0
  36. static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l);
  37. static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l);
  38. #endif
  39. static uint8_t middleBorder(sbr_info *sbr, uint8_t ch);
  40. /* function constructs new time border vector */
  41. /* first build into temp vector to be able to use previous vector on error */
  42. uint8_t envelope_time_border_vector(sbr_info *sbr, uint8_t ch)
  43. {
  44.     uint8_t l, border, temp;
  45.     uint8_t t_E_temp[6] = {0};
  46.     t_E_temp[0] = sbr->rate * sbr->abs_bord_lead[ch];
  47.     t_E_temp[sbr->L_E[ch]] = sbr->rate * sbr->abs_bord_trail[ch];
  48.     switch (sbr->bs_frame_class[ch])
  49.     {
  50.     case FIXFIX:
  51.         switch (sbr->L_E[ch])
  52.         {
  53.         case 4:
  54.             temp = (int) (sbr->numTimeSlots / 4);
  55.             t_E_temp[3] = sbr->rate * 3 * temp;
  56.             t_E_temp[2] = sbr->rate * 2 * temp;
  57.             t_E_temp[1] = sbr->rate * temp;
  58.             break;
  59.         case 2:
  60.             t_E_temp[1] = sbr->rate * (int) (sbr->numTimeSlots / 2);
  61.             break;
  62.         default:
  63.             break;
  64.         }
  65.         break;
  66.     case FIXVAR:
  67.         if (sbr->L_E[ch] > 1)
  68.         {
  69.             int8_t i = sbr->L_E[ch];
  70.             border = sbr->abs_bord_trail[ch];
  71.             for (l = 0; l < (sbr->L_E[ch] - 1); l++)
  72.             {
  73.                 if (border < sbr->bs_rel_bord[ch][l])
  74.                     return 1;
  75.                 border -= sbr->bs_rel_bord[ch][l];
  76.                 t_E_temp[--i] = sbr->rate * border;
  77.             }
  78.         }
  79.         break;
  80.     case VARFIX:
  81.         if (sbr->L_E[ch] > 1)
  82.         {
  83.             int8_t i = 1;
  84.             border = sbr->abs_bord_lead[ch];
  85.             for (l = 0; l < (sbr->L_E[ch] - 1); l++)
  86.             {
  87.                 border += sbr->bs_rel_bord[ch][l];
  88.                 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
  89.                     return 1;
  90.                 t_E_temp[i++] = sbr->rate * border;
  91.             }
  92.         }
  93.         break;
  94.     case VARVAR:
  95.         if (sbr->bs_num_rel_0[ch])
  96.         {
  97.             int8_t i = 1;
  98.             border = sbr->abs_bord_lead[ch];
  99.             for (l = 0; l < sbr->bs_num_rel_0[ch]; l++)
  100.             {
  101.                 border += sbr->bs_rel_bord_0[ch][l];
  102.                 if (sbr->rate * border + sbr->tHFAdj > sbr->numTimeSlotsRate+sbr->tHFGen)
  103.                     return 1;
  104.                 t_E_temp[i++] = sbr->rate * border;
  105.             }
  106.         }
  107.         if (sbr->bs_num_rel_1[ch])
  108.         {
  109.             int8_t i = sbr->L_E[ch];
  110.             border = sbr->abs_bord_trail[ch];
  111.             for (l = 0; l < sbr->bs_num_rel_1[ch]; l++)
  112.             {
  113.                 if (border < sbr->bs_rel_bord_1[ch][l])
  114.                     return 1;
  115.                 border -= sbr->bs_rel_bord_1[ch][l];
  116.                 t_E_temp[--i] = sbr->rate * border;
  117.             }
  118.         }
  119.         break;
  120.     }
  121.     /* no error occured, we can safely use this t_E vector */
  122.     for (l = 0; l < 6; l++)
  123.     {
  124.         sbr->t_E[ch][l] = t_E_temp[l];
  125.     }
  126.     return 0;
  127. }
  128. void noise_floor_time_border_vector(sbr_info *sbr, uint8_t ch)
  129. {
  130.     sbr->t_Q[ch][0] = sbr->t_E[ch][0];
  131.     if (sbr->L_E[ch] == 1)
  132.     {
  133.         sbr->t_Q[ch][1] = sbr->t_E[ch][1];
  134.         sbr->t_Q[ch][2] = 0;
  135.     } else {
  136.         uint8_t index = middleBorder(sbr, ch);
  137.         sbr->t_Q[ch][1] = sbr->t_E[ch][index];
  138.         sbr->t_Q[ch][2] = sbr->t_E[ch][sbr->L_E[ch]];
  139.     }
  140. }
  141. #if 0
  142. static int16_t rel_bord_lead(sbr_info *sbr, uint8_t ch, uint8_t l)
  143. {
  144.     uint8_t i;
  145.     int16_t acc = 0;
  146.     switch (sbr->bs_frame_class[ch])
  147.     {
  148.     case FIXFIX:
  149.         return sbr->numTimeSlots/sbr->L_E[ch];
  150.     case FIXVAR:
  151.         return 0;
  152.     case VARFIX:
  153.         for (i = 0; i < l; i++)
  154.         {
  155.             acc += sbr->bs_rel_bord[ch][i];
  156.         }
  157.         return acc;
  158.     case VARVAR:
  159.         for (i = 0; i < l; i++)
  160.         {
  161.             acc += sbr->bs_rel_bord_0[ch][i];
  162.         }
  163.         return acc;
  164.     }
  165.     return 0;
  166. }
  167. static int16_t rel_bord_trail(sbr_info *sbr, uint8_t ch, uint8_t l)
  168. {
  169.     uint8_t i;
  170.     int16_t acc = 0;
  171.     switch (sbr->bs_frame_class[ch])
  172.     {
  173.     case FIXFIX:
  174.     case VARFIX:
  175.         return 0;
  176.     case FIXVAR:
  177.         for (i = 0; i < l; i++)
  178.         {
  179.             acc += sbr->bs_rel_bord[ch][i];
  180.         }
  181.         return acc;
  182.     case VARVAR:
  183.         for (i = 0; i < l; i++)
  184.         {
  185.             acc += sbr->bs_rel_bord_1[ch][i];
  186.         }
  187.         return acc;
  188.     }
  189.     return 0;
  190. }
  191. #endif
  192. static uint8_t middleBorder(sbr_info *sbr, uint8_t ch)
  193. {
  194.     int8_t retval = 0;
  195.     switch (sbr->bs_frame_class[ch])
  196.     {
  197.     case FIXFIX:
  198.         retval = sbr->L_E[ch]/2;
  199.         break;
  200.     case VARFIX:
  201.         if (sbr->bs_pointer[ch] == 0)
  202.             retval = 1;
  203.         else if (sbr->bs_pointer[ch] == 1)
  204.             retval = sbr->L_E[ch] - 1;
  205.         else
  206.             retval = sbr->bs_pointer[ch] - 1;
  207.         break;
  208.     case FIXVAR:
  209.     case VARVAR:
  210.         if (sbr->bs_pointer[ch] > 1)
  211.             retval = sbr->L_E[ch] + 1 - sbr->bs_pointer[ch];
  212.         else
  213.             retval = sbr->L_E[ch] - 1;
  214.         break;
  215.     }
  216.     return (retval > 0) ? retval : 0;
  217. }
  218. #endif