ssr_fb.c
上传用户:xjjlds
上传日期:2015-12-05
资源大小:22823k
文件大小:7k
源码类别:

多媒体编程

开发平台:

Visual C++

  1. /*
  2. ** FAAD2 - Freeware Advanced Audio (AAC) Decoder including SBR decoding
  3. ** Copyright (C) 2003-2005 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. ** Software using this code must display the following message visibly in the
  23. ** software:
  24. ** "FAAD2 AAC/HE-AAC/HE-AACv2/DRM decoder (c) Ahead Software, www.nero.com"
  25. ** in, for example, the about-box or help/startup screen.
  26. **
  27. ** Commercial non-GPL licensing of this software is possible.
  28. ** For more info contact Ahead Software through Mpeg4AAClicense@nero.com.
  29. **
  30. ** $Id: ssr_fb.c,v 1.2 2005/11/01 21:41:43 gabest Exp $
  31. **/
  32. #include "common.h"
  33. #include "structs.h"
  34. #ifdef SSR_DEC
  35. #include <string.h>
  36. #include <stdlib.h>
  37. #include "syntax.h"
  38. #include "filtbank.h"
  39. #include "mdct.h"
  40. #include "ssr_fb.h"
  41. #include "ssr_win.h"
  42. fb_info *ssr_filter_bank_init(uint16_t frame_len)
  43. {
  44.     uint16_t nshort = frame_len/8;
  45.     fb_info *fb = (fb_info*)faad_malloc(sizeof(fb_info));
  46.     memset(fb, 0, sizeof(fb_info));
  47.     /* normal */
  48.     fb->mdct256 = faad_mdct_init(2*nshort);
  49.     fb->mdct2048 = faad_mdct_init(2*frame_len);
  50.     fb->long_window[0]  = sine_long_256;
  51.     fb->short_window[0] = sine_short_32;
  52.     fb->long_window[1]  = kbd_long_256;
  53.     fb->short_window[1] = kbd_short_32;
  54.     return fb;
  55. }
  56. void ssr_filter_bank_end(fb_info *fb)
  57. {
  58.     faad_mdct_end(fb->mdct256);
  59.     faad_mdct_end(fb->mdct2048);
  60.     if (fb) faad_free(fb);
  61. }
  62. static INLINE void imdct_ssr(fb_info *fb, real_t *in_data,
  63.                              real_t *out_data, uint16_t len)
  64. {
  65.     mdct_info *mdct;
  66.     switch (len)
  67.     {
  68.     case 512:
  69.         mdct = fb->mdct2048;
  70.         break;
  71.     case 64:
  72.         mdct = fb->mdct256;
  73.         break;
  74.     }
  75.     faad_imdct(mdct, in_data, out_data);
  76. }
  77. /* NON-overlapping inverse filterbank for use with SSR */
  78. void ssr_ifilter_bank(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
  79.                       uint8_t window_shape_prev, real_t *freq_in,
  80.                       real_t *time_out, uint16_t frame_len)
  81. {
  82.     int16_t i;
  83.     real_t *transf_buf;
  84.     real_t *window_long;
  85.     real_t *window_long_prev;
  86.     real_t *window_short;
  87.     real_t *window_short_prev;
  88.     uint16_t nlong = frame_len;
  89.     uint16_t nshort = frame_len/8;
  90.     uint16_t trans = nshort/2;
  91.     uint16_t nflat_ls = (nlong-nshort)/2;
  92.     transf_buf = (real_t*)faad_malloc(2*nlong*sizeof(real_t));
  93.     window_long       = fb->long_window[window_shape];
  94.     window_long_prev  = fb->long_window[window_shape_prev];
  95.     window_short      = fb->short_window[window_shape];
  96.     window_short_prev = fb->short_window[window_shape_prev];
  97.     switch (window_sequence)
  98.     {
  99.     case ONLY_LONG_SEQUENCE:
  100.         imdct_ssr(fb, freq_in, transf_buf, 2*nlong);
  101.         for (i = nlong-1; i >= 0; i--)
  102.         {
  103.             time_out[i] = MUL_R_C(transf_buf[i],window_long_prev[i]);
  104.             time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]);
  105.         }
  106.         break;
  107.     case LONG_START_SEQUENCE:
  108.         imdct_ssr(fb, freq_in, transf_buf, 2*nlong);
  109.         for (i = 0; i < nlong; i++)
  110.             time_out[i] = MUL_R_C(transf_buf[i],window_long_prev[i]);
  111.         for (i = 0; i < nflat_ls; i++)
  112.             time_out[nlong+i] = transf_buf[nlong+i];
  113.         for (i = 0; i < nshort; i++)
  114.             time_out[nlong+nflat_ls+i] = MUL_R_C(transf_buf[nlong+nflat_ls+i],window_short[nshort-i-1]);
  115.         for (i = 0; i < nflat_ls; i++)
  116.             time_out[nlong+nflat_ls+nshort+i] = 0;
  117.         break;
  118.     case EIGHT_SHORT_SEQUENCE:
  119.         imdct_ssr(fb, freq_in+0*nshort, transf_buf+2*nshort*0, 2*nshort);
  120.         imdct_ssr(fb, freq_in+1*nshort, transf_buf+2*nshort*1, 2*nshort);
  121.         imdct_ssr(fb, freq_in+2*nshort, transf_buf+2*nshort*2, 2*nshort);
  122.         imdct_ssr(fb, freq_in+3*nshort, transf_buf+2*nshort*3, 2*nshort);
  123.         imdct_ssr(fb, freq_in+4*nshort, transf_buf+2*nshort*4, 2*nshort);
  124.         imdct_ssr(fb, freq_in+5*nshort, transf_buf+2*nshort*5, 2*nshort);
  125.         imdct_ssr(fb, freq_in+6*nshort, transf_buf+2*nshort*6, 2*nshort);
  126.         imdct_ssr(fb, freq_in+7*nshort, transf_buf+2*nshort*7, 2*nshort);
  127.         for(i = nshort-1; i >= 0; i--)
  128.         {
  129.             time_out[i+0*nshort] = MUL_R_C(transf_buf[nshort*0+i],window_short_prev[i]);
  130.             time_out[i+1*nshort] = MUL_R_C(transf_buf[nshort*1+i],window_short[i]);
  131.             time_out[i+2*nshort] = MUL_R_C(transf_buf[nshort*2+i],window_short_prev[i]);
  132.             time_out[i+3*nshort] = MUL_R_C(transf_buf[nshort*3+i],window_short[i]);
  133.             time_out[i+4*nshort] = MUL_R_C(transf_buf[nshort*4+i],window_short_prev[i]);
  134.             time_out[i+5*nshort] = MUL_R_C(transf_buf[nshort*5+i],window_short[i]);
  135.             time_out[i+6*nshort] = MUL_R_C(transf_buf[nshort*6+i],window_short_prev[i]);
  136.             time_out[i+7*nshort] = MUL_R_C(transf_buf[nshort*7+i],window_short[i]);
  137.             time_out[i+8*nshort] = MUL_R_C(transf_buf[nshort*8+i],window_short_prev[i]);
  138.             time_out[i+9*nshort] = MUL_R_C(transf_buf[nshort*9+i],window_short[i]);
  139.             time_out[i+10*nshort] = MUL_R_C(transf_buf[nshort*10+i],window_short_prev[i]);
  140.             time_out[i+11*nshort] = MUL_R_C(transf_buf[nshort*11+i],window_short[i]);
  141.             time_out[i+12*nshort] = MUL_R_C(transf_buf[nshort*12+i],window_short_prev[i]);
  142.             time_out[i+13*nshort] = MUL_R_C(transf_buf[nshort*13+i],window_short[i]);
  143.             time_out[i+14*nshort] = MUL_R_C(transf_buf[nshort*14+i],window_short_prev[i]);
  144.             time_out[i+15*nshort] = MUL_R_C(transf_buf[nshort*15+i],window_short[i]);
  145.         }
  146.         break;
  147.     case LONG_STOP_SEQUENCE:
  148.         imdct_ssr(fb, freq_in, transf_buf, 2*nlong);
  149.         for (i = 0; i < nflat_ls; i++)
  150.             time_out[i] = 0;
  151.         for (i = 0; i < nshort; i++)
  152.             time_out[nflat_ls+i] = MUL_R_C(transf_buf[nflat_ls+i],window_short_prev[i]);
  153.         for (i = 0; i < nflat_ls; i++)
  154.             time_out[nflat_ls+nshort+i] = transf_buf[nflat_ls+nshort+i];
  155.         for (i = 0; i < nlong; i++)
  156.             time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]);
  157. break;
  158.     }
  159.     faad_free(transf_buf);
  160. }
  161. #endif