00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
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
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
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