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