1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | /*
|
---|
10 | * Mpeg Layer-3 audio decoder
|
---|
11 | * --------------------------
|
---|
12 | * copyright (c) 1995,1996,1997 by Michael Hipp.
|
---|
13 | * All rights reserved. See also 'README'
|
---|
14 | *
|
---|
15 | * - I'm currently working on that .. needs a few more optimizations,
|
---|
16 | * though the code is now fast enough to run in realtime on a 100Mhz 486
|
---|
17 | * - a few personal notes are in german ..
|
---|
18 | *
|
---|
19 | * used source:
|
---|
20 | * mpeg1_iis package
|
---|
21 | */
|
---|
22 |
|
---|
23 | #include "loaders/mp3/mpg123.hh"
|
---|
24 | #include "loaders/mp3/huffman.hh"
|
---|
25 |
|
---|
26 | #if 0
|
---|
27 | #include "loaders/mp3/get1bit.hh"
|
---|
28 | #endif
|
---|
29 |
|
---|
30 | static real ispow[8207];
|
---|
31 | static real aa_ca[8],aa_cs[8];
|
---|
32 | static real COS1[12][6];
|
---|
33 | static real win[4][36];
|
---|
34 | static real win1[4][36];
|
---|
35 | static real gainpow2[256+118+4];
|
---|
36 | static real COS9[9];
|
---|
37 | static real COS6_1,COS6_2;
|
---|
38 | static real tfcos36[9];
|
---|
39 | static real tfcos12[3];
|
---|
40 | #ifdef NEW_DCT9
|
---|
41 | static real cos9[3],cos18[3];
|
---|
42 | #endif
|
---|
43 |
|
---|
44 | struct bandInfoStruct {
|
---|
45 | int longIdx[23];
|
---|
46 | int longDiff[22];
|
---|
47 | int shortIdx[14];
|
---|
48 | int shortDiff[13];
|
---|
49 | };
|
---|
50 |
|
---|
51 | int longLimit[7][23];
|
---|
52 | int shortLimit[7][14];
|
---|
53 |
|
---|
54 | struct bandInfoStruct bandInfo[7] = {
|
---|
55 |
|
---|
56 | /* MPEG 1.0 */
|
---|
57 | { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
|
---|
58 | {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158},
|
---|
59 | {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3},
|
---|
60 | {4,4,4,4,6,8,10,12,14,18,22,30,56} } ,
|
---|
61 |
|
---|
62 | { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576},
|
---|
63 | {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192},
|
---|
64 | {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3},
|
---|
65 | {4,4,4,4,6,6,10,12,14,16,20,26,66} } ,
|
---|
66 |
|
---|
67 | { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} ,
|
---|
68 | {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} ,
|
---|
69 | {0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} ,
|
---|
70 | {4,4,4,4,6,8,12,16,20,26,34,42,12} } ,
|
---|
71 |
|
---|
72 | /* MPEG 2.0 */
|
---|
73 | { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
|
---|
74 | {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } ,
|
---|
75 | {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} ,
|
---|
76 | {4,4,4,6,6,8,10,14,18,26,32,42,18 } } ,
|
---|
77 |
|
---|
78 | { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,330,394,464,540,576},
|
---|
79 | {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,52,64,70,76,36 } ,
|
---|
80 | {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} ,
|
---|
81 | {4,4,4,6,8,10,12,14,18,24,32,44,12 } } ,
|
---|
82 |
|
---|
83 | { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
|
---|
84 | {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 },
|
---|
85 | {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3},
|
---|
86 | {4,4,4,6,8,10,12,14,18,24,30,40,18 } } ,
|
---|
87 |
|
---|
88 | /* MPEG 2.5, wrong! table (it's just a copy of MPEG 2.0/44.1kHz) */
|
---|
89 | { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
|
---|
90 | {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } ,
|
---|
91 | {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} ,
|
---|
92 | {4,4,4,6,6,8,10,14,18,26,32,42,18 } } ,
|
---|
93 | };
|
---|
94 |
|
---|
95 | static int mapbuf0[7][152];
|
---|
96 | static int mapbuf1[7][156];
|
---|
97 | static int mapbuf2[7][44];
|
---|
98 | static int *map[7][3];
|
---|
99 | static int *mapend[7][3];
|
---|
100 |
|
---|
101 | static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */
|
---|
102 | static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */
|
---|
103 |
|
---|
104 | static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
|
---|
105 | static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
|
---|
106 |
|
---|
107 | static real block[2][2][SBLIMIT*SSLIMIT] = { { { 0, } } };
|
---|
108 | static int blc[2]={0,0};
|
---|
109 |
|
---|
110 | /*
|
---|
111 | * init tables for layer-3
|
---|
112 | */
|
---|
113 | void init_layer3(int down_samp)
|
---|
114 | {
|
---|
115 | int i,j,k,l;
|
---|
116 |
|
---|
117 | memset(block, 0, sizeof(block));
|
---|
118 | memset(blc, 0, sizeof(blc));
|
---|
119 |
|
---|
120 | for(i=-256;i<118+4;i++)
|
---|
121 | gainpow2[i+256] = pow((double)2.0,-0.25 * (double) (i+210) );
|
---|
122 |
|
---|
123 | for(i=0;i<8207;i++)
|
---|
124 | ispow[i] = pow((double)i,(double)4.0/3.0);
|
---|
125 |
|
---|
126 | for (i=0;i<8;i++)
|
---|
127 | {
|
---|
128 | static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037};
|
---|
129 | double sq=sqrt(1.0+Ci[i]*Ci[i]);
|
---|
130 | aa_cs[i] = 1.0/sq;
|
---|
131 | aa_ca[i] = Ci[i]/sq;
|
---|
132 | }
|
---|
133 |
|
---|
134 | for(i=0;i<18;i++)
|
---|
135 | {
|
---|
136 | win[0][i] = win[1][i] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+0) +1) ) / cos ( M_PI * (double) (2*(i+0) +19) / 72.0 );
|
---|
137 | win[0][i+18] = win[3][i+18] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+18)+1) ) / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
|
---|
138 | }
|
---|
139 | for(i=0;i<6;i++)
|
---|
140 | {
|
---|
141 | win[1][i+18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
|
---|
142 | win[3][i+12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 );
|
---|
143 | win[1][i+24] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 );
|
---|
144 | win[1][i+30] = win[3][i] = 0.0;
|
---|
145 | win[3][i+6 ] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 );
|
---|
146 | }
|
---|
147 |
|
---|
148 | for(i=0;i<9;i++)
|
---|
149 | COS9[i] = cos( M_PI / 18.0 * (double) i);
|
---|
150 |
|
---|
151 | for(i=0;i<9;i++)
|
---|
152 | tfcos36[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 );
|
---|
153 | for(i=0;i<3;i++)
|
---|
154 | tfcos12[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 );
|
---|
155 |
|
---|
156 | COS6_1 = cos( M_PI / 6.0 * (double) 1);
|
---|
157 | COS6_2 = cos( M_PI / 6.0 * (double) 2);
|
---|
158 |
|
---|
159 | #ifdef NEW_DCT9
|
---|
160 | cos9[0] = cos(1.0*M_PI/9.0);
|
---|
161 | cos9[1] = cos(5.0*M_PI/9.0);
|
---|
162 | cos9[2] = cos(7.0*M_PI/9.0);
|
---|
163 | cos18[0] = cos(1.0*M_PI/18.0);
|
---|
164 | cos18[1] = cos(11.0*M_PI/18.0);
|
---|
165 | cos18[2] = cos(13.0*M_PI/18.0);
|
---|
166 | #endif
|
---|
167 |
|
---|
168 | for(i=0;i<12;i++)
|
---|
169 | {
|
---|
170 | win[2][i] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 );
|
---|
171 | for(j=0;j<6;j++)
|
---|
172 | COS1[i][j] = cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) );
|
---|
173 | }
|
---|
174 |
|
---|
175 | for(j=0;j<4;j++) {
|
---|
176 | static int len[4] = { 36,36,12,36 };
|
---|
177 | for(i=0;i<len[j];i+=2)
|
---|
178 | win1[j][i] = + win[j][i];
|
---|
179 | for(i=1;i<len[j];i+=2)
|
---|
180 | win1[j][i] = - win[j][i];
|
---|
181 | }
|
---|
182 |
|
---|
183 | for(i=0;i<16;i++)
|
---|
184 | {
|
---|
185 | double t = tan( (double) i * M_PI / 12.0 );
|
---|
186 | tan1_1[i] = t / (1.0+t);
|
---|
187 | tan2_1[i] = 1.0 / (1.0 + t);
|
---|
188 | tan1_2[i] = M_SQRT2 * t / (1.0+t);
|
---|
189 | tan2_2[i] = M_SQRT2 / (1.0 + t);
|
---|
190 |
|
---|
191 | for(j=0;j<2;j++) {
|
---|
192 | double base = pow(2.0,-0.25*(j+1.0));
|
---|
193 | double p1=1.0,p2=1.0;
|
---|
194 | if(i > 0) {
|
---|
195 | if( i & 1 )
|
---|
196 | p1 = pow(base,(i+1.0)*0.5);
|
---|
197 | else
|
---|
198 | p2 = pow(base,i*0.5);
|
---|
199 | }
|
---|
200 | pow1_1[j][i] = p1;
|
---|
201 | pow2_1[j][i] = p2;
|
---|
202 | pow1_2[j][i] = M_SQRT2 * p1;
|
---|
203 | pow2_2[j][i] = M_SQRT2 * p2;
|
---|
204 | }
|
---|
205 | }
|
---|
206 |
|
---|
207 | for(j=0;j<7;j++)
|
---|
208 | {
|
---|
209 | struct bandInfoStruct *bi = &bandInfo[j];
|
---|
210 | int *mp;
|
---|
211 | int cb,lwin;
|
---|
212 | int *bdf;
|
---|
213 |
|
---|
214 | mp = map[j][0] = mapbuf0[j];
|
---|
215 | bdf = bi->longDiff;
|
---|
216 | for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) {
|
---|
217 | *mp++ = (*bdf) >> 1;
|
---|
218 | *mp++ = i;
|
---|
219 | *mp++ = 3;
|
---|
220 | *mp++ = cb;
|
---|
221 | }
|
---|
222 | bdf = bi->shortDiff+3;
|
---|
223 | for(cb=3;cb<13;cb++) {
|
---|
224 | int l = (*bdf++) >> 1;
|
---|
225 | for(lwin=0;lwin<3;lwin++) {
|
---|
226 | *mp++ = l;
|
---|
227 | *mp++ = i + lwin;
|
---|
228 | *mp++ = lwin;
|
---|
229 | *mp++ = cb;
|
---|
230 | }
|
---|
231 | i += 6*l;
|
---|
232 | }
|
---|
233 | mapend[j][0] = mp;
|
---|
234 |
|
---|
235 | mp = map[j][1] = mapbuf1[j];
|
---|
236 | bdf = bi->shortDiff+0;
|
---|
237 | for(i=0,cb=0;cb<13;cb++) {
|
---|
238 | int l = (*bdf++) >> 1;
|
---|
239 | for(lwin=0;lwin<3;lwin++) {
|
---|
240 | *mp++ = l;
|
---|
241 | *mp++ = i + lwin;
|
---|
242 | *mp++ = lwin;
|
---|
243 | *mp++ = cb;
|
---|
244 | }
|
---|
245 | i += 6*l;
|
---|
246 | }
|
---|
247 | mapend[j][1] = mp;
|
---|
248 |
|
---|
249 | mp = map[j][2] = mapbuf2[j];
|
---|
250 | bdf = bi->longDiff;
|
---|
251 | for(cb = 0; cb < 22 ; cb++) {
|
---|
252 | *mp++ = (*bdf++) >> 1;
|
---|
253 | *mp++ = cb;
|
---|
254 | }
|
---|
255 | mapend[j][2] = mp;
|
---|
256 |
|
---|
257 | }
|
---|
258 |
|
---|
259 | for(j=0;j<7;j++) {
|
---|
260 | for(i=0;i<23;i++) {
|
---|
261 | longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1;
|
---|
262 | if(longLimit[j][i] > (SBLIMIT >> down_samp) )
|
---|
263 | longLimit[j][i] = SBLIMIT >> down_samp;
|
---|
264 | }
|
---|
265 | for(i=0;i<14;i++) {
|
---|
266 | shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1;
|
---|
267 | if(shortLimit[j][i] > (SBLIMIT >> down_samp) )
|
---|
268 | shortLimit[j][i] = SBLIMIT >> down_samp;
|
---|
269 | }
|
---|
270 | }
|
---|
271 |
|
---|
272 | for(i=0;i<5;i++) {
|
---|
273 | for(j=0;j<6;j++) {
|
---|
274 | for(k=0;k<6;k++) {
|
---|
275 | int n = k + j * 6 + i * 36;
|
---|
276 | i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12);
|
---|
277 | }
|
---|
278 | }
|
---|
279 | }
|
---|
280 | for(i=0;i<4;i++) {
|
---|
281 | for(j=0;j<4;j++) {
|
---|
282 | for(k=0;k<4;k++) {
|
---|
283 | int n = k + j * 4 + i * 16;
|
---|
284 | i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12);
|
---|
285 | }
|
---|
286 | }
|
---|
287 | }
|
---|
288 | for(i=0;i<4;i++) {
|
---|
289 | for(j=0;j<3;j++) {
|
---|
290 | int n = j + i * 3;
|
---|
291 | i_slen2[n+244] = i|(j<<3) | (5<<12);
|
---|
292 | n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15);
|
---|
293 | }
|
---|
294 | }
|
---|
295 |
|
---|
296 | for(i=0;i<5;i++) {
|
---|
297 | for(j=0;j<5;j++) {
|
---|
298 | for(k=0;k<4;k++) {
|
---|
299 | for(l=0;l<4;l++) {
|
---|
300 | int n = l + k * 4 + j * 16 + i * 80;
|
---|
301 | n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12);
|
---|
302 | }
|
---|
303 | }
|
---|
304 | }
|
---|
305 | }
|
---|
306 | for(i=0;i<5;i++) {
|
---|
307 | for(j=0;j<5;j++) {
|
---|
308 | for(k=0;k<4;k++) {
|
---|
309 | int n = k + j * 4 + i * 20;
|
---|
310 | n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12);
|
---|
311 | }
|
---|
312 | }
|
---|
313 | }
|
---|
314 | }
|
---|
315 |
|
---|
316 | /*
|
---|
317 | * read additional side information
|
---|
318 | */
|
---|
319 | static void III_get_side_info_1(struct III_sideinfo *si,int stereo,
|
---|
320 | int ms_stereo,long sfreq,int single)
|
---|
321 | {
|
---|
322 | int ch, gr;
|
---|
323 | int powdiff = (single == 3) ? 4 : 0;
|
---|
324 |
|
---|
325 | si->main_data_begin = getbits(9);
|
---|
326 | if (stereo == 1)
|
---|
327 | si->private_bits = getbits_fast(5);
|
---|
328 | else
|
---|
329 | si->private_bits = getbits_fast(3);
|
---|
330 |
|
---|
331 | for (ch=0; ch<stereo; ch++) {
|
---|
332 | si->ch[ch].gr[0].scfsi = -1;
|
---|
333 | si->ch[ch].gr[1].scfsi = getbits_fast(4);
|
---|
334 | }
|
---|
335 |
|
---|
336 | for (gr=0; gr<2; gr++)
|
---|
337 | {
|
---|
338 | for (ch=0; ch<stereo; ch++)
|
---|
339 | {
|
---|
340 | III_sideinfo::what_the::gr_info_s *gr_info = (III_sideinfo::what_the::gr_info_s *)(&(si->ch[ch].gr[gr]));
|
---|
341 |
|
---|
342 | gr_info->part2_3_length = getbits(12);
|
---|
343 | gr_info->big_values = getbits_fast(9);
|
---|
344 | gr_info->pow2gain = gainpow2+256 - getbits_fast(8) + powdiff;
|
---|
345 | if(ms_stereo)
|
---|
346 | gr_info->pow2gain += 2;
|
---|
347 | gr_info->scalefac_compress = getbits_fast(4);
|
---|
348 | /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
|
---|
349 | if(get1bit())
|
---|
350 | {
|
---|
351 | int i;
|
---|
352 | gr_info->block_type = getbits_fast(2);
|
---|
353 | gr_info->mixed_block_flag = get1bit();
|
---|
354 | gr_info->table_select[0] = getbits_fast(5);
|
---|
355 | gr_info->table_select[1] = getbits_fast(5);
|
---|
356 | /*
|
---|
357 | * table_select[2] not needed, because there is no region2,
|
---|
358 | * but to satisfy some verifications tools we set it either.
|
---|
359 | */
|
---|
360 | gr_info->table_select[2] = 0;
|
---|
361 | for(i=0;i<3;i++)
|
---|
362 | gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);
|
---|
363 |
|
---|
364 | if(gr_info->block_type == 0) {
|
---|
365 | exit(1);
|
---|
366 | }
|
---|
367 | /* region_count/start parameters are implicit in this case. */
|
---|
368 | gr_info->region1start = 36>>1;
|
---|
369 | gr_info->region2start = 576>>1;
|
---|
370 | }
|
---|
371 | else
|
---|
372 | {
|
---|
373 | int i,r0c,r1c;
|
---|
374 | for (i=0; i<3; i++)
|
---|
375 | gr_info->table_select[i] = getbits_fast(5);
|
---|
376 | r0c = getbits_fast(4);
|
---|
377 | r1c = getbits_fast(3);
|
---|
378 | gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
|
---|
379 | gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
|
---|
380 | gr_info->block_type = 0;
|
---|
381 | gr_info->mixed_block_flag = 0;
|
---|
382 | }
|
---|
383 | gr_info->preflag = get1bit();
|
---|
384 | gr_info->scalefac_scale = get1bit();
|
---|
385 | gr_info->count1table_select = get1bit();
|
---|
386 | }
|
---|
387 | }
|
---|
388 | }
|
---|
389 |
|
---|
390 | /*
|
---|
391 | * Side Info for MPEG 2.0 / LSF
|
---|
392 | */
|
---|
393 | static void III_get_side_info_2(struct III_sideinfo *si,int stereo,
|
---|
394 | int ms_stereo,long sfreq,int single)
|
---|
395 | {
|
---|
396 | int ch;
|
---|
397 | int powdiff = (single == 3) ? 4 : 0;
|
---|
398 |
|
---|
399 | si->main_data_begin = getbits(8);
|
---|
400 | if (stereo == 1)
|
---|
401 | si->private_bits = get1bit();
|
---|
402 | else
|
---|
403 | si->private_bits = getbits_fast(2);
|
---|
404 |
|
---|
405 | for (ch=0; ch<stereo; ch++)
|
---|
406 | {
|
---|
407 | III_sideinfo::what_the::gr_info_s *gr_info = (III_sideinfo::what_the::gr_info_s *)&(si->ch[ch].gr[0]);
|
---|
408 |
|
---|
409 | gr_info->part2_3_length = getbits(12);
|
---|
410 | gr_info->big_values = getbits_fast(9);
|
---|
411 | gr_info->pow2gain = gainpow2+256 - getbits_fast(8) + powdiff;
|
---|
412 | if(ms_stereo)
|
---|
413 | gr_info->pow2gain += 2;
|
---|
414 | gr_info->scalefac_compress = getbits(9);
|
---|
415 | /* window-switching flag == 1 for block_Type != 0 .. and block-type == 0 -> win-sw-flag = 0 */
|
---|
416 | if(get1bit())
|
---|
417 | {
|
---|
418 | int i;
|
---|
419 | gr_info->block_type = getbits_fast(2);
|
---|
420 | gr_info->mixed_block_flag = get1bit();
|
---|
421 | gr_info->table_select[0] = getbits_fast(5);
|
---|
422 | gr_info->table_select[1] = getbits_fast(5);
|
---|
423 | /*
|
---|
424 | * table_select[2] not needed, because there is no region2,
|
---|
425 | * but to satisfy some verifications tools we set it either.
|
---|
426 | */
|
---|
427 | gr_info->table_select[2] = 0;
|
---|
428 | for(i=0;i<3;i++)
|
---|
429 | gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);
|
---|
430 |
|
---|
431 | if(gr_info->block_type == 0) {
|
---|
432 | exit(1);
|
---|
433 | }
|
---|
434 | /* region_count/start parameters are implicit in this case. */
|
---|
435 | /* check this again! */
|
---|
436 | if(gr_info->block_type == 2)
|
---|
437 | gr_info->region1start = 36>>1;
|
---|
438 | else {
|
---|
439 | gr_info->region1start = 54>>1;
|
---|
440 | }
|
---|
441 | gr_info->region2start = 576>>1;
|
---|
442 | }
|
---|
443 | else
|
---|
444 | {
|
---|
445 | int i,r0c,r1c;
|
---|
446 | for (i=0; i<3; i++)
|
---|
447 | gr_info->table_select[i] = getbits_fast(5);
|
---|
448 | r0c = getbits_fast(4);
|
---|
449 | r1c = getbits_fast(3);
|
---|
450 | gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
|
---|
451 | gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
|
---|
452 | gr_info->block_type = 0;
|
---|
453 | gr_info->mixed_block_flag = 0;
|
---|
454 | }
|
---|
455 | gr_info->scalefac_scale = get1bit();
|
---|
456 | gr_info->count1table_select = get1bit();
|
---|
457 | }
|
---|
458 | }
|
---|
459 |
|
---|
460 | /*
|
---|
461 | * read scalefactors
|
---|
462 | */
|
---|
463 | static int III_get_scale_factors_1(int *scf,struct III_sideinfo::what_the::gr_info_s *gr_info)
|
---|
464 | {
|
---|
465 | static unsigned char slen[2][16] = {
|
---|
466 | {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
|
---|
467 | {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
|
---|
468 | };
|
---|
469 | int numbits;
|
---|
470 | int num0 = slen[0][gr_info->scalefac_compress];
|
---|
471 | int num1 = slen[1][gr_info->scalefac_compress];
|
---|
472 |
|
---|
473 | if (gr_info->block_type == 2)
|
---|
474 | {
|
---|
475 | int i=18;
|
---|
476 | numbits = (num0 + num1) * 18;
|
---|
477 |
|
---|
478 | if (gr_info->mixed_block_flag) {
|
---|
479 | for (i=8;i;i--)
|
---|
480 | *scf++ = getbits_fast(num0);
|
---|
481 | i = 9;
|
---|
482 | numbits -= num0; /* num0 * 17 + num1 * 18 */
|
---|
483 | }
|
---|
484 |
|
---|
485 | for (;i;i--)
|
---|
486 | *scf++ = getbits_fast(num0);
|
---|
487 | for (i = 18; i; i--)
|
---|
488 | *scf++ = getbits_fast(num1);
|
---|
489 | *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
|
---|
490 | }
|
---|
491 | else
|
---|
492 | {
|
---|
493 | int i;
|
---|
494 | int scfsi = gr_info->scfsi;
|
---|
495 |
|
---|
496 | if(scfsi < 0) { /* scfsi < 0 => granule == 0 */
|
---|
497 | for(i=11;i;i--)
|
---|
498 | *scf++ = getbits_fast(num0);
|
---|
499 | for(i=10;i;i--)
|
---|
500 | *scf++ = getbits_fast(num1);
|
---|
501 | numbits = (num0 + num1) * 10 + num0;
|
---|
502 | }
|
---|
503 | else {
|
---|
504 | numbits = 0;
|
---|
505 | if(!(scfsi & 0x8)) {
|
---|
506 | for (i=6;i;i--)
|
---|
507 | *scf++ = getbits_fast(num0);
|
---|
508 | numbits += num0 * 6;
|
---|
509 | }
|
---|
510 | else {
|
---|
511 | *scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
|
---|
512 | *scf++ = 0; *scf++ = 0; *scf++ = 0;
|
---|
513 | }
|
---|
514 |
|
---|
515 | if(!(scfsi & 0x4)) {
|
---|
516 | for (i=5;i;i--)
|
---|
517 | *scf++ = getbits_fast(num0);
|
---|
518 | numbits += num0 * 5;
|
---|
519 | }
|
---|
520 | else {
|
---|
521 | *scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
|
---|
522 | *scf++ = 0; *scf++ = 0;
|
---|
523 | }
|
---|
524 |
|
---|
525 | if(!(scfsi & 0x2)) {
|
---|
526 | for(i=5;i;i--)
|
---|
527 | *scf++ = getbits_fast(num1);
|
---|
528 | numbits += num1 * 5;
|
---|
529 | }
|
---|
530 | else {
|
---|
531 | *scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
|
---|
532 | *scf++ = 0; *scf++ = 0;
|
---|
533 | }
|
---|
534 |
|
---|
535 | if(!(scfsi & 0x1)) {
|
---|
536 | for (i=5;i;i--)
|
---|
537 | *scf++ = getbits_fast(num1);
|
---|
538 | numbits += num1 * 5;
|
---|
539 | }
|
---|
540 | else {
|
---|
541 | *scf++ = 0; *scf++ = 0; *scf++ = 0; /* set to ZERO necessary? */
|
---|
542 | *scf++ = 0; *scf++ = 0;
|
---|
543 | }
|
---|
544 | }
|
---|
545 |
|
---|
546 | *scf++ = 0; /* no l[21] in original sources */
|
---|
547 | }
|
---|
548 | return numbits;
|
---|
549 | }
|
---|
550 |
|
---|
551 | static int III_get_scale_factors_2(int *scf, III_sideinfo::what_the::gr_info_s *gr_info,int i_stereo)
|
---|
552 | {
|
---|
553 | unsigned char *pnt;
|
---|
554 | int i,j;
|
---|
555 | unsigned int slen;
|
---|
556 | int n = 0;
|
---|
557 | int numbits = 0;
|
---|
558 |
|
---|
559 | static unsigned char stab[3][6][4] = {
|
---|
560 | { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} ,
|
---|
561 | { 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } ,
|
---|
562 | { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} ,
|
---|
563 | {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } ,
|
---|
564 | { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} ,
|
---|
565 | { 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} } };
|
---|
566 |
|
---|
567 | if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
|
---|
568 | slen = i_slen2[gr_info->scalefac_compress>>1];
|
---|
569 | else
|
---|
570 | slen = n_slen2[gr_info->scalefac_compress];
|
---|
571 |
|
---|
572 | gr_info->preflag = (slen>>15) & 0x1;
|
---|
573 |
|
---|
574 | n = 0;
|
---|
575 | if( gr_info->block_type == 2 ) {
|
---|
576 | n++;
|
---|
577 | if(gr_info->mixed_block_flag)
|
---|
578 | n++;
|
---|
579 | }
|
---|
580 |
|
---|
581 | pnt = stab[n][(slen>>12)&0x7];
|
---|
582 |
|
---|
583 | for(i=0;i<4;i++) {
|
---|
584 | int num = slen & 0x7;
|
---|
585 | slen >>= 3;
|
---|
586 | if(num) {
|
---|
587 | for(j=0;j<pnt[i];j++)
|
---|
588 | *scf++ = getbits(num);
|
---|
589 | numbits += pnt[i] * num;
|
---|
590 | }
|
---|
591 | else {
|
---|
592 | for(j=0;j<pnt[i];j++)
|
---|
593 | *scf++ = 0;
|
---|
594 | }
|
---|
595 | }
|
---|
596 |
|
---|
597 | n = (n << 1) + 1;
|
---|
598 | for(i=0;i<n;i++)
|
---|
599 | *scf++ = 0;
|
---|
600 |
|
---|
601 | return numbits;
|
---|
602 | }
|
---|
603 |
|
---|
604 | static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0};
|
---|
605 | static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
|
---|
606 |
|
---|
607 | /*
|
---|
608 | * don't forget to apply the same changes to III_dequantize_sample_ms() !!!
|
---|
609 | */
|
---|
610 | static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
|
---|
611 | III_sideinfo::what_the::gr_info_s *gr_info,int sfreq,int part2bits)
|
---|
612 | {
|
---|
613 | int shift = 1 + gr_info->scalefac_scale;
|
---|
614 | real *xrpnt = (real *) xr;
|
---|
615 | int l[3],l3;
|
---|
616 | int part2remain = gr_info->part2_3_length - part2bits;
|
---|
617 | int *me;
|
---|
618 |
|
---|
619 | {
|
---|
620 | int bv = gr_info->big_values;
|
---|
621 | int region1 = gr_info->region1start;
|
---|
622 | int region2 = gr_info->region2start;
|
---|
623 |
|
---|
624 | l3 = ((576>>1)-bv)>>1;
|
---|
625 | /*
|
---|
626 | * we may lose the 'odd' bit here !!
|
---|
627 | * check this later again
|
---|
628 | */
|
---|
629 | if(bv <= region1) {
|
---|
630 | l[0] = bv; l[1] = 0; l[2] = 0;
|
---|
631 | }
|
---|
632 | else {
|
---|
633 | l[0] = region1;
|
---|
634 | if(bv <= region2) {
|
---|
635 | l[1] = bv - l[0]; l[2] = 0;
|
---|
636 | }
|
---|
637 | else {
|
---|
638 | l[1] = region2 - l[0]; l[2] = bv - region2;
|
---|
639 | }
|
---|
640 | }
|
---|
641 | }
|
---|
642 |
|
---|
643 | if(gr_info->block_type == 2) {
|
---|
644 | /*
|
---|
645 | * decoding with short or mixed mode BandIndex table
|
---|
646 | */
|
---|
647 | int i,max[4];
|
---|
648 | int step=0,lwin=0,cb=0;
|
---|
649 | register real v = 0.0;
|
---|
650 | register int *m,mc;
|
---|
651 |
|
---|
652 | if(gr_info->mixed_block_flag) {
|
---|
653 | max[3] = -1;
|
---|
654 | max[0] = max[1] = max[2] = 2;
|
---|
655 | m = map[sfreq][0];
|
---|
656 | me = mapend[sfreq][0];
|
---|
657 | }
|
---|
658 | else {
|
---|
659 | max[0] = max[1] = max[2] = max[3] = -1;
|
---|
660 | /* max[3] not really needed in this case */
|
---|
661 | m = map[sfreq][1];
|
---|
662 | me = mapend[sfreq][1];
|
---|
663 | }
|
---|
664 |
|
---|
665 | mc = 0;
|
---|
666 | for(i=0;i<2;i++) {
|
---|
667 | int lp = l[i];
|
---|
668 | struct newhuff *h = ht+gr_info->table_select[i];
|
---|
669 | for(;lp;lp--,mc--) {
|
---|
670 | register int x,y;
|
---|
671 | if( (!mc) ) {
|
---|
672 | mc = *m++;
|
---|
673 | xrpnt = ((real *) xr) + (*m++);
|
---|
674 | lwin = *m++;
|
---|
675 | cb = *m++;
|
---|
676 | if(lwin == 3) {
|
---|
677 | v = gr_info->pow2gain[(*scf++) << shift];
|
---|
678 | step = 1;
|
---|
679 | }
|
---|
680 | else {
|
---|
681 | v = gr_info->full_gain[lwin][(*scf++) << shift];
|
---|
682 | step = 3;
|
---|
683 | }
|
---|
684 | }
|
---|
685 | {
|
---|
686 | register short *val = h->table;
|
---|
687 | while((y=*val++)<0) {
|
---|
688 | if (get1bit())
|
---|
689 | val -= y;
|
---|
690 | part2remain--;
|
---|
691 | }
|
---|
692 | x = y >> 4;
|
---|
693 | y &= 0xf;
|
---|
694 | }
|
---|
695 | if(x == 15) {
|
---|
696 | max[lwin] = cb;
|
---|
697 | part2remain -= h->linbits+1;
|
---|
698 | x += getbits(h->linbits);
|
---|
699 | if(get1bit())
|
---|
700 | *xrpnt = -ispow[x] * v;
|
---|
701 | else
|
---|
702 | *xrpnt = ispow[x] * v;
|
---|
703 | }
|
---|
704 | else if(x) {
|
---|
705 | max[lwin] = cb;
|
---|
706 | if(get1bit())
|
---|
707 | *xrpnt = -ispow[x] * v;
|
---|
708 | else
|
---|
709 | *xrpnt = ispow[x] * v;
|
---|
710 | part2remain--;
|
---|
711 | }
|
---|
712 | else
|
---|
713 | *xrpnt = 0.0;
|
---|
714 | xrpnt += step;
|
---|
715 | if(y == 15) {
|
---|
716 | max[lwin] = cb;
|
---|
717 | part2remain -= h->linbits+1;
|
---|
718 | y += getbits(h->linbits);
|
---|
719 | if(get1bit())
|
---|
720 | *xrpnt = -ispow[y] * v;
|
---|
721 | else
|
---|
722 | *xrpnt = ispow[y] * v;
|
---|
723 | }
|
---|
724 | else if(y) {
|
---|
725 | max[lwin] = cb;
|
---|
726 | if(get1bit())
|
---|
727 | *xrpnt = -ispow[y] * v;
|
---|
728 | else
|
---|
729 | *xrpnt = ispow[y] * v;
|
---|
730 | part2remain--;
|
---|
731 | }
|
---|
732 | else
|
---|
733 | *xrpnt = 0.0;
|
---|
734 | xrpnt += step;
|
---|
735 | }
|
---|
736 | }
|
---|
737 | for(;l3 && (part2remain > 0);l3--) {
|
---|
738 | struct newhuff *h = htc+gr_info->count1table_select;
|
---|
739 | register short *val = h->table,a;
|
---|
740 |
|
---|
741 | while((a=*val++)<0) {
|
---|
742 | part2remain--;
|
---|
743 | if(part2remain < 0) {
|
---|
744 | part2remain++;
|
---|
745 | a = 0;
|
---|
746 | break;
|
---|
747 | }
|
---|
748 | if (get1bit())
|
---|
749 | val -= a;
|
---|
750 | }
|
---|
751 |
|
---|
752 | for(i=0;i<4;i++) {
|
---|
753 | if(!(i & 1)) {
|
---|
754 | if(!mc) {
|
---|
755 | mc = *m++;
|
---|
756 | xrpnt = ((real *) xr) + (*m++);
|
---|
757 | lwin = *m++;
|
---|
758 | cb = *m++;
|
---|
759 | if(lwin == 3) {
|
---|
760 | v = gr_info->pow2gain[(*scf++) << shift];
|
---|
761 | step = 1;
|
---|
762 | }
|
---|
763 | else {
|
---|
764 | v = gr_info->full_gain[lwin][(*scf++) << shift];
|
---|
765 | step = 3;
|
---|
766 | }
|
---|
767 | }
|
---|
768 | mc--;
|
---|
769 | }
|
---|
770 | if( (a & (0x8>>i)) ) {
|
---|
771 | max[lwin] = cb;
|
---|
772 | part2remain--;
|
---|
773 | if(part2remain < 0) {
|
---|
774 | part2remain++;
|
---|
775 | break;
|
---|
776 | }
|
---|
777 | if(get1bit())
|
---|
778 | *xrpnt = -v;
|
---|
779 | else
|
---|
780 | *xrpnt = v;
|
---|
781 | }
|
---|
782 | else
|
---|
783 | *xrpnt = 0.0;
|
---|
784 | xrpnt += step;
|
---|
785 | }
|
---|
786 | }
|
---|
787 |
|
---|
788 | while( m < me ) {
|
---|
789 | if(!mc) {
|
---|
790 | mc = *m++;
|
---|
791 | xrpnt = ((real *) xr) + *m++;
|
---|
792 | if( (*m++) == 3)
|
---|
793 | step = 1;
|
---|
794 | else
|
---|
795 | step = 3;
|
---|
796 | m++; /* cb */
|
---|
797 | }
|
---|
798 | mc--;
|
---|
799 | *xrpnt = 0.0;
|
---|
800 | xrpnt += step;
|
---|
801 | *xrpnt = 0.0;
|
---|
802 | xrpnt += step;
|
---|
803 | /* we could add a little opt. here:
|
---|
804 | * if we finished a band for window 3 or a long band
|
---|
805 | * further bands could copied in a simple loop without a
|
---|
806 | * special 'map' decoding
|
---|
807 | */
|
---|
808 | }
|
---|
809 |
|
---|
810 | gr_info->maxband[0] = max[0]+1;
|
---|
811 | gr_info->maxband[1] = max[1]+1;
|
---|
812 | gr_info->maxband[2] = max[2]+1;
|
---|
813 | gr_info->maxbandl = max[3]+1;
|
---|
814 |
|
---|
815 | {
|
---|
816 | int rmax = max[0] > max[1] ? max[0] : max[1];
|
---|
817 | rmax = (rmax > max[2] ? rmax : max[2]) + 1;
|
---|
818 | gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1];
|
---|
819 | }
|
---|
820 |
|
---|
821 | }
|
---|
822 | else {
|
---|
823 | /*
|
---|
824 | * decoding with 'long' BandIndex table (block_type != 2)
|
---|
825 | */
|
---|
826 | int *pretab = gr_info->preflag ? pretab1 : pretab2;
|
---|
827 | int i,max = -1;
|
---|
828 | int cb = 0;
|
---|
829 | register int *m = map[sfreq][2];
|
---|
830 | register real v = 0.0;
|
---|
831 | register int mc = 0;
|
---|
832 | #if 0
|
---|
833 | me = mapend[sfreq][2];
|
---|
834 | #endif
|
---|
835 |
|
---|
836 | /*
|
---|
837 | * long hash table values
|
---|
838 | */
|
---|
839 | for(i=0;i<3;i++) {
|
---|
840 | int lp = l[i];
|
---|
841 | struct newhuff *h = ht+gr_info->table_select[i];
|
---|
842 |
|
---|
843 | for(;lp;lp--,mc--) {
|
---|
844 | int x,y;
|
---|
845 |
|
---|
846 | if(!mc) {
|
---|
847 | mc = *m++;
|
---|
848 | v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
|
---|
849 | cb = *m++;
|
---|
850 | }
|
---|
851 | {
|
---|
852 | register short *val = h->table;
|
---|
853 | while((y=*val++)<0) {
|
---|
854 | if (get1bit())
|
---|
855 | val -= y;
|
---|
856 | part2remain--;
|
---|
857 | }
|
---|
858 | x = y >> 4;
|
---|
859 | y &= 0xf;
|
---|
860 | }
|
---|
861 | if (x == 15) {
|
---|
862 | max = cb;
|
---|
863 | part2remain -= h->linbits+1;
|
---|
864 | x += getbits(h->linbits);
|
---|
865 | if(get1bit())
|
---|
866 | *xrpnt++ = -ispow[x] * v;
|
---|
867 | else
|
---|
868 | *xrpnt++ = ispow[x] * v;
|
---|
869 | }
|
---|
870 | else if(x) {
|
---|
871 | max = cb;
|
---|
872 | if(get1bit())
|
---|
873 | *xrpnt++ = -ispow[x] * v;
|
---|
874 | else
|
---|
875 | *xrpnt++ = ispow[x] * v;
|
---|
876 | part2remain--;
|
---|
877 | }
|
---|
878 | else
|
---|
879 | *xrpnt++ = 0.0;
|
---|
880 |
|
---|
881 | if (y == 15) {
|
---|
882 | max = cb;
|
---|
883 | part2remain -= h->linbits+1;
|
---|
884 | y += getbits(h->linbits);
|
---|
885 | if(get1bit())
|
---|
886 | *xrpnt++ = -ispow[y] * v;
|
---|
887 | else
|
---|
888 | *xrpnt++ = ispow[y] * v;
|
---|
889 | }
|
---|
890 | else if(y) {
|
---|
891 | max = cb;
|
---|
892 | if(get1bit())
|
---|
893 | *xrpnt++ = -ispow[y] * v;
|
---|
894 | else
|
---|
895 | *xrpnt++ = ispow[y] * v;
|
---|
896 | part2remain--;
|
---|
897 | }
|
---|
898 | else
|
---|
899 | *xrpnt++ = 0.0;
|
---|
900 | }
|
---|
901 | }
|
---|
902 |
|
---|
903 | /*
|
---|
904 | * short (count1table) values
|
---|
905 | */
|
---|
906 | for(;l3 && (part2remain > 0);l3--) {
|
---|
907 | struct newhuff *h = htc+gr_info->count1table_select;
|
---|
908 | register short *val = h->table,a;
|
---|
909 |
|
---|
910 | while((a=*val++)<0) {
|
---|
911 | part2remain--;
|
---|
912 | if(part2remain < 0) {
|
---|
913 | part2remain++;
|
---|
914 | a = 0;
|
---|
915 | break;
|
---|
916 | }
|
---|
917 | if (get1bit())
|
---|
918 | val -= a;
|
---|
919 | }
|
---|
920 |
|
---|
921 | for(i=0;i<4;i++) {
|
---|
922 | if(!(i & 1)) {
|
---|
923 | if(!mc) {
|
---|
924 | mc = *m++;
|
---|
925 | cb = *m++;
|
---|
926 | v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
|
---|
927 | }
|
---|
928 | mc--;
|
---|
929 | }
|
---|
930 | if ( (a & (0x8>>i)) ) {
|
---|
931 | max = cb;
|
---|
932 | part2remain--;
|
---|
933 | if(part2remain < 0) {
|
---|
934 | part2remain++;
|
---|
935 | break;
|
---|
936 | }
|
---|
937 | if(get1bit())
|
---|
938 | *xrpnt++ = -v;
|
---|
939 | else
|
---|
940 | *xrpnt++ = v;
|
---|
941 | }
|
---|
942 | else
|
---|
943 | *xrpnt++ = 0.0;
|
---|
944 | }
|
---|
945 | }
|
---|
946 |
|
---|
947 | /*
|
---|
948 | * zero part
|
---|
949 | */
|
---|
950 | for(i=(&xr[SBLIMIT][SSLIMIT]-xrpnt)>>1;i;i--) {
|
---|
951 | *xrpnt++ = 0.0;
|
---|
952 | *xrpnt++ = 0.0;
|
---|
953 | }
|
---|
954 |
|
---|
955 | gr_info->maxbandl = max+1;
|
---|
956 | gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
|
---|
957 | }
|
---|
958 |
|
---|
959 | while( part2remain > 16 ) {
|
---|
960 | getbits(16); /* Dismiss stuffing Bits */
|
---|
961 | part2remain -= 16;
|
---|
962 | }
|
---|
963 | if(part2remain > 0)
|
---|
964 | getbits(part2remain);
|
---|
965 | else if(part2remain < 0) {
|
---|
966 | return 1; /* -> error */
|
---|
967 | }
|
---|
968 | return 0;
|
---|
969 | }
|
---|
970 |
|
---|
971 | static int III_dequantize_sample_ms(real xr[2][SBLIMIT][SSLIMIT],int *scf,
|
---|
972 | III_sideinfo::what_the::gr_info_s *gr_info,int sfreq,int part2bits)
|
---|
973 | {
|
---|
974 | int shift = 1 + gr_info->scalefac_scale;
|
---|
975 | real *xrpnt = (real *) xr[1];
|
---|
976 | real *xr0pnt = (real *) xr[0];
|
---|
977 | int l[3],l3;
|
---|
978 | int part2remain = gr_info->part2_3_length - part2bits;
|
---|
979 | int *me;
|
---|
980 |
|
---|
981 | {
|
---|
982 | int bv = gr_info->big_values;
|
---|
983 | int region1 = gr_info->region1start;
|
---|
984 | int region2 = gr_info->region2start;
|
---|
985 |
|
---|
986 | l3 = ((576>>1)-bv)>>1;
|
---|
987 | /*
|
---|
988 | * we may lose the 'odd' bit here !!
|
---|
989 | * check this later gain
|
---|
990 | */
|
---|
991 | if(bv <= region1) {
|
---|
992 | l[0] = bv; l[1] = 0; l[2] = 0;
|
---|
993 | }
|
---|
994 | else {
|
---|
995 | l[0] = region1;
|
---|
996 | if(bv <= region2) {
|
---|
997 | l[1] = bv - l[0]; l[2] = 0;
|
---|
998 | }
|
---|
999 | else {
|
---|
1000 | l[1] = region2 - l[0]; l[2] = bv - region2;
|
---|
1001 | }
|
---|
1002 | }
|
---|
1003 | }
|
---|
1004 |
|
---|
1005 | if(gr_info->block_type == 2) {
|
---|
1006 | int i,max[4];
|
---|
1007 | int step=0,lwin=0,cb=0;
|
---|
1008 | register real v = 0.0;
|
---|
1009 | register int *m,mc = 0;
|
---|
1010 |
|
---|
1011 | if(gr_info->mixed_block_flag) {
|
---|
1012 | max[3] = -1;
|
---|
1013 | max[0] = max[1] = max[2] = 2;
|
---|
1014 | m = map[sfreq][0];
|
---|
1015 | me = mapend[sfreq][0];
|
---|
1016 | }
|
---|
1017 | else {
|
---|
1018 | max[0] = max[1] = max[2] = max[3] = -1;
|
---|
1019 | /* max[3] not really needed in this case */
|
---|
1020 | m = map[sfreq][1];
|
---|
1021 | me = mapend[sfreq][1];
|
---|
1022 | }
|
---|
1023 |
|
---|
1024 | for(i=0;i<2;i++) {
|
---|
1025 | int lp = l[i];
|
---|
1026 | struct newhuff *h = ht+gr_info->table_select[i];
|
---|
1027 | for(;lp;lp--,mc--) {
|
---|
1028 | int x,y;
|
---|
1029 |
|
---|
1030 | if(!mc) {
|
---|
1031 | mc = *m++;
|
---|
1032 | xrpnt = ((real *) xr[1]) + *m;
|
---|
1033 | xr0pnt = ((real *) xr[0]) + *m++;
|
---|
1034 | lwin = *m++;
|
---|
1035 | cb = *m++;
|
---|
1036 | if(lwin == 3) {
|
---|
1037 | v = gr_info->pow2gain[(*scf++) << shift];
|
---|
1038 | step = 1;
|
---|
1039 | }
|
---|
1040 | else {
|
---|
1041 | v = gr_info->full_gain[lwin][(*scf++) << shift];
|
---|
1042 | step = 3;
|
---|
1043 | }
|
---|
1044 | }
|
---|
1045 | {
|
---|
1046 | register short *val = h->table;
|
---|
1047 | while((y=*val++)<0) {
|
---|
1048 | if (get1bit())
|
---|
1049 | val -= y;
|
---|
1050 | part2remain--;
|
---|
1051 | }
|
---|
1052 | x = y >> 4;
|
---|
1053 | y &= 0xf;
|
---|
1054 | }
|
---|
1055 | if(x == 15) {
|
---|
1056 | max[lwin] = cb;
|
---|
1057 | part2remain -= h->linbits+1;
|
---|
1058 | x += getbits(h->linbits);
|
---|
1059 | if(get1bit()) {
|
---|
1060 | real a = ispow[x] * v;
|
---|
1061 | *xrpnt = *xr0pnt + a;
|
---|
1062 | *xr0pnt -= a;
|
---|
1063 | }
|
---|
1064 | else {
|
---|
1065 | real a = ispow[x] * v;
|
---|
1066 | *xrpnt = *xr0pnt - a;
|
---|
1067 | *xr0pnt += a;
|
---|
1068 | }
|
---|
1069 | }
|
---|
1070 | else if(x) {
|
---|
1071 | max[lwin] = cb;
|
---|
1072 | if(get1bit()) {
|
---|
1073 | real a = ispow[x] * v;
|
---|
1074 | *xrpnt = *xr0pnt + a;
|
---|
1075 | *xr0pnt -= a;
|
---|
1076 | }
|
---|
1077 | else {
|
---|
1078 | real a = ispow[x] * v;
|
---|
1079 | *xrpnt = *xr0pnt - a;
|
---|
1080 | *xr0pnt += a;
|
---|
1081 | }
|
---|
1082 | part2remain--;
|
---|
1083 | }
|
---|
1084 | else
|
---|
1085 | *xrpnt = *xr0pnt;
|
---|
1086 | xrpnt += step;
|
---|
1087 | xr0pnt += step;
|
---|
1088 |
|
---|
1089 | if(y == 15) {
|
---|
1090 | max[lwin] = cb;
|
---|
1091 | part2remain -= h->linbits+1;
|
---|
1092 | y += getbits(h->linbits);
|
---|
1093 | if(get1bit()) {
|
---|
1094 | real a = ispow[y] * v;
|
---|
1095 | *xrpnt = *xr0pnt + a;
|
---|
1096 | *xr0pnt -= a;
|
---|
1097 | }
|
---|
1098 | else {
|
---|
1099 | real a = ispow[y] * v;
|
---|
1100 | *xrpnt = *xr0pnt - a;
|
---|
1101 | *xr0pnt += a;
|
---|
1102 | }
|
---|
1103 | }
|
---|
1104 | else if(y) {
|
---|
1105 | max[lwin] = cb;
|
---|
1106 | if(get1bit()) {
|
---|
1107 | real a = ispow[y] * v;
|
---|
1108 | *xrpnt = *xr0pnt + a;
|
---|
1109 | *xr0pnt -= a;
|
---|
1110 | }
|
---|
1111 | else {
|
---|
1112 | real a = ispow[y] * v;
|
---|
1113 | *xrpnt = *xr0pnt - a;
|
---|
1114 | *xr0pnt += a;
|
---|
1115 | }
|
---|
1116 | part2remain--;
|
---|
1117 | }
|
---|
1118 | else
|
---|
1119 | *xrpnt = *xr0pnt;
|
---|
1120 | xrpnt += step;
|
---|
1121 | xr0pnt += step;
|
---|
1122 | }
|
---|
1123 | }
|
---|
1124 |
|
---|
1125 | for(;l3 && (part2remain > 0);l3--) {
|
---|
1126 | struct newhuff *h = htc+gr_info->count1table_select;
|
---|
1127 | register short *val = h->table,a;
|
---|
1128 |
|
---|
1129 | while((a=*val++)<0) {
|
---|
1130 | part2remain--;
|
---|
1131 | if(part2remain < 0) {
|
---|
1132 | part2remain++;
|
---|
1133 | a = 0;
|
---|
1134 | break;
|
---|
1135 | }
|
---|
1136 | if (get1bit())
|
---|
1137 | val -= a;
|
---|
1138 | }
|
---|
1139 |
|
---|
1140 | for(i=0;i<4;i++) {
|
---|
1141 | if(!(i & 1)) {
|
---|
1142 | if(!mc) {
|
---|
1143 | mc = *m++;
|
---|
1144 | xrpnt = ((real *) xr[1]) + *m;
|
---|
1145 | xr0pnt = ((real *) xr[0]) + *m++;
|
---|
1146 | lwin = *m++;
|
---|
1147 | cb = *m++;
|
---|
1148 | if(lwin == 3) {
|
---|
1149 | v = gr_info->pow2gain[(*scf++) << shift];
|
---|
1150 | step = 1;
|
---|
1151 | }
|
---|
1152 | else {
|
---|
1153 | v = gr_info->full_gain[lwin][(*scf++) << shift];
|
---|
1154 | step = 3;
|
---|
1155 | }
|
---|
1156 | }
|
---|
1157 | mc--;
|
---|
1158 | }
|
---|
1159 | if( (a & (0x8>>i)) ) {
|
---|
1160 | max[lwin] = cb;
|
---|
1161 | part2remain--;
|
---|
1162 | if(part2remain < 0) {
|
---|
1163 | part2remain++;
|
---|
1164 | break;
|
---|
1165 | }
|
---|
1166 | if(get1bit()) {
|
---|
1167 | *xrpnt = *xr0pnt + v;
|
---|
1168 | *xr0pnt -= v;
|
---|
1169 | }
|
---|
1170 | else {
|
---|
1171 | *xrpnt = *xr0pnt - v;
|
---|
1172 | *xr0pnt += v;
|
---|
1173 | }
|
---|
1174 | }
|
---|
1175 | else
|
---|
1176 | *xrpnt = *xr0pnt;
|
---|
1177 | xrpnt += step;
|
---|
1178 | xr0pnt += step;
|
---|
1179 | }
|
---|
1180 | }
|
---|
1181 |
|
---|
1182 | while( m < me ) {
|
---|
1183 | if(!mc) {
|
---|
1184 | mc = *m++;
|
---|
1185 | xrpnt = ((real *) xr[1]) + *m;
|
---|
1186 | xr0pnt = ((real *) xr[0]) + *m++;
|
---|
1187 | if(*m++ == 3)
|
---|
1188 | step = 1;
|
---|
1189 | else
|
---|
1190 | step = 3;
|
---|
1191 | m++; /* cb */
|
---|
1192 | }
|
---|
1193 | mc--;
|
---|
1194 | *xrpnt = *xr0pnt;
|
---|
1195 | xrpnt += step;
|
---|
1196 | xr0pnt += step;
|
---|
1197 | *xrpnt = *xr0pnt;
|
---|
1198 | xrpnt += step;
|
---|
1199 | xr0pnt += step;
|
---|
1200 | /* we could add a little opt. here:
|
---|
1201 | * if we finished a band for window 3 or a long band
|
---|
1202 | * further bands could copied in a simple loop without a
|
---|
1203 | * special 'map' decoding
|
---|
1204 | */
|
---|
1205 | }
|
---|
1206 |
|
---|
1207 | gr_info->maxband[0] = max[0]+1;
|
---|
1208 | gr_info->maxband[1] = max[1]+1;
|
---|
1209 | gr_info->maxband[2] = max[2]+1;
|
---|
1210 | gr_info->maxbandl = max[3]+1;
|
---|
1211 |
|
---|
1212 | {
|
---|
1213 | int rmax = max[0] > max[1] ? max[0] : max[1];
|
---|
1214 | rmax = (rmax > max[2] ? rmax : max[2]) + 1;
|
---|
1215 | gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1];
|
---|
1216 | }
|
---|
1217 | }
|
---|
1218 | else {
|
---|
1219 | int *pretab = gr_info->preflag ? pretab1 : pretab2;
|
---|
1220 | int i,max = -1;
|
---|
1221 | int cb = 0;
|
---|
1222 | register int mc=0,*m = map[sfreq][2];
|
---|
1223 | register real v = 0.0;
|
---|
1224 | #if 0
|
---|
1225 | me = mapend[sfreq][2];
|
---|
1226 | #endif
|
---|
1227 |
|
---|
1228 | for(i=0;i<3;i++) {
|
---|
1229 | int lp = l[i];
|
---|
1230 | struct newhuff *h = ht+gr_info->table_select[i];
|
---|
1231 |
|
---|
1232 | for(;lp;lp--,mc--) {
|
---|
1233 | int x,y;
|
---|
1234 | if(!mc) {
|
---|
1235 | mc = *m++;
|
---|
1236 | cb = *m++;
|
---|
1237 | v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
|
---|
1238 | }
|
---|
1239 | {
|
---|
1240 | register short *val = h->table;
|
---|
1241 | while((y=*val++)<0) {
|
---|
1242 | if (get1bit())
|
---|
1243 | val -= y;
|
---|
1244 | part2remain--;
|
---|
1245 | }
|
---|
1246 | x = y >> 4;
|
---|
1247 | y &= 0xf;
|
---|
1248 | }
|
---|
1249 | if (x == 15) {
|
---|
1250 | max = cb;
|
---|
1251 | part2remain -= h->linbits+1;
|
---|
1252 | x += getbits(h->linbits);
|
---|
1253 | if(get1bit()) {
|
---|
1254 | real a = ispow[x] * v;
|
---|
1255 | *xrpnt++ = *xr0pnt + a;
|
---|
1256 | *xr0pnt++ -= a;
|
---|
1257 | }
|
---|
1258 | else {
|
---|
1259 | real a = ispow[x] * v;
|
---|
1260 | *xrpnt++ = *xr0pnt - a;
|
---|
1261 | *xr0pnt++ += a;
|
---|
1262 | }
|
---|
1263 | }
|
---|
1264 | else if(x) {
|
---|
1265 | max = cb;
|
---|
1266 | if(get1bit()) {
|
---|
1267 | real a = ispow[x] * v;
|
---|
1268 | *xrpnt++ = *xr0pnt + a;
|
---|
1269 | *xr0pnt++ -= a;
|
---|
1270 | }
|
---|
1271 | else {
|
---|
1272 | real a = ispow[x] * v;
|
---|
1273 | *xrpnt++ = *xr0pnt - a;
|
---|
1274 | *xr0pnt++ += a;
|
---|
1275 | }
|
---|
1276 | part2remain--;
|
---|
1277 | }
|
---|
1278 | else
|
---|
1279 | *xrpnt++ = *xr0pnt++;
|
---|
1280 |
|
---|
1281 | if (y == 15) {
|
---|
1282 | max = cb;
|
---|
1283 | part2remain -= h->linbits+1;
|
---|
1284 | y += getbits(h->linbits);
|
---|
1285 | if(get1bit()) {
|
---|
1286 | real a = ispow[y] * v;
|
---|
1287 | *xrpnt++ = *xr0pnt + a;
|
---|
1288 | *xr0pnt++ -= a;
|
---|
1289 | }
|
---|
1290 | else {
|
---|
1291 | real a = ispow[y] * v;
|
---|
1292 | *xrpnt++ = *xr0pnt - a;
|
---|
1293 | *xr0pnt++ += a;
|
---|
1294 | }
|
---|
1295 | }
|
---|
1296 | else if(y) {
|
---|
1297 | max = cb;
|
---|
1298 | if(get1bit()) {
|
---|
1299 | real a = ispow[y] * v;
|
---|
1300 | *xrpnt++ = *xr0pnt + a;
|
---|
1301 | *xr0pnt++ -= a;
|
---|
1302 | }
|
---|
1303 | else {
|
---|
1304 | real a = ispow[y] * v;
|
---|
1305 | *xrpnt++ = *xr0pnt - a;
|
---|
1306 | *xr0pnt++ += a;
|
---|
1307 | }
|
---|
1308 | part2remain--;
|
---|
1309 | }
|
---|
1310 | else
|
---|
1311 | *xrpnt++ = *xr0pnt++;
|
---|
1312 | }
|
---|
1313 | }
|
---|
1314 |
|
---|
1315 | for(;l3 && (part2remain > 0);l3--) {
|
---|
1316 | struct newhuff *h = htc+gr_info->count1table_select;
|
---|
1317 | register short *val = h->table,a;
|
---|
1318 |
|
---|
1319 | while((a=*val++)<0) {
|
---|
1320 | part2remain--;
|
---|
1321 | if(part2remain < 0) {
|
---|
1322 | part2remain++;
|
---|
1323 | a = 0;
|
---|
1324 | break;
|
---|
1325 | }
|
---|
1326 | if (get1bit())
|
---|
1327 | val -= a;
|
---|
1328 | }
|
---|
1329 |
|
---|
1330 | for(i=0;i<4;i++) {
|
---|
1331 | if(!(i & 1)) {
|
---|
1332 | if(!mc) {
|
---|
1333 | mc = *m++;
|
---|
1334 | cb = *m++;
|
---|
1335 | v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
|
---|
1336 | }
|
---|
1337 | mc--;
|
---|
1338 | }
|
---|
1339 | if ( (a & (0x8>>i)) ) {
|
---|
1340 | max = cb;
|
---|
1341 | part2remain--;
|
---|
1342 | if(part2remain <= 0) {
|
---|
1343 | part2remain++;
|
---|
1344 | break;
|
---|
1345 | }
|
---|
1346 | if(get1bit()) {
|
---|
1347 | *xrpnt++ = *xr0pnt + v;
|
---|
1348 | *xr0pnt++ -= v;
|
---|
1349 | }
|
---|
1350 | else {
|
---|
1351 | *xrpnt++ = *xr0pnt - v;
|
---|
1352 | *xr0pnt++ += v;
|
---|
1353 | }
|
---|
1354 | }
|
---|
1355 | else
|
---|
1356 | *xrpnt++ = *xr0pnt++;
|
---|
1357 | }
|
---|
1358 | }
|
---|
1359 | for(i=(&xr[1][SBLIMIT][SSLIMIT]-xrpnt)>>1;i;i--) {
|
---|
1360 | *xrpnt++ = *xr0pnt++;
|
---|
1361 | *xrpnt++ = *xr0pnt++;
|
---|
1362 | }
|
---|
1363 |
|
---|
1364 | gr_info->maxbandl = max+1;
|
---|
1365 | gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
|
---|
1366 | }
|
---|
1367 |
|
---|
1368 | while ( part2remain > 16 ) {
|
---|
1369 | getbits(16); /* Dismiss stuffing Bits */
|
---|
1370 | part2remain -= 16;
|
---|
1371 | }
|
---|
1372 | if(part2remain > 0 )
|
---|
1373 | getbits(part2remain);
|
---|
1374 | else if(part2remain < 0) {
|
---|
1375 | return 1; /* -> error */
|
---|
1376 | }
|
---|
1377 | return 0;
|
---|
1378 | }
|
---|
1379 |
|
---|
1380 | /*
|
---|
1381 | * III_stereo: calculate real channel values for Joint-I-Stereo-mode
|
---|
1382 | */
|
---|
1383 | static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
|
---|
1384 | III_sideinfo::what_the::gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf)
|
---|
1385 | {
|
---|
1386 | real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf;
|
---|
1387 | struct bandInfoStruct *bi = &bandInfo[sfreq];
|
---|
1388 | real *tab1,*tab2;
|
---|
1389 |
|
---|
1390 | if(lsf) {
|
---|
1391 | int p = gr_info->scalefac_compress & 0x1;
|
---|
1392 | if(ms_stereo) {
|
---|
1393 | tab1 = pow1_2[p]; tab2 = pow2_2[p];
|
---|
1394 | }
|
---|
1395 | else {
|
---|
1396 | tab1 = pow1_1[p]; tab2 = pow2_1[p];
|
---|
1397 | }
|
---|
1398 | }
|
---|
1399 | else {
|
---|
1400 | if(ms_stereo) {
|
---|
1401 | tab1 = tan1_2; tab2 = tan2_2;
|
---|
1402 | }
|
---|
1403 | else {
|
---|
1404 | tab1 = tan1_1; tab2 = tan2_1;
|
---|
1405 | }
|
---|
1406 | }
|
---|
1407 |
|
---|
1408 | if (gr_info->block_type == 2)
|
---|
1409 | {
|
---|
1410 | int lwin,do_l = 0;
|
---|
1411 | if( gr_info->mixed_block_flag )
|
---|
1412 | do_l = 1;
|
---|
1413 |
|
---|
1414 | for (lwin=0;lwin<3;lwin++) /* process each window */
|
---|
1415 | {
|
---|
1416 | /* get first band with zero values */
|
---|
1417 | int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */
|
---|
1418 | if(sfb > 3)
|
---|
1419 | do_l = 0;
|
---|
1420 |
|
---|
1421 | for(;sfb<12;sfb++)
|
---|
1422 | {
|
---|
1423 | is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
|
---|
1424 | if(is_p != 7) {
|
---|
1425 | real t1,t2;
|
---|
1426 | sb = bi->shortDiff[sfb];
|
---|
1427 | idx = bi->shortIdx[sfb] + lwin;
|
---|
1428 | t1 = tab1[is_p]; t2 = tab2[is_p];
|
---|
1429 | for (; sb > 0; sb--,idx+=3)
|
---|
1430 | {
|
---|
1431 | real v = xr[0][idx];
|
---|
1432 | xr[0][idx] = v * t1;
|
---|
1433 | xr[1][idx] = v * t2;
|
---|
1434 | }
|
---|
1435 | }
|
---|
1436 | }
|
---|
1437 |
|
---|
1438 | #if 1
|
---|
1439 | /* in the original: copy 10 to 11 , here: copy 11 to 12
|
---|
1440 | maybe still wrong??? (copy 12 to 13?) */
|
---|
1441 | is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
|
---|
1442 | sb = bi->shortDiff[12];
|
---|
1443 | idx = bi->shortIdx[12] + lwin;
|
---|
1444 | #else
|
---|
1445 | is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
|
---|
1446 | sb = bi->shortDiff[11];
|
---|
1447 | idx = bi->shortIdx[11] + lwin;
|
---|
1448 | #endif
|
---|
1449 | if(is_p != 7)
|
---|
1450 | {
|
---|
1451 | real t1,t2;
|
---|
1452 | t1 = tab1[is_p]; t2 = tab2[is_p];
|
---|
1453 | for ( ; sb > 0; sb--,idx+=3 )
|
---|
1454 | {
|
---|
1455 | real v = xr[0][idx];
|
---|
1456 | xr[0][idx] = v * t1;
|
---|
1457 | xr[1][idx] = v * t2;
|
---|
1458 | }
|
---|
1459 | }
|
---|
1460 | } /* end for(lwin; .. ; . ) */
|
---|
1461 |
|
---|
1462 | if (do_l)
|
---|
1463 | {
|
---|
1464 | /* also check l-part, if ALL bands in the three windows are 'empty'
|
---|
1465 | * and mode = mixed_mode
|
---|
1466 | */
|
---|
1467 | int sfb = gr_info->maxbandl;
|
---|
1468 | int idx = bi->longIdx[sfb];
|
---|
1469 |
|
---|
1470 | for ( ; sfb<8; sfb++ )
|
---|
1471 | {
|
---|
1472 | int sb = bi->longDiff[sfb];
|
---|
1473 | int is_p = scalefac[sfb]; /* scale: 0-15 */
|
---|
1474 | if(is_p != 7) {
|
---|
1475 | real t1,t2;
|
---|
1476 | t1 = tab1[is_p]; t2 = tab2[is_p];
|
---|
1477 | for ( ; sb > 0; sb--,idx++)
|
---|
1478 | {
|
---|
1479 | real v = xr[0][idx];
|
---|
1480 | xr[0][idx] = v * t1;
|
---|
1481 | xr[1][idx] = v * t2;
|
---|
1482 | }
|
---|
1483 | }
|
---|
1484 | else
|
---|
1485 | idx += sb;
|
---|
1486 | }
|
---|
1487 | }
|
---|
1488 | }
|
---|
1489 | else /* ((gr_info->block_type != 2)) */
|
---|
1490 | {
|
---|
1491 | int sfb = gr_info->maxbandl;
|
---|
1492 | int is_p,idx = bi->longIdx[sfb];
|
---|
1493 | for ( ; sfb<21; sfb++)
|
---|
1494 | {
|
---|
1495 | int sb = bi->longDiff[sfb];
|
---|
1496 | is_p = scalefac[sfb]; /* scale: 0-15 */
|
---|
1497 | if(is_p != 7) {
|
---|
1498 | real t1,t2;
|
---|
1499 | t1 = tab1[is_p]; t2 = tab2[is_p];
|
---|
1500 | for ( ; sb > 0; sb--,idx++)
|
---|
1501 | {
|
---|
1502 | real v = xr[0][idx];
|
---|
1503 | xr[0][idx] = v * t1;
|
---|
1504 | xr[1][idx] = v * t2;
|
---|
1505 | }
|
---|
1506 | }
|
---|
1507 | else
|
---|
1508 | idx += sb;
|
---|
1509 | }
|
---|
1510 |
|
---|
1511 | is_p = scalefac[20]; /* copy l-band 20 to l-band 21 */
|
---|
1512 | if(is_p != 7)
|
---|
1513 | {
|
---|
1514 | int sb;
|
---|
1515 | real t1 = tab1[is_p],t2 = tab2[is_p];
|
---|
1516 |
|
---|
1517 | for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ )
|
---|
1518 | {
|
---|
1519 | real v = xr[0][idx];
|
---|
1520 | xr[0][idx] = v * t1;
|
---|
1521 | xr[1][idx] = v * t2;
|
---|
1522 | }
|
---|
1523 | }
|
---|
1524 | } /* ... */
|
---|
1525 | }
|
---|
1526 |
|
---|
1527 | static void III_antialias(real xr[SBLIMIT][SSLIMIT], III_sideinfo::what_the::gr_info_s *gr_info)
|
---|
1528 | {
|
---|
1529 | int sblim;
|
---|
1530 |
|
---|
1531 | if(gr_info->block_type == 2)
|
---|
1532 | {
|
---|
1533 | if(!gr_info->mixed_block_flag)
|
---|
1534 | return;
|
---|
1535 | sblim = 1;
|
---|
1536 | }
|
---|
1537 | else {
|
---|
1538 | sblim = gr_info->maxb-1;
|
---|
1539 | }
|
---|
1540 |
|
---|
1541 | /* 31 alias-reduction operations between each pair of sub-bands */
|
---|
1542 | /* with 8 butterflies between each pair */
|
---|
1543 |
|
---|
1544 | {
|
---|
1545 | int sb;
|
---|
1546 | real *xr1=(real *) xr[1];
|
---|
1547 |
|
---|
1548 | for(sb=sblim;sb;sb--,xr1+=10)
|
---|
1549 | {
|
---|
1550 | int ss;
|
---|
1551 | real *cs=aa_cs,*ca=aa_ca;
|
---|
1552 | real *xr2 = xr1;
|
---|
1553 |
|
---|
1554 | for(ss=7;ss>=0;ss--)
|
---|
1555 | { /* upper and lower butterfly inputs */
|
---|
1556 | register real bu = *--xr2,bd = *xr1;
|
---|
1557 | *xr2 = (bu * (*cs) ) - (bd * (*ca) );
|
---|
1558 | *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) );
|
---|
1559 | }
|
---|
1560 | }
|
---|
1561 | }
|
---|
1562 | }
|
---|
1563 |
|
---|
1564 | /*
|
---|
1565 | // This is an optimized DCT from Jeff Tsay's maplay 1.2+ package.
|
---|
1566 | // Saved one multiplication by doing the 'twiddle factor' stuff
|
---|
1567 | // together with the window mul. (MH)
|
---|
1568 | //
|
---|
1569 | // This uses Byeong Gi Lee's Fast Cosine Transform algorithm, but the
|
---|
1570 | // 9 point IDCT needs to be reduced further. Unfortunately, I don't
|
---|
1571 | // know how to do that, because 9 is not an even number. - Jeff.
|
---|
1572 | //
|
---|
1573 | //////////////////////////////////////////////////////////////////
|
---|
1574 | //
|
---|
1575 | // 9 Point Inverse Discrete Cosine Transform
|
---|
1576 | //
|
---|
1577 | // This piece of code is Copyright 1997 Mikko Tommila and is freely usable
|
---|
1578 | // by anybody. The algorithm itself is of course in the public domain.
|
---|
1579 | //
|
---|
1580 | // Again derived heuristically from the 9-point WFTA.
|
---|
1581 | //
|
---|
1582 | // The algorithm is optimized (?) for speed, not for small rounding errors or
|
---|
1583 | // good readability.
|
---|
1584 | //
|
---|
1585 | // 36 additions, 11 multiplications
|
---|
1586 | //
|
---|
1587 | // Again this is very likely sub-optimal.
|
---|
1588 | //
|
---|
1589 | // The code is optimized to use a minimum number of temporary variables,
|
---|
1590 | // so it should compile quite well even on 8-register Intel x86 processors.
|
---|
1591 | // This makes the code quite obfuscated and very difficult to understand.
|
---|
1592 | //
|
---|
1593 | // References:
|
---|
1594 | // [1] S. Winograd: "On Computing the Discrete Fourier Transform",
|
---|
1595 | // Mathematics of Computation, Volume 32, Number 141, January 1978,
|
---|
1596 | // Pages 175-199
|
---|
1597 | */
|
---|
1598 |
|
---|
1599 | /*------------------------------------------------------------------*/
|
---|
1600 | /* */
|
---|
1601 | /* Function: Calculation of the inverse MDCT */
|
---|
1602 | /* */
|
---|
1603 | /*------------------------------------------------------------------*/
|
---|
1604 |
|
---|
1605 | static void dct36(real *inbuf,real *o1,real *o2,real *wintab,real *tsbuf)
|
---|
1606 | {
|
---|
1607 | #ifdef NEW_DCT9
|
---|
1608 | real tmp[18];
|
---|
1609 | #endif
|
---|
1610 |
|
---|
1611 | {
|
---|
1612 | register real *in = inbuf;
|
---|
1613 |
|
---|
1614 | in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14];
|
---|
1615 | in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11];
|
---|
1616 | in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8];
|
---|
1617 | in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5];
|
---|
1618 | in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2];
|
---|
1619 | in[2] +=in[1]; in[1] +=in[0];
|
---|
1620 |
|
---|
1621 | in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9];
|
---|
1622 | in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1];
|
---|
1623 |
|
---|
1624 |
|
---|
1625 | #ifdef NEW_DCT9
|
---|
1626 | {
|
---|
1627 | real t0, t1, t2, t3, t4, t5, t6, t7;
|
---|
1628 |
|
---|
1629 | t1 = COS6_2 * in[12];
|
---|
1630 | t2 = COS6_2 * (in[8] + in[16] - in[4]);
|
---|
1631 |
|
---|
1632 | t3 = in[0] + t1;
|
---|
1633 | t4 = in[0] - t1 - t1;
|
---|
1634 | t5 = t4 - t2;
|
---|
1635 |
|
---|
1636 | t0 = cos9[0] * (in[4] + in[8]);
|
---|
1637 | t1 = cos9[1] * (in[8] - in[16]);
|
---|
1638 |
|
---|
1639 | tmp[4] = t4 + t2 + t2;
|
---|
1640 | t2 = cos9[2] * (in[4] + in[16]);
|
---|
1641 |
|
---|
1642 | t6 = t3 - t0 - t2;
|
---|
1643 | t0 += t3 + t1;
|
---|
1644 | t3 += t2 - t1;
|
---|
1645 |
|
---|
1646 | t2 = cos18[0] * (in[2] + in[10]);
|
---|
1647 | t4 = cos18[1] * (in[10] - in[14]);
|
---|
1648 | t7 = COS6_1 * in[6];
|
---|
1649 |
|
---|
1650 | t1 = t2 + t4 + t7;
|
---|
1651 | tmp[0] = t0 + t1;
|
---|
1652 | tmp[8] = t0 - t1;
|
---|
1653 | t1 = cos18[2] * (in[2] + in[14]);
|
---|
1654 | t2 += t1 - t7;
|
---|
1655 |
|
---|
1656 | tmp[3] = t3 + t2;
|
---|
1657 | t0 = COS6_1 * (in[10] + in[14] - in[2]);
|
---|
1658 | tmp[5] = t3 - t2;
|
---|
1659 |
|
---|
1660 | t4 -= t1 + t7;
|
---|
1661 |
|
---|
1662 | tmp[1] = t5 - t0;
|
---|
1663 | tmp[7] = t5 + t0;
|
---|
1664 | tmp[2] = t6 + t4;
|
---|
1665 | tmp[6] = t6 - t4;
|
---|
1666 | }
|
---|
1667 |
|
---|
1668 | {
|
---|
1669 | real t0, t1, t2, t3, t4, t5, t6, t7;
|
---|
1670 |
|
---|
1671 | t1 = COS6_2 * in[13];
|
---|
1672 | t2 = COS6_2 * (in[9] + in[17] - in[5]);
|
---|
1673 |
|
---|
1674 | t3 = in[1] + t1;
|
---|
1675 | t4 = in[1] - t1 - t1;
|
---|
1676 | t5 = t4 - t2;
|
---|
1677 |
|
---|
1678 | t0 = cos9[0] * (in[5] + in[9]);
|
---|
1679 | t1 = cos9[1] * (in[9] - in[17]);
|
---|
1680 |
|
---|
1681 | tmp[13] = (t4 + t2 + t2) * tfcos36[17-13];
|
---|
1682 | t2 = cos9[2] * (in[5] + in[17]);
|
---|
1683 |
|
---|
1684 | t6 = t3 - t0 - t2;
|
---|
1685 | t0 += t3 + t1;
|
---|
1686 | t3 += t2 - t1;
|
---|
1687 |
|
---|
1688 | t2 = cos18[0] * (in[3] + in[11]);
|
---|
1689 | t4 = cos18[1] * (in[11] - in[15]);
|
---|
1690 | t7 = COS6_1 * in[7];
|
---|
1691 |
|
---|
1692 | t1 = t2 + t4 + t7;
|
---|
1693 | tmp[17] = (t0 + t1) * tfcos36[17-17];
|
---|
1694 | tmp[9] = (t0 - t1) * tfcos36[17-9];
|
---|
1695 | t1 = cos18[2] * (in[3] + in[15]);
|
---|
1696 | t2 += t1 - t7;
|
---|
1697 |
|
---|
1698 | tmp[14] = (t3 + t2) * tfcos36[17-14];
|
---|
1699 | t0 = COS6_1 * (in[11] + in[15] - in[3]);
|
---|
1700 | tmp[12] = (t3 - t2) * tfcos36[17-12];
|
---|
1701 |
|
---|
1702 | t4 -= t1 + t7;
|
---|
1703 |
|
---|
1704 | tmp[16] = (t5 - t0) * tfcos36[17-16];
|
---|
1705 | tmp[10] = (t5 + t0) * tfcos36[17-10];
|
---|
1706 | tmp[15] = (t6 + t4) * tfcos36[17-15];
|
---|
1707 | tmp[11] = (t6 - t4) * tfcos36[17-11];
|
---|
1708 | }
|
---|
1709 |
|
---|
1710 | #define MACRO(v) { \
|
---|
1711 | real tmpval; \
|
---|
1712 | real sum0 = tmp[(v)]; \
|
---|
1713 | real sum1 = tmp[17-(v)]; \
|
---|
1714 | out2[9+(v)] = (tmpval = sum0 + sum1) * w[27+(v)]; \
|
---|
1715 | out2[8-(v)] = tmpval * w[26-(v)]; \
|
---|
1716 | sum0 -= sum1; \
|
---|
1717 | ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \
|
---|
1718 | ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)]; }
|
---|
1719 |
|
---|
1720 | {
|
---|
1721 | register real *out2 = o2;
|
---|
1722 | register real *w = wintab;
|
---|
1723 | register real *out1 = o1;
|
---|
1724 | register real *ts = tsbuf;
|
---|
1725 |
|
---|
1726 | MACRO(0);
|
---|
1727 | MACRO(1);
|
---|
1728 | MACRO(2);
|
---|
1729 | MACRO(3);
|
---|
1730 | MACRO(4);
|
---|
1731 | MACRO(5);
|
---|
1732 | MACRO(6);
|
---|
1733 | MACRO(7);
|
---|
1734 | MACRO(8);
|
---|
1735 | }
|
---|
1736 |
|
---|
1737 | #else
|
---|
1738 |
|
---|
1739 | {
|
---|
1740 |
|
---|
1741 | #define MACRO0(v) { \
|
---|
1742 | real tmp; \
|
---|
1743 | out2[9+(v)] = (tmp = sum0 + sum1) * w[27+(v)]; \
|
---|
1744 | out2[8-(v)] = tmp * w[26-(v)]; } \
|
---|
1745 | sum0 -= sum1; \
|
---|
1746 | ts[SBLIMIT*(8-(v))] = out1[8-(v)] + sum0 * w[8-(v)]; \
|
---|
1747 | ts[SBLIMIT*(9+(v))] = out1[9+(v)] + sum0 * w[9+(v)];
|
---|
1748 | #define MACRO1(v) { \
|
---|
1749 | real sum0,sum1; \
|
---|
1750 | sum0 = tmp1a + tmp2a; \
|
---|
1751 | sum1 = (tmp1b + tmp2b) * tfcos36[(v)]; \
|
---|
1752 | MACRO0(v); }
|
---|
1753 | #define MACRO2(v) { \
|
---|
1754 | real sum0,sum1; \
|
---|
1755 | sum0 = tmp2a - tmp1a; \
|
---|
1756 | sum1 = (tmp2b - tmp1b) * tfcos36[(v)]; \
|
---|
1757 | MACRO0(v); }
|
---|
1758 |
|
---|
1759 | register const real *c = COS9;
|
---|
1760 | register real *out2 = o2;
|
---|
1761 | register real *w = wintab;
|
---|
1762 | register real *out1 = o1;
|
---|
1763 | register real *ts = tsbuf;
|
---|
1764 |
|
---|
1765 | real ta33,ta66,tb33,tb66;
|
---|
1766 |
|
---|
1767 | ta33 = in[2*3+0] * c[3];
|
---|
1768 | ta66 = in[2*6+0] * c[6];
|
---|
1769 | tb33 = in[2*3+1] * c[3];
|
---|
1770 | tb66 = in[2*6+1] * c[6];
|
---|
1771 |
|
---|
1772 | {
|
---|
1773 | real tmp1a,tmp2a,tmp1b,tmp2b;
|
---|
1774 | tmp1a = in[2*1+0] * c[1] + ta33 + in[2*5+0] * c[5] + in[2*7+0] * c[7];
|
---|
1775 | tmp1b = in[2*1+1] * c[1] + tb33 + in[2*5+1] * c[5] + in[2*7+1] * c[7];
|
---|
1776 | tmp2a = in[2*0+0] + in[2*2+0] * c[2] + in[2*4+0] * c[4] + ta66 + in[2*8+0] * c[8];
|
---|
1777 | tmp2b = in[2*0+1] + in[2*2+1] * c[2] + in[2*4+1] * c[4] + tb66 + in[2*8+1] * c[8];
|
---|
1778 |
|
---|
1779 | MACRO1(0);
|
---|
1780 | MACRO2(8);
|
---|
1781 | }
|
---|
1782 |
|
---|
1783 | {
|
---|
1784 | real tmp1a,tmp2a,tmp1b,tmp2b;
|
---|
1785 | tmp1a = ( in[2*1+0] - in[2*5+0] - in[2*7+0] ) * c[3];
|
---|
1786 | tmp1b = ( in[2*1+1] - in[2*5+1] - in[2*7+1] ) * c[3];
|
---|
1787 | tmp2a = ( in[2*2+0] - in[2*4+0] - in[2*8+0] ) * c[6] - in[2*6+0] + in[2*0+0];
|
---|
1788 | tmp2b = ( in[2*2+1] - in[2*4+1] - in[2*8+1] ) * c[6] - in[2*6+1] + in[2*0+1];
|
---|
1789 |
|
---|
1790 | MACRO1(1);
|
---|
1791 | MACRO2(7);
|
---|
1792 | }
|
---|
1793 |
|
---|
1794 | {
|
---|
1795 | real tmp1a,tmp2a,tmp1b,tmp2b;
|
---|
1796 | tmp1a = in[2*1+0] * c[5] - ta33 - in[2*5+0] * c[7] + in[2*7+0] * c[1];
|
---|
1797 | tmp1b = in[2*1+1] * c[5] - tb33 - in[2*5+1] * c[7] + in[2*7+1] * c[1];
|
---|
1798 | tmp2a = in[2*0+0] - in[2*2+0] * c[8] - in[2*4+0] * c[2] + ta66 + in[2*8+0] * c[4];
|
---|
1799 | tmp2b = in[2*0+1] - in[2*2+1] * c[8] - in[2*4+1] * c[2] + tb66 + in[2*8+1] * c[4];
|
---|
1800 |
|
---|
1801 | MACRO1(2);
|
---|
1802 | MACRO2(6);
|
---|
1803 | }
|
---|
1804 |
|
---|
1805 | {
|
---|
1806 | real tmp1a,tmp2a,tmp1b,tmp2b;
|
---|
1807 | tmp1a = in[2*1+0] * c[7] - ta33 + in[2*5+0] * c[1] - in[2*7+0] * c[5];
|
---|
1808 | tmp1b = in[2*1+1] * c[7] - tb33 + in[2*5+1] * c[1] - in[2*7+1] * c[5];
|
---|
1809 | tmp2a = in[2*0+0] - in[2*2+0] * c[4] + in[2*4+0] * c[8] + ta66 - in[2*8+0] * c[2];
|
---|
1810 | tmp2b = in[2*0+1] - in[2*2+1] * c[4] + in[2*4+1] * c[8] + tb66 - in[2*8+1] * c[2];
|
---|
1811 |
|
---|
1812 | MACRO1(3);
|
---|
1813 | MACRO2(5);
|
---|
1814 | }
|
---|
1815 |
|
---|
1816 | {
|
---|
1817 | real sum0,sum1;
|
---|
1818 | sum0 = in[2*0+0] - in[2*2+0] + in[2*4+0] - in[2*6+0] + in[2*8+0];
|
---|
1819 | sum1 = (in[2*0+1] - in[2*2+1] + in[2*4+1] - in[2*6+1] + in[2*8+1] ) * tfcos36[4];
|
---|
1820 | MACRO0(4);
|
---|
1821 | }
|
---|
1822 | }
|
---|
1823 | #endif
|
---|
1824 |
|
---|
1825 | }
|
---|
1826 | }
|
---|
1827 |
|
---|
1828 | /*
|
---|
1829 | * new DCT12
|
---|
1830 | */
|
---|
1831 | static void dct12(real *in,real *rawout1,real *rawout2,register real *wi,register real *ts)
|
---|
1832 | {
|
---|
1833 | #define DCT12_PART1 \
|
---|
1834 | in5 = in[5*3]; \
|
---|
1835 | in5 += (in4 = in[4*3]); \
|
---|
1836 | in4 += (in3 = in[3*3]); \
|
---|
1837 | in3 += (in2 = in[2*3]); \
|
---|
1838 | in2 += (in1 = in[1*3]); \
|
---|
1839 | in1 += (in0 = in[0*3]); \
|
---|
1840 | \
|
---|
1841 | in5 += in3; in3 += in1; \
|
---|
1842 | \
|
---|
1843 | in2 *= COS6_1; \
|
---|
1844 | in3 *= COS6_1; \
|
---|
1845 |
|
---|
1846 | #define DCT12_PART2 \
|
---|
1847 | in0 += in4 * COS6_2; \
|
---|
1848 | \
|
---|
1849 | in4 = in0 + in2; \
|
---|
1850 | in0 -= in2; \
|
---|
1851 | \
|
---|
1852 | in1 += in5 * COS6_2; \
|
---|
1853 | \
|
---|
1854 | in5 = (in1 + in3) * tfcos12[0]; \
|
---|
1855 | in1 = (in1 - in3) * tfcos12[2]; \
|
---|
1856 | \
|
---|
1857 | in3 = in4 + in5; \
|
---|
1858 | in4 -= in5; \
|
---|
1859 | \
|
---|
1860 | in2 = in0 + in1; \
|
---|
1861 | in0 -= in1;
|
---|
1862 |
|
---|
1863 |
|
---|
1864 | {
|
---|
1865 | real in0,in1,in2,in3,in4,in5;
|
---|
1866 | register real *out1 = rawout1;
|
---|
1867 | ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2];
|
---|
1868 | ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5];
|
---|
1869 |
|
---|
1870 | DCT12_PART1
|
---|
1871 |
|
---|
1872 | {
|
---|
1873 | real tmp0,tmp1 = (in0 - in4);
|
---|
1874 | {
|
---|
1875 | real tmp2 = (in1 - in5) * tfcos12[1];
|
---|
1876 | tmp0 = tmp1 + tmp2;
|
---|
1877 | tmp1 -= tmp2;
|
---|
1878 | }
|
---|
1879 | ts[(17-1)*SBLIMIT] = out1[17-1] + tmp0 * wi[11-1];
|
---|
1880 | ts[(12+1)*SBLIMIT] = out1[12+1] + tmp0 * wi[6+1];
|
---|
1881 | ts[(6 +1)*SBLIMIT] = out1[6 +1] + tmp1 * wi[1];
|
---|
1882 | ts[(11-1)*SBLIMIT] = out1[11-1] + tmp1 * wi[5-1];
|
---|
1883 | }
|
---|
1884 |
|
---|
1885 | DCT12_PART2
|
---|
1886 |
|
---|
1887 | ts[(17-0)*SBLIMIT] = out1[17-0] + in2 * wi[11-0];
|
---|
1888 | ts[(12+0)*SBLIMIT] = out1[12+0] + in2 * wi[6+0];
|
---|
1889 | ts[(12+2)*SBLIMIT] = out1[12+2] + in3 * wi[6+2];
|
---|
1890 | ts[(17-2)*SBLIMIT] = out1[17-2] + in3 * wi[11-2];
|
---|
1891 |
|
---|
1892 | ts[(6+0)*SBLIMIT] = out1[6+0] + in0 * wi[0];
|
---|
1893 | ts[(11-0)*SBLIMIT] = out1[11-0] + in0 * wi[5-0];
|
---|
1894 | ts[(6+2)*SBLIMIT] = out1[6+2] + in4 * wi[2];
|
---|
1895 | ts[(11-2)*SBLIMIT] = out1[11-2] + in4 * wi[5-2];
|
---|
1896 | }
|
---|
1897 |
|
---|
1898 | in++;
|
---|
1899 |
|
---|
1900 | {
|
---|
1901 | real in0,in1,in2,in3,in4,in5;
|
---|
1902 | register real *out2 = rawout2;
|
---|
1903 |
|
---|
1904 | DCT12_PART1
|
---|
1905 |
|
---|
1906 | {
|
---|
1907 | real tmp0,tmp1 = (in0 - in4);
|
---|
1908 | {
|
---|
1909 | real tmp2 = (in1 - in5) * tfcos12[1];
|
---|
1910 | tmp0 = tmp1 + tmp2;
|
---|
1911 | tmp1 -= tmp2;
|
---|
1912 | }
|
---|
1913 | out2[5-1] = tmp0 * wi[11-1];
|
---|
1914 | out2[0+1] = tmp0 * wi[6+1];
|
---|
1915 | ts[(12+1)*SBLIMIT] += tmp1 * wi[1];
|
---|
1916 | ts[(17-1)*SBLIMIT] += tmp1 * wi[5-1];
|
---|
1917 | }
|
---|
1918 |
|
---|
1919 | DCT12_PART2
|
---|
1920 |
|
---|
1921 | out2[5-0] = in2 * wi[11-0];
|
---|
1922 | out2[0+0] = in2 * wi[6+0];
|
---|
1923 | out2[0+2] = in3 * wi[6+2];
|
---|
1924 | out2[5-2] = in3 * wi[11-2];
|
---|
1925 |
|
---|
1926 | ts[(12+0)*SBLIMIT] += in0 * wi[0];
|
---|
1927 | ts[(17-0)*SBLIMIT] += in0 * wi[5-0];
|
---|
1928 | ts[(12+2)*SBLIMIT] += in4 * wi[2];
|
---|
1929 | ts[(17-2)*SBLIMIT] += in4 * wi[5-2];
|
---|
1930 | }
|
---|
1931 |
|
---|
1932 | in++;
|
---|
1933 |
|
---|
1934 | {
|
---|
1935 | real in0,in1,in2,in3,in4,in5;
|
---|
1936 | register real *out2 = rawout2;
|
---|
1937 | out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0;
|
---|
1938 |
|
---|
1939 | DCT12_PART1
|
---|
1940 |
|
---|
1941 | {
|
---|
1942 | real tmp0,tmp1 = (in0 - in4);
|
---|
1943 | {
|
---|
1944 | real tmp2 = (in1 - in5) * tfcos12[1];
|
---|
1945 | tmp0 = tmp1 + tmp2;
|
---|
1946 | tmp1 -= tmp2;
|
---|
1947 | }
|
---|
1948 | out2[11-1] = tmp0 * wi[11-1];
|
---|
1949 | out2[6 +1] = tmp0 * wi[6+1];
|
---|
1950 | out2[0+1] += tmp1 * wi[1];
|
---|
1951 | out2[5-1] += tmp1 * wi[5-1];
|
---|
1952 | }
|
---|
1953 |
|
---|
1954 | DCT12_PART2
|
---|
1955 |
|
---|
1956 | out2[11-0] = in2 * wi[11-0];
|
---|
1957 | out2[6 +0] = in2 * wi[6+0];
|
---|
1958 | out2[6 +2] = in3 * wi[6+2];
|
---|
1959 | out2[11-2] = in3 * wi[11-2];
|
---|
1960 |
|
---|
1961 | out2[0+0] += in0 * wi[0];
|
---|
1962 | out2[5-0] += in0 * wi[5-0];
|
---|
1963 | out2[0+2] += in4 * wi[2];
|
---|
1964 | out2[5-2] += in4 * wi[5-2];
|
---|
1965 | }
|
---|
1966 | }
|
---|
1967 |
|
---|
1968 | /*
|
---|
1969 | * III_hybrid
|
---|
1970 | */
|
---|
1971 | static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT],
|
---|
1972 | int ch, III_sideinfo::what_the::gr_info_s *gr_info)
|
---|
1973 | {
|
---|
1974 | real *tspnt = (real *) tsOut;
|
---|
1975 | real *rawout1,*rawout2;
|
---|
1976 | int bt;
|
---|
1977 | unsigned int sb = 0;
|
---|
1978 |
|
---|
1979 | {
|
---|
1980 | int b = blc[ch];
|
---|
1981 | rawout1=block[b][ch];
|
---|
1982 | b=-b+1;
|
---|
1983 | rawout2=block[b][ch];
|
---|
1984 | blc[ch] = b;
|
---|
1985 | }
|
---|
1986 |
|
---|
1987 |
|
---|
1988 | if(gr_info->mixed_block_flag) {
|
---|
1989 | sb = 2;
|
---|
1990 | dct36(fsIn[0],rawout1,rawout2,win[0],tspnt);
|
---|
1991 | dct36(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1);
|
---|
1992 | rawout1 += 36; rawout2 += 36; tspnt += 2;
|
---|
1993 | }
|
---|
1994 |
|
---|
1995 | bt = gr_info->block_type;
|
---|
1996 | if(bt == 2) {
|
---|
1997 | for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
|
---|
1998 | dct12(fsIn[sb],rawout1,rawout2,win[2],tspnt);
|
---|
1999 | dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1);
|
---|
2000 | }
|
---|
2001 | }
|
---|
2002 | else {
|
---|
2003 | for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
|
---|
2004 | dct36(fsIn[sb],rawout1,rawout2,win[bt],tspnt);
|
---|
2005 | dct36(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1);
|
---|
2006 | }
|
---|
2007 | }
|
---|
2008 |
|
---|
2009 | for(;sb<SBLIMIT;sb++,tspnt++) {
|
---|
2010 | int i;
|
---|
2011 | for(i=0;i<SSLIMIT;i++) {
|
---|
2012 | tspnt[i*SBLIMIT] = *rawout1++;
|
---|
2013 | *rawout2++ = 0.0;
|
---|
2014 | }
|
---|
2015 | }
|
---|
2016 | }
|
---|
2017 |
|
---|
2018 | /*
|
---|
2019 | * main layer3 handler
|
---|
2020 | */
|
---|
2021 | int do_layer3(struct frame *fr,int outmode,struct audio_info_struct *ai)
|
---|
2022 | {
|
---|
2023 | int gr, ch, ss,clip=0;
|
---|
2024 | int scalefacs[39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
|
---|
2025 | struct III_sideinfo sideinfo;
|
---|
2026 | int stereo = fr->stereo;
|
---|
2027 | int single = fr->single;
|
---|
2028 | int ms_stereo,i_stereo;
|
---|
2029 | int sfreq = fr->sampling_frequency;
|
---|
2030 | int stereo1,granules;
|
---|
2031 |
|
---|
2032 | if(stereo == 1) {
|
---|
2033 | stereo1 = 1;
|
---|
2034 | single = 0;
|
---|
2035 | }
|
---|
2036 | else if(single >= 0)
|
---|
2037 | stereo1 = 1;
|
---|
2038 | else
|
---|
2039 | stereo1 = 2;
|
---|
2040 |
|
---|
2041 | ms_stereo = (fr->mode == MPG_MD_JOINT_STEREO) && (fr->mode_ext & 0x2);
|
---|
2042 | i_stereo = (fr->mode == MPG_MD_JOINT_STEREO) && (fr->mode_ext & 0x1);
|
---|
2043 |
|
---|
2044 | if(fr->lsf) {
|
---|
2045 | granules = 1;
|
---|
2046 | III_get_side_info_2(&sideinfo,stereo,ms_stereo,sfreq,single);
|
---|
2047 | }
|
---|
2048 | else {
|
---|
2049 | granules = 2;
|
---|
2050 | III_get_side_info_1(&sideinfo,stereo,ms_stereo,sfreq,single);
|
---|
2051 | }
|
---|
2052 |
|
---|
2053 | set_pointer(sideinfo.main_data_begin);
|
---|
2054 |
|
---|
2055 | for (gr=0;gr<granules;gr++)
|
---|
2056 | {
|
---|
2057 | static real hybridIn[2][SBLIMIT][SSLIMIT];
|
---|
2058 | static real hybridOut[2][SSLIMIT][SBLIMIT];
|
---|
2059 |
|
---|
2060 | {
|
---|
2061 | III_sideinfo::what_the::gr_info_s *gr_info = (III_sideinfo::what_the::gr_info_s *)&(sideinfo.ch[0].gr[gr]);
|
---|
2062 | long part2bits;
|
---|
2063 | if(fr->lsf)
|
---|
2064 | part2bits = III_get_scale_factors_2(scalefacs,gr_info,0);
|
---|
2065 | else
|
---|
2066 | part2bits = III_get_scale_factors_1(scalefacs,gr_info);
|
---|
2067 | if(III_dequantize_sample(hybridIn[0], scalefacs,gr_info,sfreq,part2bits))
|
---|
2068 | return clip;
|
---|
2069 | }
|
---|
2070 | if(stereo == 2)
|
---|
2071 | {
|
---|
2072 | III_sideinfo::what_the::gr_info_s *gr_info = (III_sideinfo::what_the::gr_info_s *)&(sideinfo.ch[1].gr[gr]);
|
---|
2073 | long part2bits;
|
---|
2074 | if(fr->lsf)
|
---|
2075 | part2bits = III_get_scale_factors_2(scalefacs,gr_info,i_stereo);
|
---|
2076 | else
|
---|
2077 | part2bits = III_get_scale_factors_1(scalefacs,gr_info);
|
---|
2078 | if(ms_stereo) {
|
---|
2079 | if(III_dequantize_sample_ms(hybridIn,scalefacs,gr_info,sfreq,part2bits))
|
---|
2080 | return clip;
|
---|
2081 | }
|
---|
2082 | else {
|
---|
2083 | if(III_dequantize_sample(hybridIn[1],scalefacs,gr_info,sfreq,part2bits))
|
---|
2084 | return clip;
|
---|
2085 | }
|
---|
2086 |
|
---|
2087 | if(i_stereo)
|
---|
2088 | III_i_stereo(hybridIn,scalefacs,gr_info,sfreq,ms_stereo,fr->lsf);
|
---|
2089 |
|
---|
2090 |
|
---|
2091 | if(ms_stereo || i_stereo || (single == 3) ) {
|
---|
2092 | if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb)
|
---|
2093 | sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
|
---|
2094 | else
|
---|
2095 | gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
|
---|
2096 | }
|
---|
2097 |
|
---|
2098 | switch(single) {
|
---|
2099 | case 3:
|
---|
2100 | {
|
---|
2101 | unsigned int i;
|
---|
2102 | register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
|
---|
2103 | for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++)
|
---|
2104 | *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */
|
---|
2105 | }
|
---|
2106 | break;
|
---|
2107 | case 1:
|
---|
2108 | {
|
---|
2109 | unsigned int i;
|
---|
2110 | register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
|
---|
2111 | for(i=0;i<SSLIMIT*gr_info->maxb;i++)
|
---|
2112 | *in0++ = *in1++;
|
---|
2113 | }
|
---|
2114 | break;
|
---|
2115 | }
|
---|
2116 | }
|
---|
2117 |
|
---|
2118 | for(ch=0;ch<stereo1;ch++) {
|
---|
2119 | III_sideinfo::what_the::gr_info_s *gr_info = (III_sideinfo::what_the::gr_info_s *)&(sideinfo.ch[ch].gr[gr]);
|
---|
2120 | III_antialias(hybridIn[ch],gr_info);
|
---|
2121 | III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info);
|
---|
2122 | }
|
---|
2123 |
|
---|
2124 | for(ss=0;ss<SSLIMIT;ss++) {
|
---|
2125 | if(single >= 0) {
|
---|
2126 | clip += (fr->synth_mono)(hybridOut[0][ss],pcm_sample+pcm_point);
|
---|
2127 | }
|
---|
2128 | else {
|
---|
2129 | clip += (fr->synth)(hybridOut[0][ss],0,pcm_sample+pcm_point);
|
---|
2130 | clip += (fr->synth)(hybridOut[1][ss],1,pcm_sample+pcm_point);
|
---|
2131 | }
|
---|
2132 | pcm_point += fr->block_size;
|
---|
2133 |
|
---|
2134 | #ifdef VARMODESUPPORT
|
---|
2135 | if (playlimit < 128) {
|
---|
2136 | pcm_point -= playlimit >> 1;
|
---|
2137 | playlimit = 0;
|
---|
2138 | }
|
---|
2139 | else
|
---|
2140 | playlimit -= 128;
|
---|
2141 | #endif
|
---|
2142 |
|
---|
2143 | if(pcm_point >= audiobufsize)
|
---|
2144 | audio_flush(outmode,ai);
|
---|
2145 | }
|
---|
2146 | }
|
---|
2147 |
|
---|
2148 | return clip;
|
---|
2149 | }
|
---|
2150 |
|
---|
2151 |
|
---|