/src/mpg123/src/libmpg123/layer3.c
Line | Count | Source |
1 | | /* |
2 | | layer3.c: the layer 3 decoder |
3 | | |
4 | | copyright 1995-2021 by the mpg123 project - free software under the terms of the LGPL 2.1 |
5 | | see COPYING and AUTHORS files in distribution or http://mpg123.org |
6 | | initially written by Michael Hipp |
7 | | |
8 | | Dear visitor: |
9 | | If you feel you don't understand fully the works of this file, your feeling might be correct. |
10 | | |
11 | | Optimize-TODO: put short bands into the band-field without the stride of 3 reals |
12 | | Length-optimze: unify long and short band code where it is possible |
13 | | |
14 | | The int-vs-pointer situation has to be cleaned up. |
15 | | */ |
16 | | |
17 | | #include "mpg123lib_intern.h" |
18 | | #ifdef USE_NEW_HUFFTABLE |
19 | | #include "newhuffman.h" |
20 | | #else |
21 | | #include "huffman.h" |
22 | | #endif |
23 | | #include "getbits.h" |
24 | | #include "../common/debug.h" |
25 | | |
26 | | |
27 | | /* Predeclare the assembly routines, only called from wrappers here. */ |
28 | | void INT123_dct36_3dnow (real *,real *,real *,const real *,real *); |
29 | | void INT123_dct36_3dnowext(real *,real *,real *,const real *,real *); |
30 | | void INT123_dct36_x86_64 (real *,real *,real *,const real *,real *); |
31 | | void INT123_dct36_sse (real *,real *,real *,const real *,real *); |
32 | | void INT123_dct36_avx (real *,real *,real *,const real *,real *); |
33 | | void INT123_dct36_neon (real *,real *,real *,const real *,real *); |
34 | | void INT123_dct36_neon64 (real *,real *,real *,const real *,real *); |
35 | | |
36 | | /* define CUT_SFB21 if you want to cut-off the frequency above 16kHz */ |
37 | | #if 0 |
38 | | #define CUT_SFB21 |
39 | | #endif |
40 | | |
41 | | #include "l3tabs.h" |
42 | | #include "l3bandgain.h" |
43 | | |
44 | | #ifdef RUNTIME_TABLES |
45 | | #include "init_layer3.h" |
46 | | #endif |
47 | | |
48 | | /* Decoder state data, living on the stack of INT123_do_layer3. */ |
49 | | |
50 | | struct gr_info_s |
51 | | { |
52 | | int scfsi; |
53 | | unsigned part2_3_length; |
54 | | unsigned big_values; |
55 | | unsigned scalefac_compress; |
56 | | unsigned block_type; |
57 | | unsigned mixed_block_flag; |
58 | | unsigned table_select[3]; |
59 | | /* Making those two signed int as workaround for open64/pathscale/sun compilers, and also for consistency, since they're worked on together with other signed variables. */ |
60 | | int maxband[3]; |
61 | | int maxbandl; |
62 | | unsigned maxb; |
63 | | unsigned region1start; |
64 | | unsigned region2start; |
65 | | unsigned preflag; |
66 | | unsigned scalefac_scale; |
67 | | unsigned count1table_select; |
68 | | #ifdef REAL_IS_FIXED |
69 | | const real *full_gain[3]; |
70 | | const real *pow2gain; |
71 | | #else |
72 | | real *full_gain[3]; |
73 | | real *pow2gain; |
74 | | #endif |
75 | | }; |
76 | | |
77 | | struct III_sideinfo |
78 | | { |
79 | | unsigned main_data_begin; |
80 | | unsigned private_bits; |
81 | | /* Hm, funny... struct inside struct... */ |
82 | | struct { struct gr_info_s gr[2]; } ch[2]; |
83 | | }; |
84 | | |
85 | | #ifdef OPT_MMXORSSE |
86 | | real INT123_init_layer3_gainpow2_mmx(mpg123_handle *fr, int i) |
87 | 0 | { |
88 | 0 | if(!fr->p.down_sample) return DOUBLE_TO_REAL(16384.0 * pow((double)2.0,-0.25 * (double) (i+210) )); |
89 | 0 | else return DOUBLE_TO_REAL(pow((double)2.0,-0.25 * (double) (i+210))); |
90 | 0 | } |
91 | | #endif |
92 | | |
93 | | real INT123_init_layer3_gainpow2(mpg123_handle *fr, int i) |
94 | 223M | { |
95 | 223M | return DOUBLE_TO_REAL_SCALE_LAYER3(pow((double)2.0,-0.25 * (double) (i+210)),i+256); |
96 | 223M | } |
97 | | |
98 | | void INT123_init_layer3_stuff(mpg123_handle *fr, real (*gainpow2_func)(mpg123_handle *fr, int i)) |
99 | 592k | { |
100 | 592k | int i,j; |
101 | | |
102 | | #ifdef REAL_IS_FIXED |
103 | | fr->gainpow2 = gainpow2; |
104 | | #else |
105 | 224M | for(i=-256;i<118+4;i++) |
106 | 223M | fr->gainpow2[i+256] = gainpow2_func(fr,i); |
107 | 592k | #endif |
108 | | |
109 | 5.92M | for(j=0;j<9;j++) |
110 | 5.33M | { |
111 | 127M | for(i=0;i<23;i++) |
112 | 122M | { |
113 | 122M | fr->longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1; |
114 | 122M | if(fr->longLimit[j][i] > (fr->down_sample_sblimit) ) |
115 | 7.10M | fr->longLimit[j][i] = fr->down_sample_sblimit; |
116 | 122M | } |
117 | 79.9M | for(i=0;i<14;i++) |
118 | 74.6M | { |
119 | 74.6M | fr->shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1; |
120 | 74.6M | if(fr->shortLimit[j][i] > (fr->down_sample_sblimit) ) |
121 | 0 | fr->shortLimit[j][i] = fr->down_sample_sblimit; |
122 | 74.6M | } |
123 | 5.33M | } |
124 | 592k | } |
125 | | |
126 | | /* |
127 | | Observe! |
128 | | Now come the actualy decoding routines. |
129 | | */ |
130 | | |
131 | | /* read additional side information (for MPEG 1 and MPEG 2) */ |
132 | | static int III_get_side_info(mpg123_handle *fr, struct III_sideinfo *si,int stereo, int ms_stereo,long sfreq,int single) |
133 | 83.6k | { |
134 | 83.6k | int ch, gr; |
135 | 83.6k | int powdiff = (single == SINGLE_MIX) ? 4 : 0; |
136 | | |
137 | 83.6k | const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } }; |
138 | 83.6k | const int *tab = tabs[fr->hdr.lsf]; |
139 | | |
140 | 83.6k | { /* First ensure we got enough bits available. */ |
141 | 83.6k | unsigned int needbits = 0; |
142 | 83.6k | needbits += tab[1]; /* main_data_begin */ |
143 | 83.6k | needbits += stereo == 1 ? tab[2] : tab[3]; /* private */ |
144 | 83.6k | if(!fr->hdr.lsf) |
145 | 23.4k | needbits += stereo*4; /* scfsi */ |
146 | | /* For each granule for each channel ... */ |
147 | 83.6k | needbits += tab[0]*stereo*(29+tab[4]+1+22+(!fr->hdr.lsf?1:0)+2); |
148 | 83.6k | if(fr->bits_avail < needbits) \ |
149 | 0 | { |
150 | 0 | if(NOQUIET) |
151 | 0 | error2( "%u bits for side info needed, only %li available" |
152 | 0 | , needbits, fr->bits_avail ); |
153 | 0 | return 1; |
154 | 0 | } |
155 | 83.6k | } |
156 | | |
157 | 83.6k | si->main_data_begin = getbits(fr, tab[1]); |
158 | | |
159 | 83.6k | if(si->main_data_begin > fr->bitreservoir) |
160 | 16.0k | { |
161 | 16.0k | if(!fr->to_ignore && VERBOSE2) fprintf(stderr, "Note: missing %d bytes in bit reservoir for frame %li\n", (int)(si->main_data_begin - fr->bitreservoir), (long)fr->num); |
162 | | |
163 | | /* overwrite main_data_begin for the really available bit reservoir */ |
164 | 16.0k | backbits(fr, tab[1]); |
165 | 16.0k | if(fr->hdr.lsf == 0) |
166 | 4.65k | { |
167 | 4.65k | fr->wordpointer[0] = (unsigned char) (fr->bitreservoir >> 1); |
168 | 4.65k | fr->wordpointer[1] = (unsigned char) ((fr->bitreservoir & 1) << 7); |
169 | 4.65k | } |
170 | 11.4k | else fr->wordpointer[0] = (unsigned char) fr->bitreservoir; |
171 | | |
172 | | /* zero "side-info" data for a silence-frame |
173 | | without touching audio data used as bit reservoir for following frame */ |
174 | 16.0k | memset(fr->wordpointer+2, 0, fr->hdr.ssize-2); |
175 | | |
176 | | /* reread the new bit reservoir offset */ |
177 | 16.0k | si->main_data_begin = getbits(fr, tab[1]); |
178 | 16.0k | } |
179 | | |
180 | | /* Keep track of the available data bytes for the bit reservoir. |
181 | | CRC is included in ssize already. */ |
182 | 83.6k | fr->bitreservoir = fr->bitreservoir + fr->hdr.framesize - fr->hdr.ssize; |
183 | | |
184 | | /* Limit the reservoir to the max for MPEG 1.0 or 2.x . */ |
185 | 83.6k | if(fr->bitreservoir > (unsigned int) (fr->hdr.lsf == 0 ? 511 : 255)) |
186 | 1.89k | fr->bitreservoir = (fr->hdr.lsf == 0 ? 511 : 255); |
187 | | |
188 | | /* Now back into less commented territory. It's code. It works. */ |
189 | | |
190 | 83.6k | if (stereo == 1) |
191 | 26.9k | si->private_bits = getbits(fr, tab[2]); |
192 | 56.6k | else |
193 | 56.6k | si->private_bits = getbits(fr, tab[3]); |
194 | | |
195 | 83.6k | if(!fr->hdr.lsf) for(ch=0; ch<stereo; ch++) |
196 | 34.8k | { |
197 | 34.8k | si->ch[ch].gr[0].scfsi = -1; |
198 | 34.8k | si->ch[ch].gr[1].scfsi = getbits(fr, 4); |
199 | 34.8k | } |
200 | | |
201 | 186k | for (gr=0; gr<tab[0]; gr++) |
202 | 277k | for (ch=0; ch<stereo; ch++) |
203 | 174k | { |
204 | 174k | register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]); |
205 | 174k | unsigned int qss; |
206 | 174k | gr_info->part2_3_length = getbits(fr, 12); |
207 | 174k | gr_info->big_values = getbits(fr, 9); |
208 | 174k | if(gr_info->big_values > 288) |
209 | 27.1k | { |
210 | 27.1k | if(NOQUIET) error("big_values too large!"); |
211 | 27.1k | gr_info->big_values = 288; |
212 | 27.1k | } |
213 | 174k | qss = getbits_fast(fr, 8); |
214 | 174k | gr_info->pow2gain = fr->gainpow2+256 - qss + powdiff; |
215 | 174k | if(ms_stereo) |
216 | 31.1k | gr_info->pow2gain += 2; |
217 | 174k | #ifndef NO_MOREINFO |
218 | 174k | if(fr->pinfo) |
219 | 0 | fr->pinfo->qss[gr][ch] = qss; |
220 | 174k | #endif |
221 | 174k | gr_info->scalefac_compress = getbits(fr, tab[4]); |
222 | 174k | if(gr_info->part2_3_length == 0) |
223 | 78.8k | { |
224 | 78.8k | if(gr_info->scalefac_compress > 0 && VERBOSE2) |
225 | 78.8k | error1( "scalefac_compress should be zero instead of %i" |
226 | 78.8k | , gr_info->scalefac_compress ); |
227 | 78.8k | gr_info->scalefac_compress = 0; |
228 | 78.8k | } |
229 | | |
230 | | /* 22 bits for if/else block */ |
231 | 174k | if(getbits(fr,1)) |
232 | 74.3k | { /* window switch flag */ |
233 | 74.3k | int i; |
234 | 74.3k | gr_info->block_type = getbits_fast(fr, 2); |
235 | 74.3k | gr_info->mixed_block_flag = get1bit(fr); |
236 | 74.3k | gr_info->table_select[0] = getbits_fast(fr, 5); |
237 | 74.3k | gr_info->table_select[1] = getbits_fast(fr, 5); |
238 | | /* |
239 | | table_select[2] not needed, because there is no region2, |
240 | | but to satisfy some verification tools we set it either. |
241 | | */ |
242 | 74.3k | gr_info->table_select[2] = 0; |
243 | 297k | for(i=0;i<3;i++) |
244 | 223k | { |
245 | 223k | unsigned int sbg = (getbits_fast(fr, 3)<<3); |
246 | 223k | gr_info->full_gain[i] = gr_info->pow2gain + sbg; |
247 | 223k | #ifndef NO_MOREINFO |
248 | 223k | if(fr->pinfo) |
249 | 0 | fr->pinfo->sub_gain[gr][ch][i] = sbg / 8; |
250 | 223k | #endif |
251 | 223k | } |
252 | | |
253 | 74.3k | if(gr_info->block_type == 0) |
254 | 3.54k | { |
255 | 3.54k | if(NOQUIET) error("Blocktype == 0 and window-switching == 1 not allowed."); |
256 | 3.54k | return 1; |
257 | 3.54k | } |
258 | | |
259 | | /* region_count/start parameters are implicit in this case. */ |
260 | 70.8k | if( (!fr->hdr.lsf || (gr_info->block_type == 2)) && !fr->hdr.mpeg25) |
261 | 54.1k | { |
262 | 54.1k | gr_info->region1start = 36>>1; |
263 | 54.1k | gr_info->region2start = 576>>1; |
264 | 54.1k | } |
265 | 16.6k | else |
266 | 16.6k | { |
267 | 16.6k | if(fr->hdr.mpeg25) |
268 | 11.4k | { |
269 | 11.4k | int r0c,r1c; |
270 | 11.4k | if((gr_info->block_type == 2) && (!gr_info->mixed_block_flag) ) r0c = 5; |
271 | 7.54k | else r0c = 7; |
272 | | |
273 | | /* r0c+1+r1c+1 == 22, always. */ |
274 | 11.4k | r1c = 20 - r0c; |
275 | 11.4k | gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; |
276 | 11.4k | gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; |
277 | 11.4k | } |
278 | 5.20k | else |
279 | 5.20k | { |
280 | 5.20k | gr_info->region1start = 54>>1; |
281 | 5.20k | gr_info->region2start = 576>>1; |
282 | 5.20k | } |
283 | 16.6k | } |
284 | 70.8k | } |
285 | 99.6k | else |
286 | 99.6k | { |
287 | 99.6k | int i,r0c,r1c; |
288 | 398k | for (i=0; i<3; i++) |
289 | 299k | gr_info->table_select[i] = getbits_fast(fr, 5); |
290 | | |
291 | 99.6k | r0c = getbits_fast(fr, 4); /* 0 .. 15 */ |
292 | 99.6k | r1c = getbits_fast(fr, 3); /* 0 .. 7 */ |
293 | 99.6k | gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ; |
294 | | |
295 | | /* max(r0c+r1c+2) = 15+7+2 = 24 */ |
296 | 99.6k | if(r0c+1+r1c+1 > 22) gr_info->region2start = 576>>1; |
297 | 94.7k | else gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1; |
298 | | |
299 | 99.6k | gr_info->block_type = 0; |
300 | 99.6k | gr_info->mixed_block_flag = 0; |
301 | 99.6k | } |
302 | 170k | if(!fr->hdr.lsf) gr_info->preflag = get1bit(fr); |
303 | | |
304 | 170k | gr_info->scalefac_scale = get1bit(fr); |
305 | 170k | gr_info->count1table_select = get1bit(fr); |
306 | 170k | } |
307 | 80.0k | return 0; |
308 | 83.6k | } |
309 | | |
310 | | |
311 | | /* read scalefactors */ |
312 | | static int III_get_scale_factors_1(mpg123_handle *fr, int *scf,struct gr_info_s *gr_info,int ch,int gr) |
313 | 54.0k | { |
314 | 54.0k | const unsigned char slen[2][16] = |
315 | 54.0k | { |
316 | 54.0k | {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4}, |
317 | 54.0k | {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3} |
318 | 54.0k | }; |
319 | 54.0k | int numbits; |
320 | 54.0k | int num0 = slen[0][gr_info->scalefac_compress]; |
321 | 54.0k | int num1 = slen[1][gr_info->scalefac_compress]; |
322 | | |
323 | 54.0k | if(gr_info->block_type == 2) |
324 | 21.8k | { |
325 | 21.8k | int i=18; |
326 | 21.8k | numbits = (num0 + num1) * 18 /* num0 * (17+1?) + num1 * 18 */ |
327 | 21.8k | - (gr_info->mixed_block_flag ? num0 : 0); |
328 | 21.8k | if(fr->bits_avail < numbits) |
329 | 1.45k | return -1; |
330 | | |
331 | 20.3k | if(gr_info->mixed_block_flag) |
332 | 15.0k | { |
333 | 135k | for (i=8;i;i--) |
334 | 120k | *scf++ = getbits_fast(fr, num0); |
335 | | |
336 | 15.0k | i = 9; |
337 | 15.0k | } |
338 | | |
339 | 252k | for(;i;i--) *scf++ = getbits_fast(fr, num0); |
340 | | |
341 | 387k | for(i = 18; i; i--) *scf++ = getbits_fast(fr, num1); |
342 | | |
343 | 20.3k | *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */ |
344 | 20.3k | } |
345 | 32.1k | else |
346 | 32.1k | { |
347 | 32.1k | int i; |
348 | 32.1k | int scfsi = gr_info->scfsi; |
349 | | |
350 | 32.1k | if(scfsi < 0) |
351 | 18.3k | { /* scfsi < 0 => granule == 0 */ |
352 | 18.3k | numbits = (num0 + num1) * 10 + num0; |
353 | 18.3k | if(fr->bits_avail < numbits) |
354 | 548 | return -1; |
355 | | |
356 | 214k | for(i=11;i;i--) *scf++ = getbits_fast(fr, num0); |
357 | | |
358 | 196k | for(i=10;i;i--) *scf++ = getbits_fast(fr, num1); |
359 | | |
360 | 17.8k | *scf++ = 0; |
361 | 17.8k | } |
362 | 13.8k | else |
363 | 13.8k | { |
364 | 13.8k | numbits = !(scfsi & 0x8) * num0 * 6 |
365 | 13.8k | + !(scfsi & 0x4) * num0 * 5 |
366 | 13.8k | + !(scfsi & 0x2) * num1 * 5 |
367 | 13.8k | + !(scfsi & 0x1) * num1 * 5; |
368 | 13.8k | if(fr->bits_avail < numbits) |
369 | 331 | return -1; |
370 | | |
371 | 13.4k | if(!(scfsi & 0x8)) |
372 | 10.7k | { |
373 | 75.0k | for (i=0;i<6;i++) *scf++ = getbits_fast(fr, num0); |
374 | 10.7k | } |
375 | 2.76k | else scf += 6; |
376 | | |
377 | 13.4k | if(!(scfsi & 0x4)) |
378 | 10.4k | { |
379 | 62.4k | for (i=0;i<5;i++) *scf++ = getbits_fast(fr, num0); |
380 | 10.4k | } |
381 | 3.06k | else scf += 5; |
382 | | |
383 | 13.4k | if(!(scfsi & 0x2)) |
384 | 10.7k | { |
385 | 64.5k | for(i=0;i<5;i++) *scf++ = getbits_fast(fr, num1); |
386 | 10.7k | } |
387 | 2.72k | else scf += 5; |
388 | | |
389 | 13.4k | if(!(scfsi & 0x1)) |
390 | 9.99k | { |
391 | 59.9k | for (i=0;i<5;i++) *scf++ = getbits_fast(fr, num1); |
392 | 9.99k | } |
393 | 3.48k | else scf += 5; |
394 | | |
395 | 13.4k | *scf++ = 0; /* no l[21] in original sources */ |
396 | 13.4k | } |
397 | 32.1k | } |
398 | | |
399 | 51.7k | return numbits; |
400 | 54.0k | } |
401 | | |
402 | | |
403 | | static int III_get_scale_factors_2(mpg123_handle *fr, int *scf,struct gr_info_s *gr_info,int i_stereo) |
404 | 81.4k | { |
405 | 81.4k | const unsigned char *pnt; |
406 | 81.4k | int i,j,n=0,numbits=0; |
407 | 81.4k | unsigned int slen, slen2; |
408 | | |
409 | 81.4k | const unsigned char stab[3][6][4] = |
410 | 81.4k | { |
411 | 81.4k | { |
412 | 81.4k | { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0}, |
413 | 81.4k | { 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} |
414 | 81.4k | }, |
415 | 81.4k | { |
416 | 81.4k | { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0}, |
417 | 81.4k | {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} |
418 | 81.4k | }, |
419 | 81.4k | { |
420 | 81.4k | { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0}, |
421 | 81.4k | { 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} |
422 | 81.4k | } |
423 | 81.4k | }; |
424 | | |
425 | 81.4k | if(i_stereo) /* i_stereo AND second channel -> INT123_do_layer3() checks this */ |
426 | 22.3k | slen = i_slen2[gr_info->scalefac_compress>>1]; |
427 | 59.1k | else |
428 | 59.1k | slen = n_slen2[gr_info->scalefac_compress]; |
429 | | |
430 | 81.4k | gr_info->preflag = (slen>>15) & 0x1; |
431 | | |
432 | 81.4k | n = 0; |
433 | 81.4k | if( gr_info->block_type == 2 ) |
434 | 28.4k | { |
435 | 28.4k | n++; |
436 | 28.4k | if(gr_info->mixed_block_flag) n++; |
437 | 28.4k | } |
438 | | |
439 | 81.4k | pnt = stab[n][(slen>>12)&0x7]; |
440 | | |
441 | 81.4k | slen2 = slen; |
442 | 407k | for(i=0;i<4;i++) |
443 | 325k | { |
444 | 325k | int num = slen2 & 0x7; |
445 | 325k | slen2 >>= 3; |
446 | 325k | if(num) |
447 | 45.3k | numbits += pnt[i] * num; |
448 | 325k | } |
449 | 81.4k | if(numbits > gr_info->part2_3_length) |
450 | 7.06k | return -1; |
451 | | |
452 | 371k | for(i=0;i<4;i++) |
453 | 297k | { |
454 | 297k | int num = slen & 0x7; |
455 | 297k | slen >>= 3; |
456 | 297k | if(num) |
457 | 29.1k | { |
458 | 272k | for(j=0;j<(int)(pnt[i]);j++) *scf++ = getbits_fast(fr, num); |
459 | 29.1k | } |
460 | 268k | else |
461 | 1.91M | for(j=0;j<(int)(pnt[i]);j++) *scf++ = 0; |
462 | 297k | } |
463 | | |
464 | 74.3k | n = (n << 1) + 1; |
465 | 221k | for(i=0;i<n;i++) *scf++ = 0; |
466 | | |
467 | 74.3k | return numbits; |
468 | 81.4k | } |
469 | | |
470 | | static unsigned char pretab_choice[2][22] = |
471 | | { |
472 | | {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}, |
473 | | {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0} |
474 | | }; |
475 | | |
476 | | /* |
477 | | Dequantize samples |
478 | | ...includes Huffman decoding |
479 | | */ |
480 | | |
481 | | /* 24 is enough because tab13 has max. a 19 bit huffvector */ |
482 | | /* The old code played games with shifting signed integers around in not quite */ |
483 | | /* legal ways. Also, it used long where just 32 bits are required. This could */ |
484 | | /* be good or bad on 64 bit architectures ... anyway, making clear that */ |
485 | | /* 32 bits suffice is a benefit. */ |
486 | | #if 0 |
487 | | /* To reconstruct old code, use this: */ |
488 | | #define MASK_STYPE long |
489 | | #define MASK_UTYPE unsigned long |
490 | | #define MASK_TYPE MASK_STYPE |
491 | | #define MSB_MASK (mask < 0) |
492 | | #else |
493 | | /* This should be more proper: */ |
494 | 3.49M | #define MASK_STYPE int32_t |
495 | 55.2k | #define MASK_UTYPE uint32_t |
496 | 55.2k | #define MASK_TYPE MASK_UTYPE |
497 | 10.1M | #define MSB_MASK ((MASK_UTYPE)mask & (MASK_UTYPE)1<<(sizeof(MASK_TYPE)*8-1)) |
498 | | #endif |
499 | 28.3M | #define BITSHIFT ((sizeof(MASK_TYPE)-1)*8) |
500 | | #define REFRESH_MASK \ |
501 | 13.1M | while(num < BITSHIFT) { \ |
502 | 4.64M | mask |= ((MASK_UTYPE)getbyte(fr))<<(BITSHIFT-num); \ |
503 | 4.64M | num += 8; \ |
504 | 4.64M | part2remain -= 8; } |
505 | | /* Complicated way of checking for msb value. This used to be (mask < 0). */ |
506 | | |
507 | | static int III_dequantize_sample(mpg123_handle *fr, real xr[SBLIMIT][SSLIMIT],int *scf, struct gr_info_s *gr_info,int sfreq,int part2bits) |
508 | 126k | { |
509 | 126k | int shift = 1 + gr_info->scalefac_scale; |
510 | | // Pointer cast to make pedantic compilers happy. |
511 | 126k | real *xrpnt = (real*)xr; |
512 | | // Some compiler freaks out over &xr[SBLIMIT][0], which is the same. |
513 | 126k | real *xrpntlimit = (real*)xr+SBLIMIT*SSLIMIT; |
514 | 126k | int l[3],l3; |
515 | 126k | int part2remain = gr_info->part2_3_length - part2bits; |
516 | 126k | const short *me; |
517 | | #ifdef REAL_IS_FIXED |
518 | | int gainpow2_scale_idx = 378; |
519 | | #endif |
520 | | |
521 | | /* Assumption: If there is some part2_3_length at all, there should be |
522 | | enough of it to work with properly. In case of zero length we silently |
523 | | zero things. */ |
524 | 126k | if(gr_info->part2_3_length > 0) |
525 | 55.2k | { |
526 | | |
527 | | /* mhipp tree has this split up a bit... */ |
528 | 55.2k | int num=getbitoffset(fr); |
529 | 55.2k | MASK_TYPE mask; |
530 | | /* We must split this, because for num==0 the shift is undefined if you do it in one step. */ |
531 | 55.2k | mask = ((MASK_UTYPE) getbits(fr, num))<<BITSHIFT; |
532 | 55.2k | mask <<= 8-num; |
533 | 55.2k | part2remain -= num; |
534 | | |
535 | | /* Bitindex is zero now, we are allowed to use getbyte(). */ |
536 | | |
537 | 55.2k | { |
538 | 55.2k | int bv = gr_info->big_values; |
539 | 55.2k | int region1 = gr_info->region1start; |
540 | 55.2k | int region2 = gr_info->region2start; |
541 | 55.2k | l3 = ((576>>1)-bv)>>1; |
542 | | |
543 | | /* we may lose the 'odd' bit here !! check this later again */ |
544 | 55.2k | if(bv <= region1) |
545 | 26.7k | { |
546 | 26.7k | l[0] = bv; |
547 | 26.7k | l[1] = 0; |
548 | 26.7k | l[2] = 0; |
549 | 26.7k | } |
550 | 28.5k | else |
551 | 28.5k | { |
552 | 28.5k | l[0] = region1; |
553 | 28.5k | if(bv <= region2) |
554 | 17.5k | { |
555 | 17.5k | l[1] = bv - l[0]; |
556 | 17.5k | l[2] = 0; |
557 | 17.5k | } |
558 | 10.9k | else |
559 | 10.9k | { |
560 | 10.9k | l[1] = region2 - l[0]; |
561 | 10.9k | l[2] = bv - region2; |
562 | 10.9k | } |
563 | 28.5k | } |
564 | 55.2k | } |
565 | | |
566 | 16.7M | #define CHECK_XRPNT if(xrpnt >= xrpntlimit) \ |
567 | 0 | { \ |
568 | 0 | if(NOQUIET) \ |
569 | 0 | error2("attempted xrpnt overflow (%p !< %p)", (void*) xrpnt, (void*) xrpntlimit); \ |
570 | 0 | return 1; \ |
571 | 0 | } |
572 | | |
573 | 55.2k | if(gr_info->block_type == 2) |
574 | 30.4k | { |
575 | | /* decoding with short or mixed mode BandIndex table */ |
576 | 30.4k | int i,max[4]; |
577 | 30.4k | int step=0,lwin=3,cb=0; |
578 | 30.4k | register real v = 0.0; |
579 | 30.4k | register int mc; |
580 | 30.4k | register const short *m; |
581 | | |
582 | 30.4k | if(gr_info->mixed_block_flag) |
583 | 14.4k | { |
584 | 14.4k | max[3] = -1; |
585 | 14.4k | max[0] = max[1] = max[2] = 2; |
586 | 14.4k | m = map[sfreq][0]; |
587 | 14.4k | me = mapend[sfreq][0]; |
588 | 14.4k | } |
589 | 16.0k | else |
590 | 16.0k | { |
591 | 16.0k | max[0] = max[1] = max[2] = max[3] = -1; |
592 | | /* max[3] not really needed in this case */ |
593 | 16.0k | m = map[sfreq][1]; |
594 | 16.0k | me = mapend[sfreq][1]; |
595 | 16.0k | } |
596 | | |
597 | 30.4k | mc = 0; |
598 | 91.3k | for(i=0;i<2;i++) |
599 | 60.8k | { |
600 | 60.8k | int lp = l[i]; |
601 | 60.8k | const struct newhuff *h = ht+gr_info->table_select[i]; |
602 | 3.10M | for(;lp;lp--,mc--) |
603 | 3.04M | { |
604 | 3.04M | register MASK_STYPE x,y; |
605 | 3.04M | if( (!mc) ) |
606 | 472k | { |
607 | 472k | mc = *m++; |
608 | | //fprintf(stderr, "%i setting xrpnt = xr + %i (%ld)\n", __LINE__, *m, xrpnt-(real*)xr); |
609 | 472k | xrpnt = ((real *) xr) + (*m++); |
610 | 472k | lwin = *m++; |
611 | 472k | cb = *m++; |
612 | 472k | if(lwin == 3) |
613 | 52.3k | { |
614 | | #ifdef REAL_IS_FIXED |
615 | | gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2); |
616 | | #endif |
617 | 52.3k | v = gr_info->pow2gain[(*scf++) << shift]; |
618 | 52.3k | step = 1; |
619 | 52.3k | } |
620 | 420k | else |
621 | 420k | { |
622 | | #ifdef REAL_IS_FIXED |
623 | | gainpow2_scale_idx = (int)(gr_info->full_gain[lwin] + (*scf << shift) - fr->gainpow2); |
624 | | #endif |
625 | 420k | v = gr_info->full_gain[lwin][(*scf++) << shift]; |
626 | 420k | step = 3; |
627 | 420k | } |
628 | 472k | } |
629 | 3.04M | { |
630 | 3.04M | const short *val = h->table; |
631 | 3.04M | REFRESH_MASK; |
632 | 3.04M | #ifdef USE_NEW_HUFFTABLE |
633 | 4.53M | while((y=val[(MASK_UTYPE)mask>>(BITSHIFT+4)])<0) |
634 | 1.48M | { |
635 | 1.48M | val -= y; |
636 | 1.48M | num -= 4; |
637 | 1.48M | mask <<= 4; |
638 | 1.48M | } |
639 | 3.04M | num -= (y >> 8); |
640 | 3.04M | mask <<= (y >> 8); |
641 | 3.04M | x = (y >> 4) & 0xf; |
642 | 3.04M | y &= 0xf; |
643 | | #else |
644 | | while((y=*val++)<0) |
645 | | { |
646 | | if (MSB_MASK) val -= y; |
647 | | |
648 | | num--; |
649 | | mask <<= 1; |
650 | | } |
651 | | x = y >> 4; |
652 | | y &= 0xf; |
653 | | #endif |
654 | 3.04M | } |
655 | 3.04M | CHECK_XRPNT; |
656 | 3.04M | if(x == 15 && h->linbits) |
657 | 12.8k | { |
658 | 12.8k | max[lwin] = cb; |
659 | 12.8k | REFRESH_MASK; |
660 | 12.8k | x += ((MASK_UTYPE) mask) >> (BITSHIFT+8-h->linbits); |
661 | 12.8k | num -= h->linbits+1; |
662 | 12.8k | mask <<= h->linbits; |
663 | 12.8k | if(MSB_MASK) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx); |
664 | 5.95k | else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx); |
665 | | |
666 | 12.8k | mask <<= 1; |
667 | 12.8k | } |
668 | 3.03M | else if(x) |
669 | 983k | { |
670 | 983k | max[lwin] = cb; |
671 | 983k | if(MSB_MASK) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx); |
672 | 960k | else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx); |
673 | | |
674 | 983k | num--; |
675 | 983k | mask <<= 1; |
676 | 983k | } |
677 | 2.04M | else *xrpnt = DOUBLE_TO_REAL(0.0); |
678 | | |
679 | 3.04M | xrpnt += step; |
680 | 3.04M | CHECK_XRPNT; |
681 | 3.04M | if(y == 15 && h->linbits) |
682 | 679k | { |
683 | 679k | max[lwin] = cb; |
684 | 679k | REFRESH_MASK; |
685 | 679k | y += ((MASK_UTYPE) mask) >> (BITSHIFT+8-h->linbits); |
686 | 679k | num -= h->linbits+1; |
687 | 679k | mask <<= h->linbits; |
688 | 679k | if(MSB_MASK) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx); |
689 | 673k | else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx); |
690 | | |
691 | 679k | mask <<= 1; |
692 | 679k | } |
693 | 2.36M | else if(y) |
694 | 312k | { |
695 | 312k | max[lwin] = cb; |
696 | 312k | if(MSB_MASK) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx); |
697 | 287k | else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx); |
698 | | |
699 | 312k | num--; |
700 | 312k | mask <<= 1; |
701 | 312k | } |
702 | 2.05M | else *xrpnt = DOUBLE_TO_REAL(0.0); |
703 | | |
704 | 3.04M | xrpnt += step; |
705 | 3.04M | } |
706 | 60.8k | } |
707 | | |
708 | 411k | for(;l3 && (part2remain+num > 0);l3--) |
709 | 391k | { |
710 | 391k | const struct newhuff* h; |
711 | 391k | const short* val; |
712 | 391k | register short a; |
713 | | |
714 | 391k | h = htc+gr_info->count1table_select; |
715 | 391k | val = h->table; |
716 | | |
717 | 391k | REFRESH_MASK; |
718 | 2.02M | while((a=*val++)<0) |
719 | 1.63M | { |
720 | 1.63M | if(MSB_MASK) val -= a; |
721 | | |
722 | 1.63M | num--; |
723 | 1.63M | mask <<= 1; |
724 | 1.63M | } |
725 | 391k | if(part2remain+num <= 0) |
726 | 10.1k | { |
727 | 10.1k | num -= part2remain+num; |
728 | 10.1k | break; |
729 | 10.1k | } |
730 | | |
731 | 1.89M | for(i=0;i<4;i++) |
732 | 1.52M | { |
733 | 1.52M | if(!(i & 1)) |
734 | 761k | { |
735 | 761k | if(!mc) |
736 | 125k | { |
737 | 125k | mc = *m++; |
738 | | //fprintf(stderr, "%i setting xrpnt = xr + %i (%ld)\n", __LINE__, *m, xrpnt-(real*)xr); |
739 | 125k | xrpnt = ((real *) xr) + (*m++); |
740 | 125k | lwin = *m++; |
741 | 125k | cb = *m++; |
742 | 125k | if(lwin == 3) |
743 | 19.4k | { |
744 | | #ifdef REAL_IS_FIXED |
745 | | gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2); |
746 | | #endif |
747 | 19.4k | v = gr_info->pow2gain[(*scf++) << shift]; |
748 | 19.4k | step = 1; |
749 | 19.4k | } |
750 | 105k | else |
751 | 105k | { |
752 | | #ifdef REAL_IS_FIXED |
753 | | gainpow2_scale_idx = (int)(gr_info->full_gain[lwin] + (*scf << shift) - fr->gainpow2); |
754 | | #endif |
755 | 105k | v = gr_info->full_gain[lwin][(*scf++) << shift]; |
756 | 105k | step = 3; |
757 | 105k | } |
758 | 125k | } |
759 | 761k | mc--; |
760 | 761k | } |
761 | 1.52M | CHECK_XRPNT; |
762 | 1.52M | if( (a & (0x8>>i)) ) |
763 | 1.30M | { |
764 | 1.30M | max[lwin] = cb; |
765 | 1.30M | if(part2remain+num <= 0) |
766 | 7.03k | break; |
767 | | |
768 | 1.29M | if(MSB_MASK) *xrpnt = -REAL_SCALE_LAYER3(v, gainpow2_scale_idx); |
769 | 1.27M | else *xrpnt = REAL_SCALE_LAYER3(v, gainpow2_scale_idx); |
770 | | |
771 | 1.29M | num--; |
772 | 1.29M | mask <<= 1; |
773 | 1.29M | } |
774 | 219k | else *xrpnt = DOUBLE_TO_REAL(0.0); |
775 | | |
776 | 1.51M | xrpnt += step; |
777 | 1.51M | } |
778 | 381k | } |
779 | | |
780 | 30.4k | if(lwin < 3) |
781 | 20.7k | { /* short band? */ |
782 | 39.6k | while(1) |
783 | 39.6k | { |
784 | 255k | for(;mc > 0;mc--) |
785 | 215k | { |
786 | 215k | CHECK_XRPNT; |
787 | 215k | *xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3; /* short band -> step=3 */ |
788 | 215k | *xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3; |
789 | 215k | } |
790 | 39.6k | if(m >= me) |
791 | 9.28k | break; |
792 | | |
793 | 30.3k | mc = *m++; |
794 | 30.3k | xrpnt = ((real *) xr) + *m++; |
795 | 30.3k | if(*m++ == 0) |
796 | 11.4k | break; /* optimize: field will be set to zero at the end of the function */ |
797 | | |
798 | 18.8k | m++; /* cb */ |
799 | 18.8k | } |
800 | 20.7k | } |
801 | | |
802 | 30.4k | gr_info->maxband[0] = max[0]+1; |
803 | 30.4k | gr_info->maxband[1] = max[1]+1; |
804 | 30.4k | gr_info->maxband[2] = max[2]+1; |
805 | 30.4k | gr_info->maxbandl = max[3]+1; |
806 | | |
807 | 30.4k | { |
808 | 30.4k | int rmax = max[0] > max[1] ? max[0] : max[1]; |
809 | 30.4k | rmax = (rmax > max[2] ? rmax : max[2]) + 1; |
810 | 30.4k | gr_info->maxb = rmax ? fr->shortLimit[sfreq][rmax] : fr->longLimit[sfreq][max[3]+1]; |
811 | 30.4k | } |
812 | | |
813 | 30.4k | } |
814 | 24.8k | else |
815 | 24.8k | { |
816 | | /* decoding with 'long' BandIndex table (block_type != 2) */ |
817 | 24.8k | const unsigned char *pretab = pretab_choice[gr_info->preflag]; |
818 | 24.8k | int i,max = -1; |
819 | 24.8k | int cb = 0; |
820 | 24.8k | const short *m = map[sfreq][2]; |
821 | 24.8k | register real v = 0.0; |
822 | 24.8k | int mc = 0; |
823 | | |
824 | | /* long hash table values */ |
825 | 99.3k | for(i=0;i<3;i++) |
826 | 74.4k | { |
827 | 74.4k | int lp = l[i]; |
828 | 74.4k | const struct newhuff *h = ht+gr_info->table_select[i]; |
829 | | |
830 | 3.56M | for(;lp;lp--,mc--) |
831 | 3.49M | { |
832 | 3.49M | MASK_STYPE x,y; |
833 | 3.49M | if(!mc) |
834 | 313k | { |
835 | 313k | mc = *m++; |
836 | 313k | cb = *m++; |
837 | | #ifdef CUT_SFB21 |
838 | | if(cb == 21) |
839 | | v = 0.0; |
840 | | else |
841 | | #endif |
842 | 313k | { |
843 | | #ifdef REAL_IS_FIXED |
844 | | gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2); |
845 | | #endif |
846 | 313k | v = gr_info->pow2gain[(*(scf++) + (*pretab++)) << shift]; |
847 | 313k | } |
848 | 313k | } |
849 | 3.49M | { |
850 | 3.49M | const short *val = h->table; |
851 | 3.49M | REFRESH_MASK; |
852 | 3.49M | #ifdef USE_NEW_HUFFTABLE |
853 | 4.84M | while((y=val[(MASK_UTYPE)mask>>(BITSHIFT+4)])<0) |
854 | 1.35M | { |
855 | 1.35M | val -= y; |
856 | 1.35M | num -= 4; |
857 | 1.35M | mask <<= 4; |
858 | 1.35M | } |
859 | 3.49M | num -= (y >> 8); |
860 | 3.49M | mask <<= (y >> 8); |
861 | 3.49M | x = (y >> 4) & 0xf; |
862 | 3.49M | y &= 0xf; |
863 | | #else |
864 | | while((y=*val++)<0) |
865 | | { |
866 | | if (MSB_MASK) val -= y; |
867 | | |
868 | | num--; |
869 | | mask <<= 1; |
870 | | } |
871 | | x = y >> 4; |
872 | | y &= 0xf; |
873 | | #endif |
874 | 3.49M | } |
875 | | |
876 | 3.49M | CHECK_XRPNT; |
877 | 3.49M | if(x == 15 && h->linbits) |
878 | 10.9k | { |
879 | 10.9k | max = cb; |
880 | 10.9k | REFRESH_MASK; |
881 | 10.9k | x += ((MASK_UTYPE) mask) >> (BITSHIFT+8-h->linbits); |
882 | 10.9k | num -= h->linbits+1; |
883 | 10.9k | mask <<= h->linbits; |
884 | 10.9k | if(MSB_MASK) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx); |
885 | 7.00k | else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx); |
886 | | |
887 | 10.9k | mask <<= 1; |
888 | 10.9k | } |
889 | 3.48M | else if(x) |
890 | 902k | { |
891 | 902k | max = cb; |
892 | 902k | if(MSB_MASK) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx); |
893 | 880k | else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx); |
894 | 902k | num--; |
895 | | |
896 | 902k | mask <<= 1; |
897 | 902k | } |
898 | 2.58M | else *xrpnt++ = DOUBLE_TO_REAL(0.0); |
899 | | |
900 | 3.49M | CHECK_XRPNT; |
901 | 3.49M | if(y == 15 && h->linbits) |
902 | 390k | { |
903 | 390k | max = cb; |
904 | 390k | REFRESH_MASK; |
905 | 390k | y += ((MASK_UTYPE) mask) >> (BITSHIFT+8-h->linbits); |
906 | 390k | num -= h->linbits+1; |
907 | 390k | mask <<= h->linbits; |
908 | 390k | if(MSB_MASK) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx); |
909 | 383k | else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx); |
910 | | |
911 | 390k | mask <<= 1; |
912 | 390k | } |
913 | 3.10M | else if(y) |
914 | 513k | { |
915 | 513k | max = cb; |
916 | 513k | if(MSB_MASK) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx); |
917 | 494k | else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx); |
918 | | |
919 | 513k | num--; |
920 | 513k | mask <<= 1; |
921 | 513k | } |
922 | 2.58M | else *xrpnt++ = DOUBLE_TO_REAL(0.0); |
923 | 3.49M | } |
924 | 74.4k | } |
925 | | |
926 | | /* short (count1table) values */ |
927 | 520k | for(;l3 && (part2remain+num > 0);l3--) |
928 | 504k | { |
929 | 504k | const struct newhuff *h = htc+gr_info->count1table_select; |
930 | 504k | const short *val = h->table; |
931 | 504k | register short a; |
932 | | |
933 | 504k | REFRESH_MASK; |
934 | 2.67M | while((a=*val++)<0) |
935 | 2.17M | { |
936 | 2.17M | if (MSB_MASK) val -= a; |
937 | | |
938 | 2.17M | num--; |
939 | 2.17M | mask <<= 1; |
940 | 2.17M | } |
941 | 504k | if(part2remain+num <= 0) |
942 | 9.01k | { |
943 | 9.01k | num -= part2remain+num; |
944 | 9.01k | break; |
945 | 9.01k | } |
946 | | |
947 | 2.47M | for(i=0;i<4;i++) |
948 | 1.97M | { |
949 | 1.97M | if(!(i & 1)) |
950 | 990k | { |
951 | 990k | if(!mc) |
952 | 82.1k | { |
953 | 82.1k | mc = *m++; |
954 | 82.1k | cb = *m++; |
955 | | #ifdef CUT_SFB21 |
956 | | if(cb == 21) |
957 | | v = 0.0; |
958 | | else |
959 | | #endif |
960 | 82.1k | { |
961 | | #ifdef REAL_IS_FIXED |
962 | | gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2); |
963 | | #endif |
964 | 82.1k | v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift]; |
965 | 82.1k | } |
966 | 82.1k | } |
967 | 990k | mc--; |
968 | 990k | } |
969 | 1.97M | CHECK_XRPNT; |
970 | 1.97M | if( (a & (0x8>>i)) ) |
971 | 1.24M | { |
972 | 1.24M | max = cb; |
973 | 1.24M | if(part2remain+num <= 0) |
974 | 3.26k | break; |
975 | | |
976 | 1.24M | if(MSB_MASK) *xrpnt++ = -REAL_SCALE_LAYER3(v, gainpow2_scale_idx); |
977 | 1.18M | else *xrpnt++ = REAL_SCALE_LAYER3(v, gainpow2_scale_idx); |
978 | | |
979 | 1.24M | num--; |
980 | 1.24M | mask <<= 1; |
981 | 1.24M | } |
982 | 730k | else *xrpnt++ = DOUBLE_TO_REAL(0.0); |
983 | 1.97M | } |
984 | 495k | } |
985 | | |
986 | 24.8k | gr_info->maxbandl = max+1; |
987 | 24.8k | gr_info->maxb = fr->longLimit[sfreq][gr_info->maxbandl]; |
988 | 24.8k | } |
989 | | |
990 | 55.2k | part2remain += num; |
991 | 55.2k | backbits(fr, num); |
992 | 55.2k | num = 0; |
993 | | |
994 | 55.2k | } |
995 | 70.8k | else |
996 | 70.8k | { |
997 | 70.8k | part2remain = 0; |
998 | | /* Not entirely sure what good values are, must be > 0. */ |
999 | 70.8k | gr_info->maxband[0] = |
1000 | 70.8k | gr_info->maxband[1] = |
1001 | 70.8k | gr_info->maxband[2] = |
1002 | 70.8k | gr_info->maxbandl = 1; /* sfb=maxband[lwin]*3 + lwin - mixed_block_flag must be >= 0 */ |
1003 | 70.8k | gr_info->maxb = 1; |
1004 | 70.8k | } |
1005 | | |
1006 | 55.7M | while(xrpnt < xrpntlimit) |
1007 | 55.6M | *xrpnt++ = DOUBLE_TO_REAL(0.0); |
1008 | | |
1009 | 650k | while( part2remain > 16 ) |
1010 | 524k | { |
1011 | 524k | skipbits(fr, 16); /* Dismiss stuffing Bits */ |
1012 | 524k | part2remain -= 16; |
1013 | 524k | } |
1014 | 126k | if(part2remain > 0) skipbits(fr, part2remain); |
1015 | 114k | else if(part2remain < 0) |
1016 | 11.4k | { |
1017 | 11.4k | if(VERBOSE2) |
1018 | 11.4k | error1("Can't rewind stream by %d bits!",-part2remain); |
1019 | 11.4k | return 1; /* -> error */ |
1020 | 11.4k | } |
1021 | 114k | return 0; |
1022 | 126k | } |
1023 | | |
1024 | | |
1025 | | /* calculate real channel values for Joint-I-Stereo-mode */ |
1026 | | static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac, struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf) |
1027 | 25.1k | { |
1028 | 25.1k | real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf; |
1029 | 25.1k | const struct bandInfoStruct *bi = &bandInfo[sfreq]; |
1030 | | |
1031 | 25.1k | const real *tab1,*tab2; |
1032 | | |
1033 | 25.1k | #if 1 |
1034 | 25.1k | int tab; |
1035 | | /* TODO: optimize as static */ |
1036 | 25.1k | const real *tabs[3][2][2] = |
1037 | 25.1k | { |
1038 | 25.1k | { { tan1_1,tan2_1 } , { tan1_2,tan2_2 } }, |
1039 | 25.1k | { { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } }, |
1040 | 25.1k | { { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } } |
1041 | 25.1k | }; |
1042 | | |
1043 | 25.1k | tab = lsf + (gr_info->scalefac_compress & lsf); |
1044 | 25.1k | tab1 = tabs[tab][ms_stereo][0]; |
1045 | 25.1k | tab2 = tabs[tab][ms_stereo][1]; |
1046 | | #else |
1047 | | if(lsf) |
1048 | | { |
1049 | | int p = gr_info->scalefac_compress & 0x1; |
1050 | | if(ms_stereo) |
1051 | | { |
1052 | | tab1 = pow1_2[p]; |
1053 | | tab2 = pow2_2[p]; |
1054 | | } |
1055 | | else |
1056 | | { |
1057 | | tab1 = pow1_1[p]; |
1058 | | tab2 = pow2_1[p]; |
1059 | | } |
1060 | | } |
1061 | | else |
1062 | | { |
1063 | | if(ms_stereo) |
1064 | | { |
1065 | | tab1 = tan1_2; |
1066 | | tab2 = tan2_2; |
1067 | | } |
1068 | | else |
1069 | | { |
1070 | | tab1 = tan1_1; |
1071 | | tab2 = tan2_1; |
1072 | | } |
1073 | | } |
1074 | | #endif |
1075 | | |
1076 | 25.1k | if(gr_info->block_type == 2) |
1077 | 14.0k | { |
1078 | 14.0k | int lwin,do_l = 0; |
1079 | 14.0k | if( gr_info->mixed_block_flag ) do_l = 1; |
1080 | | |
1081 | 56.1k | for(lwin=0;lwin<3;lwin++) |
1082 | 42.1k | { /* process each window */ |
1083 | | /* get first band with zero values */ |
1084 | 42.1k | int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */ |
1085 | 42.1k | if(sfb > 3) do_l = 0; |
1086 | | |
1087 | 464k | for(;sfb<12;sfb++) |
1088 | 422k | { |
1089 | 422k | is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ |
1090 | 422k | if(is_p != 7) |
1091 | 418k | { |
1092 | 418k | real t1,t2; |
1093 | 418k | sb = bi->shortDiff[sfb]; |
1094 | 418k | idx = bi->shortIdx[sfb] + lwin; |
1095 | 418k | t1 = tab1[is_p]; t2 = tab2[is_p]; |
1096 | 6.46M | for (; sb > 0; sb--,idx+=3) |
1097 | 6.04M | { |
1098 | 6.04M | real v = xr[0][idx]; |
1099 | 6.04M | xr[0][idx] = REAL_MUL_15(v, t1); |
1100 | 6.04M | xr[1][idx] = REAL_MUL_15(v, t2); |
1101 | 6.04M | } |
1102 | 418k | } |
1103 | 422k | } |
1104 | | |
1105 | 42.1k | #if 1 |
1106 | | /* in the original: copy 10 to 11 , here: copy 11 to 12 |
1107 | | maybe still wrong??? (copy 12 to 13?) */ |
1108 | 42.1k | is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ |
1109 | 42.1k | sb = bi->shortDiff[12]; |
1110 | 42.1k | idx = bi->shortIdx[12] + lwin; |
1111 | | #else |
1112 | | is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */ |
1113 | | sb = bi->shortDiff[11]; |
1114 | | idx = bi->shortIdx[11] + lwin; |
1115 | | #endif |
1116 | 42.1k | if(is_p != 7) |
1117 | 40.8k | { |
1118 | 40.8k | real t1,t2; |
1119 | 40.8k | t1 = tab1[is_p]; t2 = tab2[is_p]; |
1120 | 1.40M | for( ; sb > 0; sb--,idx+=3 ) |
1121 | 1.36M | { |
1122 | 1.36M | real v = xr[0][idx]; |
1123 | 1.36M | xr[0][idx] = REAL_MUL_15(v, t1); |
1124 | 1.36M | xr[1][idx] = REAL_MUL_15(v, t2); |
1125 | 1.36M | } |
1126 | 40.8k | } |
1127 | 42.1k | } /* end for(lwin; .. ; . ) */ |
1128 | | |
1129 | | /* also check l-part, if ALL bands in the three windows are 'empty' and mode = mixed_mode */ |
1130 | 14.0k | if(do_l) |
1131 | 12.2k | { |
1132 | 12.2k | int sfb = gr_info->maxbandl; |
1133 | 12.2k | int idx; |
1134 | 12.2k | if(sfb > 21) return; /* similarity fix related to CVE-2006-1655 */ |
1135 | | |
1136 | 12.2k | idx = bi->longIdx[sfb]; |
1137 | 82.4k | for( ; sfb<8; sfb++ ) |
1138 | 70.2k | { |
1139 | 70.2k | int sb = bi->longDiff[sfb]; |
1140 | 70.2k | int is_p = scalefac[sfb]; /* scale: 0-15 */ |
1141 | 70.2k | if(is_p != 7) |
1142 | 69.7k | { |
1143 | 69.7k | real t1,t2; |
1144 | 69.7k | t1 = tab1[is_p]; t2 = tab2[is_p]; |
1145 | 508k | for( ; sb > 0; sb--,idx++) |
1146 | 439k | { |
1147 | 439k | real v = xr[0][idx]; |
1148 | 439k | xr[0][idx] = REAL_MUL_15(v, t1); |
1149 | 439k | xr[1][idx] = REAL_MUL_15(v, t2); |
1150 | 439k | } |
1151 | 69.7k | } |
1152 | 468 | else idx += sb; |
1153 | 70.2k | } |
1154 | 12.2k | } |
1155 | 14.0k | } |
1156 | 11.0k | else |
1157 | 11.0k | { /* ((gr_info->block_type != 2)) */ |
1158 | 11.0k | int sfb = gr_info->maxbandl; |
1159 | 11.0k | int is_p,idx; |
1160 | 11.0k | if(sfb > 21) return; /* tightened fix for CVE-2006-1655 */ |
1161 | | |
1162 | 10.1k | idx = bi->longIdx[sfb]; |
1163 | 175k | for ( ; sfb<21; sfb++) |
1164 | 164k | { |
1165 | 164k | int sb = bi->longDiff[sfb]; |
1166 | 164k | is_p = scalefac[sfb]; /* scale: 0-15 */ |
1167 | 164k | if(is_p != 7) |
1168 | 154k | { |
1169 | 154k | real t1,t2; |
1170 | 154k | t1 = tab1[is_p]; t2 = tab2[is_p]; |
1171 | 3.66M | for( ; sb > 0; sb--,idx++) |
1172 | 3.51M | { |
1173 | 3.51M | real v = xr[0][idx]; |
1174 | 3.51M | xr[0][idx] = REAL_MUL_15(v, t1); |
1175 | 3.51M | xr[1][idx] = REAL_MUL_15(v, t2); |
1176 | 3.51M | } |
1177 | 154k | } |
1178 | 10.8k | else idx += sb; |
1179 | 164k | } |
1180 | | |
1181 | 10.1k | is_p = scalefac[20]; |
1182 | 10.1k | if(is_p != 7) |
1183 | 6.80k | { /* copy l-band 20 to l-band 21 */ |
1184 | 6.80k | int sb; |
1185 | 6.80k | real t1 = tab1[is_p],t2 = tab2[is_p]; |
1186 | | |
1187 | 683k | for( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) |
1188 | 676k | { |
1189 | 676k | real v = xr[0][idx]; |
1190 | 676k | xr[0][idx] = REAL_MUL_15(v, t1); |
1191 | 676k | xr[1][idx] = REAL_MUL_15(v, t2); |
1192 | 676k | } |
1193 | 6.80k | } |
1194 | 10.1k | } |
1195 | 25.1k | } |
1196 | | |
1197 | | |
1198 | | static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) |
1199 | 89.6k | { |
1200 | 89.6k | int sblim; |
1201 | | |
1202 | 89.6k | if(gr_info->block_type == 2) |
1203 | 27.7k | { |
1204 | 27.7k | if(!gr_info->mixed_block_flag) return; |
1205 | | |
1206 | 22.2k | sblim = 1; |
1207 | 22.2k | } |
1208 | 61.8k | else sblim = gr_info->maxb-1; |
1209 | | |
1210 | | /* 31 alias-reduction operations between each pair of sub-bands */ |
1211 | | /* with 8 butterflies between each pair */ |
1212 | | |
1213 | 84.1k | { |
1214 | 84.1k | int sb; |
1215 | 84.1k | real *xr1=(real *) xr[1]; |
1216 | | |
1217 | 319k | for(sb=sblim; sb; sb--,xr1+=10) |
1218 | 234k | { |
1219 | 234k | int ss; |
1220 | 234k | const real *cs=aa_cs,*ca=aa_ca; |
1221 | 234k | real *xr2 = xr1; |
1222 | | |
1223 | 2.11M | for(ss=7;ss>=0;ss--) |
1224 | 1.87M | { /* upper and lower butterfly inputs */ |
1225 | 1.87M | register real bu = *--xr2,bd = *xr1; |
1226 | 1.87M | *xr2 = REAL_MUL(bu, *cs) - REAL_MUL(bd, *ca); |
1227 | 1.87M | *xr1++ = REAL_MUL(bd, *cs++) + REAL_MUL(bu, *ca++); |
1228 | 1.87M | } |
1229 | 234k | } |
1230 | 84.1k | } |
1231 | 84.1k | } |
1232 | | |
1233 | | /* |
1234 | | This is an optimized DCT from Jeff Tsay's maplay 1.2+ package. |
1235 | | Saved one multiplication by doing the 'twiddle factor' stuff |
1236 | | together with the window mul. (MH) |
1237 | | |
1238 | | This uses Byeong Gi Lee's Fast Cosine Transform algorithm, but the |
1239 | | 9 point IDCT needs to be reduced further. Unfortunately, I don't |
1240 | | know how to do that, because 9 is not an even number. - Jeff. |
1241 | | |
1242 | | Original Message: |
1243 | | |
1244 | | 9 Point Inverse Discrete Cosine Transform |
1245 | | |
1246 | | This piece of code is Copyright 1997 Mikko Tommila and is freely usable |
1247 | | by anybody. The algorithm itself is of course in the public domain. |
1248 | | |
1249 | | Again derived heuristically from the 9-point WFTA. |
1250 | | |
1251 | | The algorithm is optimized (?) for speed, not for small rounding errors or |
1252 | | good readability. |
1253 | | |
1254 | | 36 additions, 11 multiplications |
1255 | | |
1256 | | Again this is very likely sub-optimal. |
1257 | | |
1258 | | The code is optimized to use a minimum number of temporary variables, |
1259 | | so it should compile quite well even on 8-register Intel x86 processors. |
1260 | | This makes the code quite obfuscated and very difficult to understand. |
1261 | | |
1262 | | References: |
1263 | | [1] S. Winograd: "On Computing the Discrete Fourier Transform", |
1264 | | Mathematics of Computation, Volume 32, Number 141, January 1978, |
1265 | | Pages 175-199 |
1266 | | */ |
1267 | | static void INT123_dct36(real *inbuf,real *o1,real *o2,const real *wintab,real *tsbuf) |
1268 | 0 | { |
1269 | 0 | real tmp[18]; |
1270 | |
|
1271 | 0 | { |
1272 | 0 | register real *in = inbuf; |
1273 | |
|
1274 | 0 | in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14]; |
1275 | 0 | in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11]; |
1276 | 0 | in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8]; |
1277 | 0 | in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5]; |
1278 | 0 | in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2]; |
1279 | 0 | in[2] +=in[1]; in[1] +=in[0]; |
1280 | |
|
1281 | 0 | in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9]; |
1282 | 0 | in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1]; |
1283 | |
|
1284 | 0 | #if 1 |
1285 | 0 | { |
1286 | 0 | real t3; |
1287 | 0 | { |
1288 | 0 | real t0, t1, t2; |
1289 | |
|
1290 | 0 | t0 = REAL_MUL(COS6_2, (in[8] + in[16] - in[4])); |
1291 | 0 | t1 = REAL_MUL(COS6_2, in[12]); |
1292 | |
|
1293 | 0 | t3 = in[0]; |
1294 | 0 | t2 = t3 - t1 - t1; |
1295 | 0 | tmp[1] = tmp[7] = t2 - t0; |
1296 | 0 | tmp[4] = t2 + t0 + t0; |
1297 | 0 | t3 += t1; |
1298 | |
|
1299 | 0 | t2 = REAL_MUL(COS6_1, (in[10] + in[14] - in[2])); |
1300 | 0 | tmp[1] -= t2; |
1301 | 0 | tmp[7] += t2; |
1302 | 0 | } |
1303 | 0 | { |
1304 | 0 | real t0, t1, t2; |
1305 | |
|
1306 | 0 | t0 = REAL_MUL(cos9[0], (in[4] + in[8] )); |
1307 | 0 | t1 = REAL_MUL(cos9[1], (in[8] - in[16])); |
1308 | 0 | t2 = REAL_MUL(cos9[2], (in[4] + in[16])); |
1309 | |
|
1310 | 0 | tmp[2] = tmp[6] = t3 - t0 - t2; |
1311 | 0 | tmp[0] = tmp[8] = t3 + t0 + t1; |
1312 | 0 | tmp[3] = tmp[5] = t3 - t1 + t2; |
1313 | 0 | } |
1314 | 0 | } |
1315 | 0 | { |
1316 | 0 | real t1, t2, t3; |
1317 | |
|
1318 | 0 | t1 = REAL_MUL(cos18[0], (in[2] + in[10])); |
1319 | 0 | t2 = REAL_MUL(cos18[1], (in[10] - in[14])); |
1320 | 0 | t3 = REAL_MUL(COS6_1, in[6]); |
1321 | |
|
1322 | 0 | { |
1323 | 0 | real t0 = t1 + t2 + t3; |
1324 | 0 | tmp[0] += t0; |
1325 | 0 | tmp[8] -= t0; |
1326 | 0 | } |
1327 | |
|
1328 | 0 | t2 -= t3; |
1329 | 0 | t1 -= t3; |
1330 | |
|
1331 | 0 | t3 = REAL_MUL(cos18[2], (in[2] + in[14])); |
1332 | |
|
1333 | 0 | t1 += t3; |
1334 | 0 | tmp[3] += t1; |
1335 | 0 | tmp[5] -= t1; |
1336 | |
|
1337 | 0 | t2 -= t3; |
1338 | 0 | tmp[2] += t2; |
1339 | 0 | tmp[6] -= t2; |
1340 | 0 | } |
1341 | |
|
1342 | | #else |
1343 | | { |
1344 | | real t0, t1, t2, t3, t4, t5, t6, t7; |
1345 | | |
1346 | | t1 = REAL_MUL(COS6_2, in[12]); |
1347 | | t2 = REAL_MUL(COS6_2, (in[8] + in[16] - in[4])); |
1348 | | |
1349 | | t3 = in[0] + t1; |
1350 | | t4 = in[0] - t1 - t1; |
1351 | | t5 = t4 - t2; |
1352 | | tmp[4] = t4 + t2 + t2; |
1353 | | |
1354 | | t0 = REAL_MUL(cos9[0], (in[4] + in[8])); |
1355 | | t1 = REAL_MUL(cos9[1], (in[8] - in[16])); |
1356 | | |
1357 | | t2 = REAL_MUL(cos9[2], (in[4] + in[16])); |
1358 | | |
1359 | | t6 = t3 - t0 - t2; |
1360 | | t0 += t3 + t1; |
1361 | | t3 += t2 - t1; |
1362 | | |
1363 | | t2 = REAL_MUL(cos18[0], (in[2] + in[10])); |
1364 | | t4 = REAL_MUL(cos18[1], (in[10] - in[14])); |
1365 | | t7 = REAL_MUL(COS6_1, in[6]); |
1366 | | |
1367 | | t1 = t2 + t4 + t7; |
1368 | | tmp[0] = t0 + t1; |
1369 | | tmp[8] = t0 - t1; |
1370 | | t1 = REAL_MUL(cos18[2], (in[2] + in[14])); |
1371 | | t2 += t1 - t7; |
1372 | | |
1373 | | tmp[3] = t3 + t2; |
1374 | | t0 = REAL_MUL(COS6_1, (in[10] + in[14] - in[2])); |
1375 | | tmp[5] = t3 - t2; |
1376 | | |
1377 | | t4 -= t1 + t7; |
1378 | | |
1379 | | tmp[1] = t5 - t0; |
1380 | | tmp[7] = t5 + t0; |
1381 | | tmp[2] = t6 + t4; |
1382 | | tmp[6] = t6 - t4; |
1383 | | } |
1384 | | #endif |
1385 | |
|
1386 | 0 | { |
1387 | 0 | real t0, t1, t2, t3, t4, t5, t6, t7; |
1388 | |
|
1389 | 0 | t1 = REAL_MUL(COS6_2, in[13]); |
1390 | 0 | t2 = REAL_MUL(COS6_2, (in[9] + in[17] - in[5])); |
1391 | |
|
1392 | 0 | t3 = in[1] + t1; |
1393 | 0 | t4 = in[1] - t1 - t1; |
1394 | 0 | t5 = t4 - t2; |
1395 | |
|
1396 | 0 | t0 = REAL_MUL(cos9[0], (in[5] + in[9])); |
1397 | 0 | t1 = REAL_MUL(cos9[1], (in[9] - in[17])); |
1398 | |
|
1399 | 0 | tmp[13] = REAL_MUL((t4 + t2 + t2), INT123_tfcos36[17-13]); |
1400 | 0 | t2 = REAL_MUL(cos9[2], (in[5] + in[17])); |
1401 | |
|
1402 | 0 | t6 = t3 - t0 - t2; |
1403 | 0 | t0 += t3 + t1; |
1404 | 0 | t3 += t2 - t1; |
1405 | |
|
1406 | 0 | t2 = REAL_MUL(cos18[0], (in[3] + in[11])); |
1407 | 0 | t4 = REAL_MUL(cos18[1], (in[11] - in[15])); |
1408 | 0 | t7 = REAL_MUL(COS6_1, in[7]); |
1409 | |
|
1410 | 0 | t1 = t2 + t4 + t7; |
1411 | 0 | tmp[17] = REAL_MUL((t0 + t1), INT123_tfcos36[17-17]); |
1412 | 0 | tmp[9] = REAL_MUL((t0 - t1), INT123_tfcos36[17-9]); |
1413 | 0 | t1 = REAL_MUL(cos18[2], (in[3] + in[15])); |
1414 | 0 | t2 += t1 - t7; |
1415 | |
|
1416 | 0 | tmp[14] = REAL_MUL((t3 + t2), INT123_tfcos36[17-14]); |
1417 | 0 | t0 = REAL_MUL(COS6_1, (in[11] + in[15] - in[3])); |
1418 | 0 | tmp[12] = REAL_MUL((t3 - t2), INT123_tfcos36[17-12]); |
1419 | |
|
1420 | 0 | t4 -= t1 + t7; |
1421 | |
|
1422 | 0 | tmp[16] = REAL_MUL((t5 - t0), INT123_tfcos36[17-16]); |
1423 | 0 | tmp[10] = REAL_MUL((t5 + t0), INT123_tfcos36[17-10]); |
1424 | 0 | tmp[15] = REAL_MUL((t6 + t4), INT123_tfcos36[17-15]); |
1425 | 0 | tmp[11] = REAL_MUL((t6 - t4), INT123_tfcos36[17-11]); |
1426 | 0 | } |
1427 | |
|
1428 | 0 | #define MACRO(v) { \ |
1429 | 0 | real tmpval; \ |
1430 | 0 | tmpval = tmp[(v)] + tmp[17-(v)]; \ |
1431 | 0 | out2[9+(v)] = REAL_MUL(tmpval, w[27+(v)]); \ |
1432 | 0 | out2[8-(v)] = REAL_MUL(tmpval, w[26-(v)]); \ |
1433 | 0 | tmpval = tmp[(v)] - tmp[17-(v)]; \ |
1434 | 0 | ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(tmpval, w[8-(v)]); \ |
1435 | 0 | ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(tmpval, w[9+(v)]); } |
1436 | |
|
1437 | 0 | { |
1438 | 0 | register real *out2 = o2; |
1439 | 0 | register const real *w = wintab; |
1440 | 0 | register real *out1 = o1; |
1441 | 0 | register real *ts = tsbuf; |
1442 | |
|
1443 | 0 | MACRO(0); |
1444 | 0 | MACRO(1); |
1445 | 0 | MACRO(2); |
1446 | 0 | MACRO(3); |
1447 | 0 | MACRO(4); |
1448 | 0 | MACRO(5); |
1449 | 0 | MACRO(6); |
1450 | 0 | MACRO(7); |
1451 | 0 | MACRO(8); |
1452 | 0 | } |
1453 | |
|
1454 | 0 | } |
1455 | 0 | } |
1456 | | |
1457 | | // Wrap the assembly routine calls into C functions that serve as jump target to satisfy |
1458 | | // indirect branch protection if the toolchain enables that. Otherwise, we'd need to anticipate |
1459 | | // that in the assembly (and ensure assemblers support endbr64 and friends). |
1460 | | // Loss of efficiency: |
1461 | | |
1462 | | // In the case of one static optimization choice, we do not have that problem. |
1463 | | |
1464 | | #ifdef OPT_THE_DCT36 |
1465 | | |
1466 | | #define DCT36_WRAP(asmfunc) \ |
1467 | 371k | static void asmfunc ## _wrap(real *inbuf,real *o1,real *o2,const real *wintab,real *tsbuf) \ |
1468 | 371k | { \ |
1469 | 371k | asmfunc(inbuf, o1, o2, wintab, tsbuf); \ |
1470 | 371k | } layer3.c:INT123_dct36_avx_wrap Line | Count | Source | 1467 | 371k | static void asmfunc ## _wrap(real *inbuf,real *o1,real *o2,const real *wintab,real *tsbuf) \ | 1468 | 371k | { \ | 1469 | 371k | asmfunc(inbuf, o1, o2, wintab, tsbuf); \ | 1470 | 371k | } |
Unexecuted instantiation: layer3.c:INT123_dct36_x86_64_wrap |
1471 | | |
1472 | | #ifdef OPT_SSE |
1473 | | DCT36_WRAP(INT123_dct36_sse) |
1474 | | #endif |
1475 | | #ifdef OPT_3DNOWEXT_VINTAGE |
1476 | | DCT36_WRAP(INT123_dct36_3dnowext) |
1477 | | #endif |
1478 | | #ifdef OPT_3DNOW_VINTAGE |
1479 | | DCT36_WRAP(INT123_dct36_3dnow) |
1480 | | #endif |
1481 | | #ifdef OPT_X86_64 |
1482 | | DCT36_WRAP(INT123_dct36_x86_64) |
1483 | | #endif |
1484 | | #ifdef OPT_AVX |
1485 | | DCT36_WRAP(INT123_dct36_avx) |
1486 | | #endif |
1487 | | #ifdef OPT_NEON |
1488 | | DCT36_WRAP(INT123_dct36_neon) |
1489 | | #endif |
1490 | | #ifdef OPT_NEON64 |
1491 | | DCT36_WRAP(INT123_dct36_neon64) |
1492 | | #endif |
1493 | | |
1494 | | int INT123_dct36_match(mpg123_handle *fr, enum optdec t) |
1495 | 0 | { |
1496 | | #ifdef OPT_SSE |
1497 | | if(t == sse && fr->cpu_opts.the_dct36 == INT123_dct36_sse_wrap) |
1498 | | return 1; |
1499 | | #endif |
1500 | | #ifdef OPT_3DNOWEXT_VINTAGE |
1501 | | if(t == dreidnowext_vintage && fr->cpu_opts.the_dct36 == INT123_dct36_3dnowext_wrap) |
1502 | | return 1; |
1503 | | #endif |
1504 | | #ifdef OPT_3DNOW_VINTAGE |
1505 | | if(t == dreidnow_vintage && fr->cpu_opts.the_dct36 == INT123_dct36_3dnow_wrap) |
1506 | | return 1; |
1507 | | #endif |
1508 | 0 | return 0; |
1509 | 0 | } |
1510 | | |
1511 | | void INT123_dct36_choose(mpg123_handle *fr) |
1512 | 12.3k | { |
1513 | 12.3k | switch(fr->cpu_opts.type) |
1514 | 12.3k | { |
1515 | | #ifdef OPT_SSE |
1516 | | case sse: |
1517 | | fr->cpu_opts.the_dct36 = INT123_dct36_sse_wrap; |
1518 | | break; |
1519 | | #endif |
1520 | | #ifdef OPT_3DNOWEXT_VINTAGE |
1521 | | case dreidnowext_vintage: |
1522 | | fr->cpu_opts.the_dct36 = INT123_dct36_3dnowext_wrap; |
1523 | | break; |
1524 | | #endif |
1525 | | #ifdef OPT_3DNOW_VINTAGE |
1526 | | case dreidnow_vintage: |
1527 | | fr->cpu_opts.the_dct36 = INT123_dct36_3dnow_wrap; |
1528 | | break; |
1529 | | #endif |
1530 | 0 | #ifdef OPT_AVX |
1531 | 12.3k | case avx: |
1532 | 12.3k | fr->cpu_opts.the_dct36 = INT123_dct36_avx_wrap; |
1533 | 12.3k | break; |
1534 | 0 | #endif |
1535 | 0 | #ifdef OPT_X86_64 |
1536 | 0 | case x86_64: |
1537 | 0 | fr->cpu_opts.the_dct36 = INT123_dct36_x86_64_wrap; |
1538 | 0 | break; |
1539 | 0 | #endif |
1540 | | #ifdef OPT_NEON |
1541 | | case neon: |
1542 | | fr->cpu_opts.the_dct36 = INT123_dct36_neon_wrap; |
1543 | | break; |
1544 | | #endif |
1545 | | #ifdef OPT_NEON64 |
1546 | | case neon: |
1547 | | fr->cpu_opts.the_dct36 = INT123_dct36_neon64_wrap; |
1548 | | break; |
1549 | | #endif |
1550 | 0 | default: |
1551 | 0 | fr->cpu_opts.the_dct36 = INT123_dct36; |
1552 | 12.3k | } |
1553 | 12.3k | } |
1554 | | |
1555 | | #endif |
1556 | | |
1557 | | /* new DCT12 */ |
1558 | | static void dct12(real *in,real *rawout1,real *rawout2,register const real *wi,register real *ts) |
1559 | 55.8k | { |
1560 | 55.8k | #define DCT12_PART1 \ |
1561 | 167k | in5 = in[5*3]; \ |
1562 | 167k | in5 += (in4 = in[4*3]); \ |
1563 | 167k | in4 += (in3 = in[3*3]); \ |
1564 | 167k | in3 += (in2 = in[2*3]); \ |
1565 | 167k | in2 += (in1 = in[1*3]); \ |
1566 | 167k | in1 += (in0 = in[0*3]); \ |
1567 | 167k | \ |
1568 | 167k | in5 += in3; in3 += in1; \ |
1569 | 167k | \ |
1570 | 167k | in2 = REAL_MUL(in2, COS6_1); \ |
1571 | 167k | in3 = REAL_MUL(in3, COS6_1); |
1572 | | |
1573 | 55.8k | #define DCT12_PART2 \ |
1574 | 167k | in0 += REAL_MUL(in4, COS6_2); \ |
1575 | 167k | \ |
1576 | 167k | in4 = in0 + in2; \ |
1577 | 167k | in0 -= in2; \ |
1578 | 167k | \ |
1579 | 167k | in1 += REAL_MUL(in5, COS6_2); \ |
1580 | 167k | \ |
1581 | 167k | in5 = REAL_MUL((in1 + in3), tfcos12[0]); \ |
1582 | 167k | in1 = REAL_MUL((in1 - in3), tfcos12[2]); \ |
1583 | 167k | \ |
1584 | 167k | in3 = in4 + in5; \ |
1585 | 167k | in4 -= in5; \ |
1586 | 167k | \ |
1587 | 167k | in2 = in0 + in1; \ |
1588 | 167k | in0 -= in1; |
1589 | | |
1590 | 55.8k | { |
1591 | 55.8k | real in0,in1,in2,in3,in4,in5; |
1592 | 55.8k | register real *out1 = rawout1; |
1593 | 55.8k | ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2]; |
1594 | 55.8k | ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5]; |
1595 | | |
1596 | 55.8k | DCT12_PART1 |
1597 | | |
1598 | 55.8k | { |
1599 | 55.8k | real tmp0,tmp1 = (in0 - in4); |
1600 | 55.8k | { |
1601 | 55.8k | real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]); |
1602 | 55.8k | tmp0 = tmp1 + tmp2; |
1603 | 55.8k | tmp1 -= tmp2; |
1604 | 55.8k | } |
1605 | 55.8k | ts[(17-1)*SBLIMIT] = out1[17-1] + REAL_MUL(tmp0, wi[11-1]); |
1606 | 55.8k | ts[(12+1)*SBLIMIT] = out1[12+1] + REAL_MUL(tmp0, wi[6+1]); |
1607 | 55.8k | ts[(6 +1)*SBLIMIT] = out1[6 +1] + REAL_MUL(tmp1, wi[1]); |
1608 | 55.8k | ts[(11-1)*SBLIMIT] = out1[11-1] + REAL_MUL(tmp1, wi[5-1]); |
1609 | 55.8k | } |
1610 | | |
1611 | 55.8k | DCT12_PART2 |
1612 | | |
1613 | 55.8k | ts[(17-0)*SBLIMIT] = out1[17-0] + REAL_MUL(in2, wi[11-0]); |
1614 | 55.8k | ts[(12+0)*SBLIMIT] = out1[12+0] + REAL_MUL(in2, wi[6+0]); |
1615 | 55.8k | ts[(12+2)*SBLIMIT] = out1[12+2] + REAL_MUL(in3, wi[6+2]); |
1616 | 55.8k | ts[(17-2)*SBLIMIT] = out1[17-2] + REAL_MUL(in3, wi[11-2]); |
1617 | | |
1618 | 55.8k | ts[(6 +0)*SBLIMIT] = out1[6+0] + REAL_MUL(in0, wi[0]); |
1619 | 55.8k | ts[(11-0)*SBLIMIT] = out1[11-0] + REAL_MUL(in0, wi[5-0]); |
1620 | 55.8k | ts[(6 +2)*SBLIMIT] = out1[6+2] + REAL_MUL(in4, wi[2]); |
1621 | 55.8k | ts[(11-2)*SBLIMIT] = out1[11-2] + REAL_MUL(in4, wi[5-2]); |
1622 | 55.8k | } |
1623 | | |
1624 | 55.8k | in++; |
1625 | | |
1626 | 55.8k | { |
1627 | 55.8k | real in0,in1,in2,in3,in4,in5; |
1628 | 55.8k | register real *out2 = rawout2; |
1629 | | |
1630 | 55.8k | DCT12_PART1 |
1631 | | |
1632 | 55.8k | { |
1633 | 55.8k | real tmp0,tmp1 = (in0 - in4); |
1634 | 55.8k | { |
1635 | 55.8k | real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]); |
1636 | 55.8k | tmp0 = tmp1 + tmp2; |
1637 | 55.8k | tmp1 -= tmp2; |
1638 | 55.8k | } |
1639 | 55.8k | out2[5-1] = REAL_MUL(tmp0, wi[11-1]); |
1640 | 55.8k | out2[0+1] = REAL_MUL(tmp0, wi[6+1]); |
1641 | 55.8k | ts[(12+1)*SBLIMIT] += REAL_MUL(tmp1, wi[1]); |
1642 | 55.8k | ts[(17-1)*SBLIMIT] += REAL_MUL(tmp1, wi[5-1]); |
1643 | 55.8k | } |
1644 | | |
1645 | 55.8k | DCT12_PART2 |
1646 | | |
1647 | 55.8k | out2[5-0] = REAL_MUL(in2, wi[11-0]); |
1648 | 55.8k | out2[0+0] = REAL_MUL(in2, wi[6+0]); |
1649 | 55.8k | out2[0+2] = REAL_MUL(in3, wi[6+2]); |
1650 | 55.8k | out2[5-2] = REAL_MUL(in3, wi[11-2]); |
1651 | | |
1652 | 55.8k | ts[(12+0)*SBLIMIT] += REAL_MUL(in0, wi[0]); |
1653 | 55.8k | ts[(17-0)*SBLIMIT] += REAL_MUL(in0, wi[5-0]); |
1654 | 55.8k | ts[(12+2)*SBLIMIT] += REAL_MUL(in4, wi[2]); |
1655 | 55.8k | ts[(17-2)*SBLIMIT] += REAL_MUL(in4, wi[5-2]); |
1656 | 55.8k | } |
1657 | | |
1658 | 55.8k | in++; |
1659 | | |
1660 | 55.8k | { |
1661 | 55.8k | real in0,in1,in2,in3,in4,in5; |
1662 | 55.8k | register real *out2 = rawout2; |
1663 | 55.8k | out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0; |
1664 | | |
1665 | 55.8k | DCT12_PART1 |
1666 | | |
1667 | 55.8k | { |
1668 | 55.8k | real tmp0,tmp1 = (in0 - in4); |
1669 | 55.8k | { |
1670 | 55.8k | real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]); |
1671 | 55.8k | tmp0 = tmp1 + tmp2; |
1672 | 55.8k | tmp1 -= tmp2; |
1673 | 55.8k | } |
1674 | 55.8k | out2[11-1] = REAL_MUL(tmp0, wi[11-1]); |
1675 | 55.8k | out2[6 +1] = REAL_MUL(tmp0, wi[6+1]); |
1676 | 55.8k | out2[0+1] += REAL_MUL(tmp1, wi[1]); |
1677 | 55.8k | out2[5-1] += REAL_MUL(tmp1, wi[5-1]); |
1678 | 55.8k | } |
1679 | | |
1680 | 55.8k | DCT12_PART2 |
1681 | | |
1682 | 55.8k | out2[11-0] = REAL_MUL(in2, wi[11-0]); |
1683 | 55.8k | out2[6 +0] = REAL_MUL(in2, wi[6+0]); |
1684 | 55.8k | out2[6 +2] = REAL_MUL(in3, wi[6+2]); |
1685 | 55.8k | out2[11-2] = REAL_MUL(in3, wi[11-2]); |
1686 | | |
1687 | 55.8k | out2[0+0] += REAL_MUL(in0, wi[0]); |
1688 | 55.8k | out2[5-0] += REAL_MUL(in0, wi[5-0]); |
1689 | 55.8k | out2[0+2] += REAL_MUL(in4, wi[2]); |
1690 | 55.8k | out2[5-2] += REAL_MUL(in4, wi[5-2]); |
1691 | 55.8k | } |
1692 | 55.8k | } |
1693 | | |
1694 | | |
1695 | | static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT], real tsOut[SSLIMIT][SBLIMIT], int ch,struct gr_info_s *gr_info, mpg123_handle *fr) |
1696 | 89.6k | { |
1697 | 89.6k | real (*block)[2][SBLIMIT*SSLIMIT] = fr->hybrid_block; |
1698 | 89.6k | int *blc = fr->hybrid_blc; |
1699 | | |
1700 | 89.6k | real *tspnt = (real *) tsOut; |
1701 | 89.6k | real *rawout1,*rawout2; |
1702 | 89.6k | int bt = 0; |
1703 | 89.6k | size_t sb = 0; |
1704 | | |
1705 | 89.6k | { |
1706 | 89.6k | int b = blc[ch]; |
1707 | 89.6k | rawout1=block[b][ch]; |
1708 | 89.6k | b=-b+1; |
1709 | 89.6k | rawout2=block[b][ch]; |
1710 | 89.6k | blc[ch] = b; |
1711 | 89.6k | } |
1712 | | |
1713 | 89.6k | if(gr_info->mixed_block_flag) |
1714 | 26.3k | { |
1715 | 26.3k | sb = 2; |
1716 | 26.3k | opt_dct36(fr)(fsIn[0],rawout1,rawout2,win[0],tspnt); |
1717 | 26.3k | opt_dct36(fr)(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1); |
1718 | 26.3k | rawout1 += 36; rawout2 += 36; tspnt += 2; |
1719 | 26.3k | } |
1720 | | |
1721 | 89.6k | bt = gr_info->block_type; |
1722 | 89.6k | if(bt == 2) |
1723 | 27.7k | { |
1724 | 55.6k | for(; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) |
1725 | 27.9k | { |
1726 | 27.9k | dct12(fsIn[sb] ,rawout1 ,rawout2 ,win[2] ,tspnt); |
1727 | 27.9k | dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1); |
1728 | 27.9k | } |
1729 | 27.7k | } |
1730 | 61.8k | else |
1731 | 61.8k | { |
1732 | 221k | for(; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) |
1733 | 159k | { |
1734 | 159k | opt_dct36(fr)(fsIn[sb],rawout1,rawout2,win[bt],tspnt); |
1735 | 159k | opt_dct36(fr)(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1); |
1736 | 159k | } |
1737 | 61.8k | } |
1738 | | |
1739 | 2.53M | for(;sb<SBLIMIT;sb++,tspnt++) |
1740 | 2.44M | { |
1741 | 2.44M | int i; |
1742 | 46.3M | for(i=0;i<SSLIMIT;i++) |
1743 | 43.9M | { |
1744 | 43.9M | tspnt[i*SBLIMIT] = *rawout1++; |
1745 | 43.9M | *rawout2++ = DOUBLE_TO_REAL(0.0); |
1746 | 43.9M | } |
1747 | 2.44M | } |
1748 | 89.6k | } |
1749 | | |
1750 | | #ifndef NO_MOREINFO |
1751 | | static void fill_pinfo_side(mpg123_handle *fr, struct III_sideinfo *si, int gr, int stereo1) |
1752 | 0 | { |
1753 | 0 | int i, sb; |
1754 | 0 | float ifqstep; /* Why not double? */ |
1755 | 0 | int ch, ss;; |
1756 | |
|
1757 | 0 | for(ch = 0; ch < stereo1; ++ch) |
1758 | 0 | { |
1759 | 0 | struct gr_info_s *gr_infos = &(si->ch[ch].gr[gr]); |
1760 | 0 | fr->pinfo->big_values[gr][ch] = gr_infos->big_values; |
1761 | 0 | fr->pinfo->scalefac_scale[gr][ch] = gr_infos->scalefac_scale; |
1762 | 0 | fr->pinfo->mixed[gr][ch] = gr_infos->mixed_block_flag; |
1763 | 0 | fr->pinfo->blocktype[gr][ch] = gr_infos->block_type; |
1764 | 0 | fr->pinfo->mainbits[gr][ch] = gr_infos->part2_3_length; |
1765 | 0 | fr->pinfo->preflag[gr][ch] = gr_infos->preflag; |
1766 | 0 | if(gr == 1) |
1767 | 0 | fr->pinfo->scfsi[ch] = gr_infos->scfsi; |
1768 | 0 | } |
1769 | |
|
1770 | 0 | for(ch = 0; ch < stereo1; ++ch) |
1771 | 0 | { |
1772 | 0 | struct gr_info_s *gr_infos = &(si->ch[ch].gr[gr]); |
1773 | 0 | ifqstep = (fr->pinfo->scalefac_scale[gr][ch] == 0) ? .5 : 1.0; |
1774 | 0 | if(2 == gr_infos->block_type) |
1775 | 0 | { |
1776 | 0 | for(i = 0; i < 3; ++i) |
1777 | 0 | { |
1778 | 0 | for(sb = 0; sb < 12; ++sb) |
1779 | 0 | { |
1780 | 0 | int j = 3 * sb + i; |
1781 | | /* |
1782 | | is_p = scalefac[sfb*3+lwin-gr_infos->mixed_block_flag]; |
1783 | | */ |
1784 | | /* scalefac was copied into pinfo->sfb_s[] before */ |
1785 | 0 | fr->pinfo->sfb_s[gr][ch][j] = -ifqstep * |
1786 | 0 | fr->pinfo->sfb_s[gr][ch][j - gr_infos->mixed_block_flag]; |
1787 | 0 | fr->pinfo->sfb_s[gr][ch][j] -= 2 * |
1788 | 0 | (fr->pinfo->sub_gain[gr][ch][i]); |
1789 | 0 | } |
1790 | 0 | fr->pinfo->sfb_s[gr][ch][3 * sb + i] = |
1791 | 0 | -2 * (fr->pinfo->sub_gain[gr][ch][i]); |
1792 | 0 | } |
1793 | 0 | } else |
1794 | 0 | { |
1795 | 0 | for(sb = 0; sb < 21; ++sb) |
1796 | 0 | { |
1797 | | /* scalefac was copied into pinfo->sfb[] before */ |
1798 | 0 | fr->pinfo->sfb[gr][ch][sb] = fr->pinfo->sfb_s[gr][ch][sb]; |
1799 | 0 | if (gr_infos->preflag) |
1800 | 0 | fr->pinfo->sfb[gr][ch][sb] += pretab_choice[1][sb]; |
1801 | 0 | fr->pinfo->sfb[gr][ch][sb] *= -ifqstep; |
1802 | 0 | } |
1803 | 0 | fr->pinfo->sfb[gr][ch][21] = 0; |
1804 | 0 | } |
1805 | 0 | } |
1806 | | |
1807 | |
|
1808 | 0 | for(ch = 0; ch < stereo1; ++ch) |
1809 | 0 | { |
1810 | 0 | int j = 0; |
1811 | 0 | for(sb = 0; sb < SBLIMIT; ++sb) |
1812 | 0 | for (ss = 0; ss < SSLIMIT; ++ss, ++j) |
1813 | 0 | fr->pinfo->xr[gr][ch][j] = fr->layer3.hybrid_in[ch][sb][ss]; |
1814 | 0 | } |
1815 | 0 | } |
1816 | | #endif |
1817 | | |
1818 | | /* And at the end... the main layer3 handler */ |
1819 | | int INT123_do_layer3(mpg123_handle *fr) |
1820 | 83.6k | { |
1821 | 83.6k | int gr, ch, ss,clip=0; |
1822 | 83.6k | int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */ |
1823 | 83.6k | struct III_sideinfo sideinfo; |
1824 | 83.6k | int stereo = fr->stereo; |
1825 | 83.6k | int single = fr->single; |
1826 | 83.6k | int ms_stereo,i_stereo; |
1827 | 83.6k | int sfreq = fr->hdr.sampling_frequency; |
1828 | 83.6k | int stereo1,granules; |
1829 | | |
1830 | 83.6k | if(stereo == 1) |
1831 | 26.9k | { /* stream is mono */ |
1832 | 26.9k | stereo1 = 1; |
1833 | 26.9k | single = SINGLE_LEFT; |
1834 | 26.9k | } |
1835 | 56.6k | else if(single != SINGLE_STEREO) /* stream is stereo, but force to mono */ |
1836 | 0 | stereo1 = 1; |
1837 | 56.6k | else |
1838 | 56.6k | stereo1 = 2; |
1839 | | |
1840 | 83.6k | if(fr->hdr.mode == MPG_MD_JOINT_STEREO) |
1841 | 33.1k | { |
1842 | 33.1k | ms_stereo = (fr->hdr.mode_ext & 0x2)>>1; |
1843 | 33.1k | i_stereo = fr->hdr.mode_ext & 0x1; |
1844 | 33.1k | } |
1845 | 50.4k | else ms_stereo = i_stereo = 0; |
1846 | | |
1847 | 83.6k | granules = fr->hdr.lsf ? 1 : 2; |
1848 | | |
1849 | | /* quick hack to keep the music playing */ |
1850 | | /* after having seen this nasty test file... */ |
1851 | 83.6k | if(III_get_side_info(fr, &sideinfo,stereo,ms_stereo,sfreq,single)) |
1852 | 3.54k | { |
1853 | 3.54k | if(NOQUIET) error("bad frame - unable to get valid sideinfo"); |
1854 | 3.54k | return clip; |
1855 | 3.54k | } |
1856 | | |
1857 | 80.0k | INT123_set_pointer(fr, 1, sideinfo.main_data_begin); |
1858 | 80.0k | #ifndef NO_MOREINFO |
1859 | 80.0k | if(fr->pinfo) |
1860 | 0 | { |
1861 | 0 | fr->pinfo->maindata = sideinfo.main_data_begin; |
1862 | 0 | fr->pinfo->padding = fr->hdr.padding; |
1863 | 0 | } |
1864 | 80.0k | #endif |
1865 | 134k | for(gr=0;gr<granules;gr++) |
1866 | 97.4k | { |
1867 | | /* hybridIn[2][SBLIMIT][SSLIMIT] */ |
1868 | 97.4k | real (*hybridIn)[SBLIMIT][SSLIMIT] = fr->layer3.hybrid_in; |
1869 | | /* hybridOut[2][SSLIMIT][SBLIMIT] */ |
1870 | 97.4k | real (*hybridOut)[SSLIMIT][SBLIMIT] = fr->layer3.hybrid_out; |
1871 | | |
1872 | 97.4k | { |
1873 | 97.4k | struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]); |
1874 | 97.4k | long part2bits; |
1875 | 97.4k | if(gr_info->part2_3_length > fr->bits_avail) |
1876 | 11.9k | { |
1877 | 11.9k | if(NOQUIET) |
1878 | 11.9k | error2( |
1879 | 11.9k | "part2_3_length (%u) too large for available bit count (%li)" |
1880 | 11.9k | , gr_info->part2_3_length, fr->bits_avail ); |
1881 | 11.9k | return clip; |
1882 | 11.9k | } |
1883 | 85.4k | if(fr->hdr.lsf) |
1884 | 48.5k | part2bits = III_get_scale_factors_2(fr, scalefacs[0],gr_info,0); |
1885 | 36.9k | else |
1886 | 36.9k | part2bits = III_get_scale_factors_1(fr, scalefacs[0],gr_info,0,gr); |
1887 | | |
1888 | 85.4k | if(part2bits < 0) |
1889 | 7.94k | { |
1890 | 7.94k | if(VERBOSE2) |
1891 | 7.94k | error("not enough bits for scale factors"); |
1892 | 7.94k | return clip; |
1893 | 7.94k | } |
1894 | | |
1895 | 77.5k | #ifndef NO_MOREINFO |
1896 | 77.5k | if(fr->pinfo) |
1897 | 0 | { |
1898 | 0 | int i; |
1899 | 0 | fr->pinfo->sfbits[gr][0] = part2bits; |
1900 | 0 | for(i=0; i<39; ++i) |
1901 | 0 | fr->pinfo->sfb_s[gr][0][i] = scalefacs[0][i]; |
1902 | 0 | } |
1903 | 77.5k | #endif |
1904 | | |
1905 | 77.5k | if(III_dequantize_sample(fr, hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits)) |
1906 | 8.00k | { |
1907 | 8.00k | if(NOQUIET) |
1908 | 8.00k | error("dequantization failed!"); |
1909 | 8.00k | return clip; |
1910 | 8.00k | } |
1911 | 69.5k | if(fr->bits_avail < 0) |
1912 | 0 | { |
1913 | 0 | if(NOQUIET) |
1914 | 0 | error("bit deficit after dequant"); |
1915 | 0 | return clip; |
1916 | 0 | } |
1917 | 69.5k | } |
1918 | | |
1919 | 69.5k | if(stereo == 2) |
1920 | 49.9k | { |
1921 | 49.9k | struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]); |
1922 | 49.9k | long part2bits; |
1923 | 49.9k | if(fr->hdr.lsf) |
1924 | 32.8k | part2bits = III_get_scale_factors_2(fr, scalefacs[1],gr_info,i_stereo); |
1925 | 17.1k | else |
1926 | 17.1k | part2bits = III_get_scale_factors_1(fr, scalefacs[1],gr_info,1,gr); |
1927 | | |
1928 | 49.9k | if(part2bits < 0) |
1929 | 1.45k | { |
1930 | 1.45k | if(VERBOSE2) |
1931 | 1.45k | error("not enough bits for scale factors"); |
1932 | 1.45k | return clip; |
1933 | 1.45k | } |
1934 | | |
1935 | 48.5k | #ifndef NO_MOREINFO |
1936 | 48.5k | if(fr->pinfo) |
1937 | 0 | { |
1938 | 0 | int i; |
1939 | 0 | fr->pinfo->sfbits[gr][1] = part2bits; |
1940 | 0 | for(i=0; i<39; ++i) |
1941 | 0 | fr->pinfo->sfb_s[gr][1][i] = scalefacs[1][i]; |
1942 | 0 | } |
1943 | 48.5k | #endif |
1944 | | |
1945 | 48.5k | if(III_dequantize_sample(fr, hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits)) |
1946 | 3.49k | { |
1947 | 3.49k | if(NOQUIET) |
1948 | 3.49k | error("dequantization failed!"); |
1949 | 3.49k | return clip; |
1950 | 3.49k | } |
1951 | 45.0k | if(fr->bits_avail < 0) |
1952 | 9.99k | { |
1953 | 9.99k | if(NOQUIET) |
1954 | 9.99k | error("bit deficit after dequant"); |
1955 | 9.99k | return clip; |
1956 | 9.99k | } |
1957 | | |
1958 | 35.0k | if(ms_stereo) |
1959 | 7.14k | { |
1960 | 7.14k | int i; |
1961 | 7.14k | unsigned int maxb = sideinfo.ch[0].gr[gr].maxb; |
1962 | 7.14k | if(sideinfo.ch[1].gr[gr].maxb > maxb) maxb = sideinfo.ch[1].gr[gr].maxb; |
1963 | | |
1964 | 1.29M | for(i=0;i<SSLIMIT*(int)maxb;i++) |
1965 | 1.29M | { |
1966 | 1.29M | real tmp0 = ((real *)hybridIn[0])[i]; |
1967 | 1.29M | real tmp1 = ((real *)hybridIn[1])[i]; |
1968 | 1.29M | ((real *)hybridIn[0])[i] = tmp0 + tmp1; |
1969 | 1.29M | ((real *)hybridIn[1])[i] = tmp0 - tmp1; |
1970 | 1.29M | } |
1971 | 7.14k | } |
1972 | | |
1973 | 35.0k | if(i_stereo) III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->hdr.lsf); |
1974 | | |
1975 | 35.0k | if(ms_stereo || i_stereo || (single == SINGLE_MIX) ) |
1976 | 25.2k | { |
1977 | 25.2k | if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb) |
1978 | 7.31k | sideinfo.ch[0].gr[gr].maxb = gr_info->maxb; |
1979 | 17.9k | else |
1980 | 17.9k | gr_info->maxb = sideinfo.ch[0].gr[gr].maxb; |
1981 | 25.2k | } |
1982 | | |
1983 | 35.0k | switch(single) |
1984 | 35.0k | { |
1985 | 0 | case SINGLE_MIX: |
1986 | 0 | { |
1987 | 0 | register int i; |
1988 | 0 | register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; |
1989 | 0 | for(i=0;i<SSLIMIT*(int)gr_info->maxb;i++,in0++) |
1990 | 0 | *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */ |
1991 | 0 | } |
1992 | 0 | break; |
1993 | 0 | case SINGLE_RIGHT: |
1994 | 0 | { |
1995 | 0 | register int i; |
1996 | 0 | register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1]; |
1997 | 0 | for(i=0;i<SSLIMIT*(int)gr_info->maxb;i++) |
1998 | 0 | *in0++ = *in1++; |
1999 | 0 | } |
2000 | 0 | break; |
2001 | 35.0k | } |
2002 | 35.0k | } |
2003 | | |
2004 | 54.5k | #ifndef NO_MOREINFO |
2005 | 54.5k | if(fr->pinfo) |
2006 | 0 | fill_pinfo_side(fr, &sideinfo, gr, stereo1); |
2007 | 54.5k | #endif |
2008 | | |
2009 | 144k | for(ch=0;ch<stereo1;ch++) |
2010 | 89.6k | { |
2011 | 89.6k | struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]); |
2012 | 89.6k | III_antialias(hybridIn[ch],gr_info); |
2013 | 89.6k | III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info, fr); |
2014 | 89.6k | } |
2015 | | |
2016 | | #ifdef OPT_I486 |
2017 | | if(single != SINGLE_STEREO || fr->af.encoding != MPG123_ENC_SIGNED_16 || fr->down_sample != 0) |
2018 | | { |
2019 | | #endif |
2020 | 1.03M | for(ss=0;ss<SSLIMIT;ss++) |
2021 | 982k | { |
2022 | 982k | if(single != SINGLE_STEREO) |
2023 | 351k | clip += (fr->synth_mono)(hybridOut[0][ss], fr); |
2024 | 630k | else |
2025 | 630k | clip += (fr->synth_stereo)(hybridOut[0][ss], hybridOut[1][ss], fr); |
2026 | | |
2027 | 982k | } |
2028 | | #ifdef OPT_I486 |
2029 | | } else |
2030 | | { |
2031 | | /* Only stereo, 16 bits benefit from the 486 optimization. */ |
2032 | | ss=0; |
2033 | | while(ss < SSLIMIT) |
2034 | | { |
2035 | | int n; |
2036 | | n=(fr->buffer.size - fr->buffer.fill) / (2*2*32); |
2037 | | if(n > (SSLIMIT-ss)) n=SSLIMIT-ss; |
2038 | | |
2039 | | /* Clip counting makes no sense with this function. */ |
2040 | | INT123_absynth_1to1_i486(hybridOut[0][ss], 0, fr, n); |
2041 | | INT123_absynth_1to1_i486(hybridOut[1][ss], 1, fr, n); |
2042 | | ss+=n; |
2043 | | fr->buffer.fill+=(2*2*32)*n; |
2044 | | } |
2045 | | } |
2046 | | #endif |
2047 | 54.5k | } |
2048 | | |
2049 | 37.1k | return clip; |
2050 | 80.0k | } |