Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
165 | serge | 1 | #include "layer3.h" |
2 | #include |
||
3 | //#include |
||
4 | |||
5 | extern IS_SF_INFO m_is_sf_info; |
||
6 | extern int m_ms_mode, m_is_mode; |
||
7 | |||
8 | extern int m_sfBandIndex[2][22];// [long/short][cb] |
||
9 | extern int m_nBand[2][22]; |
||
10 | |||
11 | /* intensity stereo */ |
||
12 | /* if ms mode quant pre-scales all values by 1.0/sqrt(2.0) ms_mode in table |
||
13 | compensates */ |
||
14 | /* [ms_mode 0/1][sf][left/right] */ |
||
15 | static float lr[2][8][2]; |
||
16 | /* lr2[intensity_scale][ms_mode][sflen_offset+sf][left/right] */ |
||
17 | static float lr2[2][2][64][2]; |
||
18 | |||
19 | /*-------*msis_init_addr() |
||
20 | pi = 4.0*atan(1.0); |
||
21 | t = pi/12.0; |
||
22 | for(i=0;i<7;i++) { |
||
23 | s = sin(i*t); |
||
24 | c = cos(i*t); |
||
25 | // ms_mode = 0 |
||
26 | lr[0][i][0] = (float)(s/(s+c)); |
||
27 | lr[0][i][1] = (float)(c/(s+c)); |
||
28 | // ms_mode = 1 |
||
29 | lr[1][i][0] = (float)(sqrt(2.0)*(s/(s+c))); |
||
30 | lr[1][i][1] = (float)(sqrt(2.0)*(c/(s+c))); |
||
31 | } |
||
32 | //sf = 7 |
||
33 | //ms_mode = 0 |
||
34 | lr[0][i][0] = 1.0f; |
||
35 | lr[0][i][1] = 0.0f; |
||
36 | // ms_mode = 1, in is bands is routine does ms processing |
||
37 | lr[1][i][0] = 1.0f; |
||
38 | lr[1][i][1] = 1.0f; |
||
39 | ------------*/ |
||
40 | |||
41 | /*===============================================================*/ |
||
42 | void msis_init1() |
||
43 | { |
||
44 | int i; |
||
45 | double s, c; |
||
46 | double pi; |
||
47 | double t; |
||
48 | |||
49 | pi = 4.0 * atan(1.0); |
||
50 | t = pi / 12.0; |
||
51 | for (i = 0; i < 7; i++) |
||
52 | { |
||
53 | s = sin(i * t); |
||
54 | c = cos(i * t); |
||
55 | /* ms_mode = 0 */ |
||
56 | lr[0][i][0] = (float) (s / (s + c)); |
||
57 | lr[0][i][1] = (float) (c / (s + c)); |
||
58 | /* ms_mode = 1 */ |
||
59 | lr[1][i][0] = (float) (sqrt(2.0) * (s / (s + c))); |
||
60 | lr[1][i][1] = (float) (sqrt(2.0) * (c / (s + c))); |
||
61 | } |
||
62 | /* sf = 7 */ |
||
63 | /* ms_mode = 0 */ |
||
64 | lr[0][i][0] = 1.0f; |
||
65 | lr[0][i][1] = 0.0f; |
||
66 | /* ms_mode = 1, in is bands is routine does ms processing */ |
||
67 | lr[1][i][0] = 1.0f; |
||
68 | lr[1][i][1] = 1.0f; |
||
69 | |||
70 | |||
71 | /*------- |
||
72 | for(i=0;i<21;i++) m_nBand[0][i] = |
||
73 | sfBandTable[sr_index].l[i+1] - sfBandTable[sr_index].l[i]; |
||
74 | for(i=0;i<12;i++) m_nBand[1][i] = |
||
75 | sfBandTable[sr_index].s[i+1] - sfBandTable[sr_index].s[i]; |
||
76 | -------------*/ |
||
77 | } |
||
78 | /*===============================================================*/ |
||
79 | void msis_init2() |
||
80 | { |
||
81 | int k, n; |
||
82 | double t; |
||
83 | int intensity_scale, ms_mode, sf, sflen; |
||
84 | float ms_factor[2]; |
||
85 | |||
86 | |||
87 | ms_factor[0] = 1.0; |
||
88 | ms_factor[1] = (float) sqrt(2.0); |
||
89 | |||
90 | /* intensity stereo MPEG2 */ |
||
91 | /* lr2[intensity_scale][ms_mode][sflen_offset+sf][left/right] */ |
||
92 | |||
93 | for (intensity_scale = 0; intensity_scale < 2; intensity_scale++) |
||
94 | { |
||
95 | t = pow_test(2.0, -0.25 * (1 + intensity_scale)); |
||
96 | for (ms_mode = 0; ms_mode < 2; ms_mode++) |
||
97 | { |
||
98 | |||
99 | n = 1; |
||
100 | k = 0; |
||
101 | for (sflen = 0; sflen < 6; sflen++) |
||
102 | { |
||
103 | for (sf = 0; sf < (n - 1); sf++, k++) |
||
104 | { |
||
105 | if (sf == 0) |
||
106 | { |
||
107 | lr2[intensity_scale][ms_mode][k][0] = ms_factor[ms_mode] * 1.0f; |
||
108 | lr2[intensity_scale][ms_mode][k][1] = ms_factor[ms_mode] * 1.0f; |
||
109 | } |
||
110 | else if ((sf & 1)) |
||
111 | { |
||
112 | lr2[intensity_scale][ms_mode][k][0] = |
||
113 | (float) (ms_factor[ms_mode] * pow_test(t, (sf + 1) / 2)); |
||
114 | lr2[intensity_scale][ms_mode][k][1] = ms_factor[ms_mode] * 1.0f; |
||
115 | } |
||
116 | else |
||
117 | { |
||
118 | lr2[intensity_scale][ms_mode][k][0] = ms_factor[ms_mode] * 1.0f; |
||
119 | lr2[intensity_scale][ms_mode][k][1] = |
||
120 | (float) (ms_factor[ms_mode] * pow_test(t, sf / 2)); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | /* illegal is_pos used to do ms processing */ |
||
125 | if (ms_mode == 0) |
||
126 | { /* ms_mode = 0 */ |
||
127 | lr2[intensity_scale][ms_mode][k][0] = 1.0f; |
||
128 | lr2[intensity_scale][ms_mode][k][1] = 0.0f; |
||
129 | } |
||
130 | else |
||
131 | { |
||
132 | /* ms_mode = 1, in is bands is routine does ms processing */ |
||
133 | lr2[intensity_scale][ms_mode][k][0] = 1.0f; |
||
134 | lr2[intensity_scale][ms_mode][k][1] = 1.0f; |
||
135 | } |
||
136 | k++; |
||
137 | n = n + n; |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | } |
||
142 | |||
143 | void msis_init() |
||
144 | { |
||
145 | msis_init1(); |
||
146 | msis_init2(); |
||
147 | } |
||
148 | |||
149 | /*===============================================================*/ |
||
150 | void ms_process(float x[][1152], int n) /* sum-difference stereo */ |
||
151 | { |
||
152 | int i; |
||
153 | float xl, xr; |
||
154 | |||
155 | /*-- note: sqrt(2) done scaling by dequant ---*/ |
||
156 | for (i = 0; i < n; i++) |
||
157 | { |
||
158 | xl = x[0][i] + x[1][i]; |
||
159 | xr = x[0][i] - x[1][i]; |
||
160 | x[0][i] = xl; |
||
161 | x[1][i] = xr; |
||
162 | } |
||
163 | return; |
||
164 | } |
||
165 | |||
166 | void is_process1(float x[][1152], /* intensity stereo */ |
||
167 | SCALE_FACTOR* sf, |
||
168 | CB_INFO cb_info[2], /* [ch] */ |
||
169 | int nsamp) |
||
170 | { |
||
171 | int i, j, n, cb, w; |
||
172 | float fl, fr; |
||
173 | int m; |
||
174 | int isf; |
||
175 | float fls[3], frs[3]; |
||
176 | int cb0; |
||
177 | |||
178 | |||
179 | cb0 = cb_info[1].cbmax; /* start at end of right */ |
||
180 | i = m_sfBandIndex[cb_info[1].cbtype][cb0]; |
||
181 | cb0++; |
||
182 | m = nsamp - i; /* process to len of left */ |
||
183 | |||
184 | if (cb_info[1].cbtype) |
||
185 | goto short_blocks; |
||
186 | /*------------------------*/ |
||
187 | /* long_blocks: */ |
||
188 | for (cb = cb0; cb < 21; cb++) |
||
189 | { |
||
190 | isf = sf->l[cb]; |
||
191 | n = m_nBand[0][cb]; |
||
192 | fl = lr[m_ms_mode][isf][0]; |
||
193 | fr = lr[m_ms_mode][isf][1]; |
||
194 | for (j = 0; j < n; j++, i++) |
||
195 | { |
||
196 | if (--m < 0) |
||
197 | goto exit; |
||
198 | x[1][i] = fr * x[0][i]; |
||
199 | x[0][i] = fl * x[0][i]; |
||
200 | } |
||
201 | } |
||
202 | return; |
||
203 | /*------------------------*/ |
||
204 | short_blocks: |
||
205 | for (cb = cb0; cb < 12; cb++) |
||
206 | { |
||
207 | for (w = 0; w < 3; w++) |
||
208 | { |
||
209 | isf = sf->s[w][cb]; |
||
210 | fls[w] = lr[m_ms_mode][isf][0]; |
||
211 | frs[w] = lr[m_ms_mode][isf][1]; |
||
212 | } |
||
213 | n = m_nBand[1][cb]; |
||
214 | for (j = 0; j < n; j++) |
||
215 | { |
||
216 | m -= 3; |
||
217 | if (m < 0) |
||
218 | goto exit; |
||
219 | x[1][i] = frs[0] * x[0][i]; |
||
220 | x[0][i] = fls[0] * x[0][i]; |
||
221 | x[1][1 + i] = frs[1] * x[0][1 + i]; |
||
222 | x[0][1 + i] = fls[1] * x[0][1 + i]; |
||
223 | x[1][2 + i] = frs[2] * x[0][2 + i]; |
||
224 | x[0][2 + i] = fls[2] * x[0][2 + i]; |
||
225 | i += 3; |
||
226 | } |
||
227 | } |
||
228 | |||
229 | exit: |
||
230 | return; |
||
231 | } |
||
232 | |||
233 | typedef float ARRAY2[2]; |
||
234 | |||
235 | void is_process2(float x[][1152], /* intensity stereo */ |
||
236 | SCALE_FACTOR* sf, |
||
237 | CB_INFO cb_info[2], /* [ch] */ |
||
238 | int nsamp) |
||
239 | { |
||
240 | int i, j, k, n, cb, w; |
||
241 | float fl, fr; |
||
242 | int m; |
||
243 | int isf; |
||
244 | int il[21]; |
||
245 | int tmp; |
||
246 | int r; |
||
247 | ARRAY2 *lr; |
||
248 | int cb0, cb1; |
||
249 | |||
250 | lr = lr2[m_is_sf_info.intensity_scale][m_ms_mode]; |
||
251 | |||
252 | if (cb_info[1].cbtype) |
||
253 | goto short_blocks; |
||
254 | |||
255 | /*------------------------*/ |
||
256 | /* long_blocks: */ |
||
257 | cb0 = cb_info[1].cbmax; /* start at end of right */ |
||
258 | i = m_sfBandIndex[0][cb0]; |
||
259 | m = nsamp - i; /* process to len of left */ |
||
260 | /* gen sf info */ |
||
261 | for (k = r = 0; r < 3; r++) |
||
262 | { |
||
263 | tmp = (1 << m_is_sf_info.slen[r]) - 1; |
||
264 | for (j = 0; j < m_is_sf_info.nr[r]; j++, k++) |
||
265 | il[k] = tmp; |
||
266 | } |
||
267 | for (cb = cb0 + 1; cb < 21; cb++) |
||
268 | { |
||
269 | isf = il[cb] + sf->l[cb]; |
||
270 | // X-MaD 27-02-02 |
||
271 | if (isf < 0) { isf = 0; } |
||
272 | fl = 0; |
||
273 | fr = 0; |
||
274 | |||
275 | //try |
||
276 | //{ |
||
277 | fl = lr[isf][0]; |
||
278 | fr = lr[isf][1]; |
||
279 | n = m_nBand[0][cb]; |
||
280 | //} |
||
281 | //catch(...) |
||
282 | //{ |
||
283 | // isf = 0; |
||
284 | //} |
||
285 | // X-MaD 27-02-02 |
||
286 | |||
287 | for (j = 0; j < n; j++, i++) |
||
288 | { |
||
289 | if (--m < 0) |
||
290 | { |
||
291 | goto exit; |
||
292 | } |
||
293 | x[1][i] = fr * x[0][i]; |
||
294 | x[0][i] = fl * x[0][i]; |
||
295 | } |
||
296 | } |
||
297 | return; |
||
298 | /*------------------------*/ |
||
299 | short_blocks: |
||
300 | |||
301 | for (k = r = 0; r < 3; r++) |
||
302 | { |
||
303 | tmp = (1 << m_is_sf_info.slen[r]) - 1; |
||
304 | for (j = 0; j < m_is_sf_info.nr[r]; j++, k++) |
||
305 | il[k] = tmp; |
||
306 | } |
||
307 | |||
308 | for (w = 0; w < 3; w++) |
||
309 | { |
||
310 | cb0 = cb_info[1].cbmax_s[w]; /* start at end of right */ |
||
311 | i = m_sfBandIndex[1][cb0] + w; |
||
312 | cb1 = cb_info[0].cbmax_s[w]; /* process to end of left */ |
||
313 | |||
314 | for (cb = cb0 + 1; cb <= cb1; cb++) |
||
315 | { |
||
316 | isf = il[cb] + sf->s[w][cb]; |
||
317 | fl = lr[isf][0]; |
||
318 | fr = lr[isf][1]; |
||
319 | n = m_nBand[1][cb]; |
||
320 | for (j = 0; j < n; j++) |
||
321 | { |
||
322 | x[1][i] = fr * x[0][i]; |
||
323 | x[0][i] = fl * x[0][i]; |
||
324 | i += 3; |
||
325 | } |
||
326 | } |
||
327 | |||
328 | } |
||
329 | |||
330 | exit: |
||
331 | return; |
||
332 | }>=>>>><>>>>>>>><>>>>>>>>>>>>>>12;i++)>21;i++)>>7;i++)> |