- Main Page
- Namespaces
- Classes
- Files
- Directories

- File List
- File Members

# ssr_fb.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: ssr_fb.c,v 1.2 2005/11/01 21:41:43 gabest Exp $
    00031 **/
    00032
    00033 #include "common.h"
    00034 #include "structs.h"
    00035
    00036 #ifdef SSR_DEC
    00037
    00038 #include <string.h>
    00039 #include <stdlib.h>
    00040 #include "syntax.h"
    00041 #include "filtbank.h"
    00042 #include "mdct.h"
    00043 #include "ssr_fb.h"
    00044 #include "ssr_win.h"
    00045
    00046 fb_info *ssr_filter_bank_init(uint16_t frame_len)
    00047 {
    00048     uint16_t nshort = frame_len/8;
    00049
    00050     fb_info *fb = (fb_info*)faad_malloc(sizeof(fb_info));
    00051     memset(fb, 0, sizeof(fb_info));
    00052
    00053     /* normal */
    00054     fb->mdct256 = faad_mdct_init(2*nshort);
    00055     fb->mdct2048 = faad_mdct_init(2*frame_len);
    00056
    00057     fb->long_window[0]  = sine_long_256;
    00058     fb->short_window[0] = sine_short_32;
    00059     fb->long_window[1]  = kbd_long_256;
    00060     fb->short_window[1] = kbd_short_32;
    00061
    00062     return fb;
    00063 }
    00064
    00065 void ssr_filter_bank_end(fb_info *fb)
    00066 {
    00067     faad_mdct_end(fb->mdct256);
    00068     faad_mdct_end(fb->mdct2048);
    00069
    00070     if (fb) faad_free(fb);
    00071 }
    00072
    00073 static INLINE void imdct_ssr(fb_info *fb, real_t *in_data,
    00074                              real_t *out_data, uint16_t len)
    00075 {
    00076     mdct_info *mdct;
    00077
    00078     switch (len)
    00079     {
    00080     case 512:
    00081         mdct = fb->mdct2048;
    00082         break;
    00083     case 64:
    00084         mdct = fb->mdct256;
    00085         break;
    00086     }
    00087
    00088     faad_imdct(mdct, in_data, out_data);
    00089 }
    00090
    00091 /* NON-overlapping inverse filterbank for use with SSR */
    00092 void ssr_ifilter_bank(fb_info *fb, uint8_t window_sequence, uint8_t window_shape,
    00093                       uint8_t window_shape_prev, real_t *freq_in,
    00094                       real_t *time_out, uint16_t frame_len)
    00095 {
    00096     int16_t i;
    00097     real_t *transf_buf;
    00098
    00099     real_t *window_long;
    00100     real_t *window_long_prev;
    00101     real_t *window_short;
    00102     real_t *window_short_prev;
    00103
    00104     uint16_t nlong = frame_len;
    00105     uint16_t nshort = frame_len/8;
    00106     uint16_t trans = nshort/2;
    00107
    00108     uint16_t nflat_ls = (nlong-nshort)/2;
    00109
    00110     transf_buf = (real_t*)faad_malloc(2*nlong*sizeof(real_t));
    00111
    00112     window_long       = fb->long_window[window_shape];
    00113     window_long_prev  = fb->long_window[window_shape_prev];
    00114     window_short      = fb->short_window[window_shape];
    00115     window_short_prev = fb->short_window[window_shape_prev];
    00116
    00117     switch (window_sequence)
    00118     {
    00119     case ONLY_LONG_SEQUENCE:
    00120         imdct_ssr(fb, freq_in, transf_buf, 2*nlong);
    00121         for (i = nlong-1; i >= 0; i--)
    00122         {
    00123             time_out[i] = MUL_R_C(transf_buf[i],window_long_prev[i]);
    00124             time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]);
    00125         }
    00126         break;
    00127
    00128     case LONG_START_SEQUENCE:
    00129         imdct_ssr(fb, freq_in, transf_buf, 2*nlong);
    00130         for (i = 0; i < nlong; i++)
    00131             time_out[i] = MUL_R_C(transf_buf[i],window_long_prev[i]);
    00132         for (i = 0; i < nflat_ls; i++)
    00133             time_out[nlong+i] = transf_buf[nlong+i];
    00134         for (i = 0; i < nshort; i++)
    00135             time_out[nlong+nflat_ls+i] = MUL_R_C(transf_buf[nlong+nflat_ls+i],window_short[nshort-i-1]);
    00136         for (i = 0; i < nflat_ls; i++)
    00137             time_out[nlong+nflat_ls+nshort+i] = 0;
    00138         break;
    00139
    00140     case EIGHT_SHORT_SEQUENCE:
    00141         imdct_ssr(fb, freq_in+0*nshort, transf_buf+2*nshort*0, 2*nshort);
    00142         imdct_ssr(fb, freq_in+1*nshort, transf_buf+2*nshort*1, 2*nshort);
    00143         imdct_ssr(fb, freq_in+2*nshort, transf_buf+2*nshort*2, 2*nshort);
    00144         imdct_ssr(fb, freq_in+3*nshort, transf_buf+2*nshort*3, 2*nshort);
    00145         imdct_ssr(fb, freq_in+4*nshort, transf_buf+2*nshort*4, 2*nshort);
    00146         imdct_ssr(fb, freq_in+5*nshort, transf_buf+2*nshort*5, 2*nshort);
    00147         imdct_ssr(fb, freq_in+6*nshort, transf_buf+2*nshort*6, 2*nshort);
    00148         imdct_ssr(fb, freq_in+7*nshort, transf_buf+2*nshort*7, 2*nshort);
    00149         for(i = nshort-1; i >= 0; i--)
    00150         {
    00151             time_out[i+0*nshort] = MUL_R_C(transf_buf[nshort*0+i],window_short_prev[i]);
    00152             time_out[i+1*nshort] = MUL_R_C(transf_buf[nshort*1+i],window_short[i]);
    00153             time_out[i+2*nshort] = MUL_R_C(transf_buf[nshort*2+i],window_short_prev[i]);
    00154             time_out[i+3*nshort] = MUL_R_C(transf_buf[nshort*3+i],window_short[i]);
    00155             time_out[i+4*nshort] = MUL_R_C(transf_buf[nshort*4+i],window_short_prev[i]);
    00156             time_out[i+5*nshort] = MUL_R_C(transf_buf[nshort*5+i],window_short[i]);
    00157             time_out[i+6*nshort] = MUL_R_C(transf_buf[nshort*6+i],window_short_prev[i]);
    00158             time_out[i+7*nshort] = MUL_R_C(transf_buf[nshort*7+i],window_short[i]);
    00159             time_out[i+8*nshort] = MUL_R_C(transf_buf[nshort*8+i],window_short_prev[i]);
    00160             time_out[i+9*nshort] = MUL_R_C(transf_buf[nshort*9+i],window_short[i]);
    00161             time_out[i+10*nshort] = MUL_R_C(transf_buf[nshort*10+i],window_short_prev[i]);
    00162             time_out[i+11*nshort] = MUL_R_C(transf_buf[nshort*11+i],window_short[i]);
    00163             time_out[i+12*nshort] = MUL_R_C(transf_buf[nshort*12+i],window_short_prev[i]);
    00164             time_out[i+13*nshort] = MUL_R_C(transf_buf[nshort*13+i],window_short[i]);
    00165             time_out[i+14*nshort] = MUL_R_C(transf_buf[nshort*14+i],window_short_prev[i]);
    00166             time_out[i+15*nshort] = MUL_R_C(transf_buf[nshort*15+i],window_short[i]);
    00167         }
    00168         break;
    00169
    00170     case LONG_STOP_SEQUENCE:
    00171         imdct_ssr(fb, freq_in, transf_buf, 2*nlong);
    00172         for (i = 0; i < nflat_ls; i++)
    00173             time_out[i] = 0;
    00174         for (i = 0; i < nshort; i++)
    00175             time_out[nflat_ls+i] = MUL_R_C(transf_buf[nflat_ls+i],window_short_prev[i]);
    00176         for (i = 0; i < nflat_ls; i++)
    00177             time_out[nflat_ls+nshort+i] = transf_buf[nflat_ls+nshort+i];
    00178         for (i = 0; i < nlong; i++)
    00179             time_out[nlong+i] = MUL_R_C(transf_buf[nlong+i],window_long[nlong-1-i]);
    00180                 break;
    00181     }
    00182
    00183     faad_free(transf_buf);
    00184 }
    00185
    00186
    00187 #endif