Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
wine-mirror
GitHub Repository: wine-mirror/wine
Path: blob/master/libs/mpg123/src/libmpg123/layer3.c
4394 views
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
{
88
if(!fr->p.down_sample) return DOUBLE_TO_REAL(16384.0 * pow((double)2.0,-0.25 * (double) (i+210) ));
89
else return DOUBLE_TO_REAL(pow((double)2.0,-0.25 * (double) (i+210)));
90
}
91
#endif
92
93
real INT123_init_layer3_gainpow2(mpg123_handle *fr, int i)
94
{
95
return DOUBLE_TO_REAL_SCALE_LAYER3(pow((double)2.0,-0.25 * (double) (i+210)),i+256);
96
}
97
98
void INT123_init_layer3_stuff(mpg123_handle *fr, real (*gainpow2_func)(mpg123_handle *fr, int i))
99
{
100
int i,j;
101
102
#ifdef REAL_IS_FIXED
103
fr->gainpow2 = gainpow2;
104
#else
105
for(i=-256;i<118+4;i++)
106
fr->gainpow2[i+256] = gainpow2_func(fr,i);
107
#endif
108
109
for(j=0;j<9;j++)
110
{
111
for(i=0;i<23;i++)
112
{
113
fr->longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1;
114
if(fr->longLimit[j][i] > (fr->down_sample_sblimit) )
115
fr->longLimit[j][i] = fr->down_sample_sblimit;
116
}
117
for(i=0;i<14;i++)
118
{
119
fr->shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1;
120
if(fr->shortLimit[j][i] > (fr->down_sample_sblimit) )
121
fr->shortLimit[j][i] = fr->down_sample_sblimit;
122
}
123
}
124
}
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
{
134
int ch, gr;
135
int powdiff = (single == SINGLE_MIX) ? 4 : 0;
136
137
const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } };
138
const int *tab = tabs[fr->hdr.lsf];
139
140
{ /* First ensure we got enough bits available. */
141
unsigned int needbits = 0;
142
needbits += tab[1]; /* main_data_begin */
143
needbits += stereo == 1 ? tab[2] : tab[3]; /* private */
144
if(!fr->hdr.lsf)
145
needbits += stereo*4; /* scfsi */
146
/* For each granule for each channel ... */
147
needbits += tab[0]*stereo*(29+tab[4]+1+22+(!fr->hdr.lsf?1:0)+2);
148
if(fr->bits_avail < needbits) \
149
{
150
if(NOQUIET)
151
error2( "%u bits for side info needed, only %li available"
152
, needbits, fr->bits_avail );
153
return 1;
154
}
155
}
156
157
si->main_data_begin = getbits(fr, tab[1]);
158
159
if(si->main_data_begin > fr->bitreservoir)
160
{
161
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
backbits(fr, tab[1]);
165
if(fr->hdr.lsf == 0)
166
{
167
fr->wordpointer[0] = (unsigned char) (fr->bitreservoir >> 1);
168
fr->wordpointer[1] = (unsigned char) ((fr->bitreservoir & 1) << 7);
169
}
170
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
memset(fr->wordpointer+2, 0, fr->hdr.ssize-2);
175
176
/* reread the new bit reservoir offset */
177
si->main_data_begin = getbits(fr, tab[1]);
178
}
179
180
/* Keep track of the available data bytes for the bit reservoir.
181
CRC is included in ssize already. */
182
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
if(fr->bitreservoir > (unsigned int) (fr->hdr.lsf == 0 ? 511 : 255))
186
fr->bitreservoir = (fr->hdr.lsf == 0 ? 511 : 255);
187
188
/* Now back into less commented territory. It's code. It works. */
189
190
if (stereo == 1)
191
si->private_bits = getbits(fr, tab[2]);
192
else
193
si->private_bits = getbits(fr, tab[3]);
194
195
if(!fr->hdr.lsf) for(ch=0; ch<stereo; ch++)
196
{
197
si->ch[ch].gr[0].scfsi = -1;
198
si->ch[ch].gr[1].scfsi = getbits(fr, 4);
199
}
200
201
for (gr=0; gr<tab[0]; gr++)
202
for (ch=0; ch<stereo; ch++)
203
{
204
register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
205
unsigned int qss;
206
gr_info->part2_3_length = getbits(fr, 12);
207
gr_info->big_values = getbits(fr, 9);
208
if(gr_info->big_values > 288)
209
{
210
if(NOQUIET) error("big_values too large!");
211
gr_info->big_values = 288;
212
}
213
qss = getbits_fast(fr, 8);
214
gr_info->pow2gain = fr->gainpow2+256 - qss + powdiff;
215
if(ms_stereo)
216
gr_info->pow2gain += 2;
217
#ifndef NO_MOREINFO
218
if(fr->pinfo)
219
fr->pinfo->qss[gr][ch] = qss;
220
#endif
221
gr_info->scalefac_compress = getbits(fr, tab[4]);
222
if(gr_info->part2_3_length == 0)
223
{
224
if(gr_info->scalefac_compress > 0 && VERBOSE2)
225
error1( "scalefac_compress should be zero instead of %i"
226
, gr_info->scalefac_compress );
227
gr_info->scalefac_compress = 0;
228
}
229
230
/* 22 bits for if/else block */
231
if(getbits(fr,1))
232
{ /* window switch flag */
233
int i;
234
gr_info->block_type = getbits_fast(fr, 2);
235
gr_info->mixed_block_flag = get1bit(fr);
236
gr_info->table_select[0] = getbits_fast(fr, 5);
237
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
gr_info->table_select[2] = 0;
243
for(i=0;i<3;i++)
244
{
245
unsigned int sbg = (getbits_fast(fr, 3)<<3);
246
gr_info->full_gain[i] = gr_info->pow2gain + sbg;
247
#ifndef NO_MOREINFO
248
if(fr->pinfo)
249
fr->pinfo->sub_gain[gr][ch][i] = sbg / 8;
250
#endif
251
}
252
253
if(gr_info->block_type == 0)
254
{
255
if(NOQUIET) error("Blocktype == 0 and window-switching == 1 not allowed.");
256
return 1;
257
}
258
259
/* region_count/start parameters are implicit in this case. */
260
if( (!fr->hdr.lsf || (gr_info->block_type == 2)) && !fr->hdr.mpeg25)
261
{
262
gr_info->region1start = 36>>1;
263
gr_info->region2start = 576>>1;
264
}
265
else
266
{
267
if(fr->hdr.mpeg25)
268
{
269
int r0c,r1c;
270
if((gr_info->block_type == 2) && (!gr_info->mixed_block_flag) ) r0c = 5;
271
else r0c = 7;
272
273
/* r0c+1+r1c+1 == 22, always. */
274
r1c = 20 - r0c;
275
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
276
gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
277
}
278
else
279
{
280
gr_info->region1start = 54>>1;
281
gr_info->region2start = 576>>1;
282
}
283
}
284
}
285
else
286
{
287
int i,r0c,r1c;
288
for (i=0; i<3; i++)
289
gr_info->table_select[i] = getbits_fast(fr, 5);
290
291
r0c = getbits_fast(fr, 4); /* 0 .. 15 */
292
r1c = getbits_fast(fr, 3); /* 0 .. 7 */
293
gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
294
295
/* max(r0c+r1c+2) = 15+7+2 = 24 */
296
if(r0c+1+r1c+1 > 22) gr_info->region2start = 576>>1;
297
else gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
298
299
gr_info->block_type = 0;
300
gr_info->mixed_block_flag = 0;
301
}
302
if(!fr->hdr.lsf) gr_info->preflag = get1bit(fr);
303
304
gr_info->scalefac_scale = get1bit(fr);
305
gr_info->count1table_select = get1bit(fr);
306
}
307
return 0;
308
}
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
{
314
const unsigned char slen[2][16] =
315
{
316
{0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
317
{0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
318
};
319
int numbits;
320
int num0 = slen[0][gr_info->scalefac_compress];
321
int num1 = slen[1][gr_info->scalefac_compress];
322
323
if(gr_info->block_type == 2)
324
{
325
int i=18;
326
numbits = (num0 + num1) * 18 /* num0 * (17+1?) + num1 * 18 */
327
- (gr_info->mixed_block_flag ? num0 : 0);
328
if(fr->bits_avail < numbits)
329
return -1;
330
331
if(gr_info->mixed_block_flag)
332
{
333
for (i=8;i;i--)
334
*scf++ = getbits_fast(fr, num0);
335
336
i = 9;
337
}
338
339
for(;i;i--) *scf++ = getbits_fast(fr, num0);
340
341
for(i = 18; i; i--) *scf++ = getbits_fast(fr, num1);
342
343
*scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
344
}
345
else
346
{
347
int i;
348
int scfsi = gr_info->scfsi;
349
350
if(scfsi < 0)
351
{ /* scfsi < 0 => granule == 0 */
352
numbits = (num0 + num1) * 10 + num0;
353
if(fr->bits_avail < numbits)
354
return -1;
355
356
for(i=11;i;i--) *scf++ = getbits_fast(fr, num0);
357
358
for(i=10;i;i--) *scf++ = getbits_fast(fr, num1);
359
360
*scf++ = 0;
361
}
362
else
363
{
364
numbits = !(scfsi & 0x8) * num0 * 6
365
+ !(scfsi & 0x4) * num0 * 5
366
+ !(scfsi & 0x2) * num1 * 5
367
+ !(scfsi & 0x1) * num1 * 5;
368
if(fr->bits_avail < numbits)
369
return -1;
370
371
if(!(scfsi & 0x8))
372
{
373
for (i=0;i<6;i++) *scf++ = getbits_fast(fr, num0);
374
}
375
else scf += 6;
376
377
if(!(scfsi & 0x4))
378
{
379
for (i=0;i<5;i++) *scf++ = getbits_fast(fr, num0);
380
}
381
else scf += 5;
382
383
if(!(scfsi & 0x2))
384
{
385
for(i=0;i<5;i++) *scf++ = getbits_fast(fr, num1);
386
}
387
else scf += 5;
388
389
if(!(scfsi & 0x1))
390
{
391
for (i=0;i<5;i++) *scf++ = getbits_fast(fr, num1);
392
}
393
else scf += 5;
394
395
*scf++ = 0; /* no l[21] in original sources */
396
}
397
}
398
399
return numbits;
400
}
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
{
405
const unsigned char *pnt;
406
int i,j,n=0,numbits=0;
407
unsigned int slen, slen2;
408
409
const unsigned char stab[3][6][4] =
410
{
411
{
412
{ 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0},
413
{ 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0}
414
},
415
{
416
{ 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0},
417
{12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0}
418
},
419
{
420
{ 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0},
421
{ 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0}
422
}
423
};
424
425
if(i_stereo) /* i_stereo AND second channel -> INT123_do_layer3() checks this */
426
slen = i_slen2[gr_info->scalefac_compress>>1];
427
else
428
slen = n_slen2[gr_info->scalefac_compress];
429
430
gr_info->preflag = (slen>>15) & 0x1;
431
432
n = 0;
433
if( gr_info->block_type == 2 )
434
{
435
n++;
436
if(gr_info->mixed_block_flag) n++;
437
}
438
439
pnt = stab[n][(slen>>12)&0x7];
440
441
slen2 = slen;
442
for(i=0;i<4;i++)
443
{
444
int num = slen2 & 0x7;
445
slen2 >>= 3;
446
if(num)
447
numbits += pnt[i] * num;
448
}
449
if(numbits > gr_info->part2_3_length)
450
return -1;
451
452
for(i=0;i<4;i++)
453
{
454
int num = slen & 0x7;
455
slen >>= 3;
456
if(num)
457
{
458
for(j=0;j<(int)(pnt[i]);j++) *scf++ = getbits_fast(fr, num);
459
}
460
else
461
for(j=0;j<(int)(pnt[i]);j++) *scf++ = 0;
462
}
463
464
n = (n << 1) + 1;
465
for(i=0;i<n;i++) *scf++ = 0;
466
467
return numbits;
468
}
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
#define MASK_STYPE int32_t
495
#define MASK_UTYPE uint32_t
496
#define MASK_TYPE MASK_UTYPE
497
#define MSB_MASK ((MASK_UTYPE)mask & (MASK_UTYPE)1<<(sizeof(MASK_TYPE)*8-1))
498
#endif
499
#define BITSHIFT ((sizeof(MASK_TYPE)-1)*8)
500
#define REFRESH_MASK \
501
while(num < BITSHIFT) { \
502
mask |= ((MASK_UTYPE)getbyte(fr))<<(BITSHIFT-num); \
503
num += 8; \
504
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
{
509
int shift = 1 + gr_info->scalefac_scale;
510
// Pointer cast to make pedantic compilers happy.
511
real *xrpnt = (real*)xr;
512
// Some compiler freaks out over &xr[SBLIMIT][0], which is the same.
513
real *xrpntlimit = (real*)xr+SBLIMIT*SSLIMIT;
514
int l[3],l3;
515
int part2remain = gr_info->part2_3_length - part2bits;
516
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
if(gr_info->part2_3_length > 0)
525
{
526
527
/* mhipp tree has this split up a bit... */
528
int num=getbitoffset(fr);
529
MASK_TYPE mask;
530
/* We must split this, because for num==0 the shift is undefined if you do it in one step. */
531
mask = ((MASK_UTYPE) getbits(fr, num))<<BITSHIFT;
532
mask <<= 8-num;
533
part2remain -= num;
534
535
/* Bitindex is zero now, we are allowed to use getbyte(). */
536
537
{
538
int bv = gr_info->big_values;
539
int region1 = gr_info->region1start;
540
int region2 = gr_info->region2start;
541
l3 = ((576>>1)-bv)>>1;
542
543
/* we may lose the 'odd' bit here !! check this later again */
544
if(bv <= region1)
545
{
546
l[0] = bv;
547
l[1] = 0;
548
l[2] = 0;
549
}
550
else
551
{
552
l[0] = region1;
553
if(bv <= region2)
554
{
555
l[1] = bv - l[0];
556
l[2] = 0;
557
}
558
else
559
{
560
l[1] = region2 - l[0];
561
l[2] = bv - region2;
562
}
563
}
564
}
565
566
#define CHECK_XRPNT if(xrpnt >= xrpntlimit) \
567
{ \
568
if(NOQUIET) \
569
error2("attempted xrpnt overflow (%p !< %p)", (void*) xrpnt, (void*) xrpntlimit); \
570
return 1; \
571
}
572
573
if(gr_info->block_type == 2)
574
{
575
/* decoding with short or mixed mode BandIndex table */
576
int i,max[4];
577
int step=0,lwin=3,cb=0;
578
register real v = 0.0;
579
register int mc;
580
register const short *m;
581
582
if(gr_info->mixed_block_flag)
583
{
584
max[3] = -1;
585
max[0] = max[1] = max[2] = 2;
586
m = map[sfreq][0];
587
me = mapend[sfreq][0];
588
}
589
else
590
{
591
max[0] = max[1] = max[2] = max[3] = -1;
592
/* max[3] not really needed in this case */
593
m = map[sfreq][1];
594
me = mapend[sfreq][1];
595
}
596
597
mc = 0;
598
for(i=0;i<2;i++)
599
{
600
int lp = l[i];
601
const struct newhuff *h = ht+gr_info->table_select[i];
602
for(;lp;lp--,mc--)
603
{
604
register MASK_STYPE x,y;
605
if( (!mc) )
606
{
607
mc = *m++;
608
//fprintf(stderr, "%i setting xrpnt = xr + %i (%ld)\n", __LINE__, *m, xrpnt-(real*)xr);
609
xrpnt = ((real *) xr) + (*m++);
610
lwin = *m++;
611
cb = *m++;
612
if(lwin == 3)
613
{
614
#ifdef REAL_IS_FIXED
615
gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2);
616
#endif
617
v = gr_info->pow2gain[(*scf++) << shift];
618
step = 1;
619
}
620
else
621
{
622
#ifdef REAL_IS_FIXED
623
gainpow2_scale_idx = (int)(gr_info->full_gain[lwin] + (*scf << shift) - fr->gainpow2);
624
#endif
625
v = gr_info->full_gain[lwin][(*scf++) << shift];
626
step = 3;
627
}
628
}
629
{
630
const short *val = h->table;
631
REFRESH_MASK;
632
#ifdef USE_NEW_HUFFTABLE
633
while((y=val[(MASK_UTYPE)mask>>(BITSHIFT+4)])<0)
634
{
635
val -= y;
636
num -= 4;
637
mask <<= 4;
638
}
639
num -= (y >> 8);
640
mask <<= (y >> 8);
641
x = (y >> 4) & 0xf;
642
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
}
655
CHECK_XRPNT;
656
if(x == 15 && h->linbits)
657
{
658
max[lwin] = cb;
659
REFRESH_MASK;
660
x += ((MASK_UTYPE) mask) >> (BITSHIFT+8-h->linbits);
661
num -= h->linbits+1;
662
mask <<= h->linbits;
663
if(MSB_MASK) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx);
664
else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx);
665
666
mask <<= 1;
667
}
668
else if(x)
669
{
670
max[lwin] = cb;
671
if(MSB_MASK) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx);
672
else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx);
673
674
num--;
675
mask <<= 1;
676
}
677
else *xrpnt = DOUBLE_TO_REAL(0.0);
678
679
xrpnt += step;
680
CHECK_XRPNT;
681
if(y == 15 && h->linbits)
682
{
683
max[lwin] = cb;
684
REFRESH_MASK;
685
y += ((MASK_UTYPE) mask) >> (BITSHIFT+8-h->linbits);
686
num -= h->linbits+1;
687
mask <<= h->linbits;
688
if(MSB_MASK) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx);
689
else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx);
690
691
mask <<= 1;
692
}
693
else if(y)
694
{
695
max[lwin] = cb;
696
if(MSB_MASK) *xrpnt = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx);
697
else *xrpnt = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx);
698
699
num--;
700
mask <<= 1;
701
}
702
else *xrpnt = DOUBLE_TO_REAL(0.0);
703
704
xrpnt += step;
705
}
706
}
707
708
for(;l3 && (part2remain+num > 0);l3--)
709
{
710
const struct newhuff* h;
711
const short* val;
712
register short a;
713
714
h = htc+gr_info->count1table_select;
715
val = h->table;
716
717
REFRESH_MASK;
718
while((a=*val++)<0)
719
{
720
if(MSB_MASK) val -= a;
721
722
num--;
723
mask <<= 1;
724
}
725
if(part2remain+num <= 0)
726
{
727
num -= part2remain+num;
728
break;
729
}
730
731
for(i=0;i<4;i++)
732
{
733
if(!(i & 1))
734
{
735
if(!mc)
736
{
737
mc = *m++;
738
//fprintf(stderr, "%i setting xrpnt = xr + %i (%ld)\n", __LINE__, *m, xrpnt-(real*)xr);
739
xrpnt = ((real *) xr) + (*m++);
740
lwin = *m++;
741
cb = *m++;
742
if(lwin == 3)
743
{
744
#ifdef REAL_IS_FIXED
745
gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2);
746
#endif
747
v = gr_info->pow2gain[(*scf++) << shift];
748
step = 1;
749
}
750
else
751
{
752
#ifdef REAL_IS_FIXED
753
gainpow2_scale_idx = (int)(gr_info->full_gain[lwin] + (*scf << shift) - fr->gainpow2);
754
#endif
755
v = gr_info->full_gain[lwin][(*scf++) << shift];
756
step = 3;
757
}
758
}
759
mc--;
760
}
761
CHECK_XRPNT;
762
if( (a & (0x8>>i)) )
763
{
764
max[lwin] = cb;
765
if(part2remain+num <= 0)
766
break;
767
768
if(MSB_MASK) *xrpnt = -REAL_SCALE_LAYER3(v, gainpow2_scale_idx);
769
else *xrpnt = REAL_SCALE_LAYER3(v, gainpow2_scale_idx);
770
771
num--;
772
mask <<= 1;
773
}
774
else *xrpnt = DOUBLE_TO_REAL(0.0);
775
776
xrpnt += step;
777
}
778
}
779
780
if(lwin < 3)
781
{ /* short band? */
782
while(1)
783
{
784
for(;mc > 0;mc--)
785
{
786
CHECK_XRPNT;
787
*xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3; /* short band -> step=3 */
788
*xrpnt = DOUBLE_TO_REAL(0.0); xrpnt += 3;
789
}
790
if(m >= me)
791
break;
792
793
mc = *m++;
794
xrpnt = ((real *) xr) + *m++;
795
if(*m++ == 0)
796
break; /* optimize: field will be set to zero at the end of the function */
797
798
m++; /* cb */
799
}
800
}
801
802
gr_info->maxband[0] = max[0]+1;
803
gr_info->maxband[1] = max[1]+1;
804
gr_info->maxband[2] = max[2]+1;
805
gr_info->maxbandl = max[3]+1;
806
807
{
808
int rmax = max[0] > max[1] ? max[0] : max[1];
809
rmax = (rmax > max[2] ? rmax : max[2]) + 1;
810
gr_info->maxb = rmax ? fr->shortLimit[sfreq][rmax] : fr->longLimit[sfreq][max[3]+1];
811
}
812
813
}
814
else
815
{
816
/* decoding with 'long' BandIndex table (block_type != 2) */
817
const unsigned char *pretab = pretab_choice[gr_info->preflag];
818
int i,max = -1;
819
int cb = 0;
820
const short *m = map[sfreq][2];
821
register real v = 0.0;
822
int mc = 0;
823
824
/* long hash table values */
825
for(i=0;i<3;i++)
826
{
827
int lp = l[i];
828
const struct newhuff *h = ht+gr_info->table_select[i];
829
830
for(;lp;lp--,mc--)
831
{
832
MASK_STYPE x,y;
833
if(!mc)
834
{
835
mc = *m++;
836
cb = *m++;
837
#ifdef CUT_SFB21
838
if(cb == 21)
839
v = 0.0;
840
else
841
#endif
842
{
843
#ifdef REAL_IS_FIXED
844
gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2);
845
#endif
846
v = gr_info->pow2gain[(*(scf++) + (*pretab++)) << shift];
847
}
848
}
849
{
850
const short *val = h->table;
851
REFRESH_MASK;
852
#ifdef USE_NEW_HUFFTABLE
853
while((y=val[(MASK_UTYPE)mask>>(BITSHIFT+4)])<0)
854
{
855
val -= y;
856
num -= 4;
857
mask <<= 4;
858
}
859
num -= (y >> 8);
860
mask <<= (y >> 8);
861
x = (y >> 4) & 0xf;
862
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
}
875
876
CHECK_XRPNT;
877
if(x == 15 && h->linbits)
878
{
879
max = cb;
880
REFRESH_MASK;
881
x += ((MASK_UTYPE) mask) >> (BITSHIFT+8-h->linbits);
882
num -= h->linbits+1;
883
mask <<= h->linbits;
884
if(MSB_MASK) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx);
885
else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx);
886
887
mask <<= 1;
888
}
889
else if(x)
890
{
891
max = cb;
892
if(MSB_MASK) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[x], v, gainpow2_scale_idx);
893
else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[x], v, gainpow2_scale_idx);
894
num--;
895
896
mask <<= 1;
897
}
898
else *xrpnt++ = DOUBLE_TO_REAL(0.0);
899
900
CHECK_XRPNT;
901
if(y == 15 && h->linbits)
902
{
903
max = cb;
904
REFRESH_MASK;
905
y += ((MASK_UTYPE) mask) >> (BITSHIFT+8-h->linbits);
906
num -= h->linbits+1;
907
mask <<= h->linbits;
908
if(MSB_MASK) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx);
909
else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx);
910
911
mask <<= 1;
912
}
913
else if(y)
914
{
915
max = cb;
916
if(MSB_MASK) *xrpnt++ = REAL_MUL_SCALE_LAYER3(-ispow[y], v, gainpow2_scale_idx);
917
else *xrpnt++ = REAL_MUL_SCALE_LAYER3( ispow[y], v, gainpow2_scale_idx);
918
919
num--;
920
mask <<= 1;
921
}
922
else *xrpnt++ = DOUBLE_TO_REAL(0.0);
923
}
924
}
925
926
/* short (count1table) values */
927
for(;l3 && (part2remain+num > 0);l3--)
928
{
929
const struct newhuff *h = htc+gr_info->count1table_select;
930
const short *val = h->table;
931
register short a;
932
933
REFRESH_MASK;
934
while((a=*val++)<0)
935
{
936
if (MSB_MASK) val -= a;
937
938
num--;
939
mask <<= 1;
940
}
941
if(part2remain+num <= 0)
942
{
943
num -= part2remain+num;
944
break;
945
}
946
947
for(i=0;i<4;i++)
948
{
949
if(!(i & 1))
950
{
951
if(!mc)
952
{
953
mc = *m++;
954
cb = *m++;
955
#ifdef CUT_SFB21
956
if(cb == 21)
957
v = 0.0;
958
else
959
#endif
960
{
961
#ifdef REAL_IS_FIXED
962
gainpow2_scale_idx = (int)(gr_info->pow2gain + (*scf << shift) - fr->gainpow2);
963
#endif
964
v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
965
}
966
}
967
mc--;
968
}
969
CHECK_XRPNT;
970
if( (a & (0x8>>i)) )
971
{
972
max = cb;
973
if(part2remain+num <= 0)
974
break;
975
976
if(MSB_MASK) *xrpnt++ = -REAL_SCALE_LAYER3(v, gainpow2_scale_idx);
977
else *xrpnt++ = REAL_SCALE_LAYER3(v, gainpow2_scale_idx);
978
979
num--;
980
mask <<= 1;
981
}
982
else *xrpnt++ = DOUBLE_TO_REAL(0.0);
983
}
984
}
985
986
gr_info->maxbandl = max+1;
987
gr_info->maxb = fr->longLimit[sfreq][gr_info->maxbandl];
988
}
989
990
part2remain += num;
991
backbits(fr, num);
992
num = 0;
993
994
}
995
else
996
{
997
part2remain = 0;
998
/* Not entirely sure what good values are, must be > 0. */
999
gr_info->maxband[0] =
1000
gr_info->maxband[1] =
1001
gr_info->maxband[2] =
1002
gr_info->maxbandl = 1; /* sfb=maxband[lwin]*3 + lwin - mixed_block_flag must be >= 0 */
1003
gr_info->maxb = 1;
1004
}
1005
1006
while(xrpnt < xrpntlimit)
1007
*xrpnt++ = DOUBLE_TO_REAL(0.0);
1008
1009
while( part2remain > 16 )
1010
{
1011
skipbits(fr, 16); /* Dismiss stuffing Bits */
1012
part2remain -= 16;
1013
}
1014
if(part2remain > 0) skipbits(fr, part2remain);
1015
else if(part2remain < 0)
1016
{
1017
if(VERBOSE2)
1018
error1("Can't rewind stream by %d bits!",-part2remain);
1019
return 1; /* -> error */
1020
}
1021
return 0;
1022
}
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
{
1028
real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf;
1029
const struct bandInfoStruct *bi = &bandInfo[sfreq];
1030
1031
const real *tab1,*tab2;
1032
1033
#if 1
1034
int tab;
1035
/* TODO: optimize as static */
1036
const real *tabs[3][2][2] =
1037
{
1038
{ { tan1_1,tan2_1 } , { tan1_2,tan2_2 } },
1039
{ { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } },
1040
{ { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } }
1041
};
1042
1043
tab = lsf + (gr_info->scalefac_compress & lsf);
1044
tab1 = tabs[tab][ms_stereo][0];
1045
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
if(gr_info->block_type == 2)
1077
{
1078
int lwin,do_l = 0;
1079
if( gr_info->mixed_block_flag ) do_l = 1;
1080
1081
for(lwin=0;lwin<3;lwin++)
1082
{ /* process each window */
1083
/* get first band with zero values */
1084
int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */
1085
if(sfb > 3) do_l = 0;
1086
1087
for(;sfb<12;sfb++)
1088
{
1089
is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
1090
if(is_p != 7)
1091
{
1092
real t1,t2;
1093
sb = bi->shortDiff[sfb];
1094
idx = bi->shortIdx[sfb] + lwin;
1095
t1 = tab1[is_p]; t2 = tab2[is_p];
1096
for (; sb > 0; sb--,idx+=3)
1097
{
1098
real v = xr[0][idx];
1099
xr[0][idx] = REAL_MUL_15(v, t1);
1100
xr[1][idx] = REAL_MUL_15(v, t2);
1101
}
1102
}
1103
}
1104
1105
#if 1
1106
/* in the original: copy 10 to 11 , here: copy 11 to 12
1107
maybe still wrong??? (copy 12 to 13?) */
1108
is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
1109
sb = bi->shortDiff[12];
1110
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
if(is_p != 7)
1117
{
1118
real t1,t2;
1119
t1 = tab1[is_p]; t2 = tab2[is_p];
1120
for( ; sb > 0; sb--,idx+=3 )
1121
{
1122
real v = xr[0][idx];
1123
xr[0][idx] = REAL_MUL_15(v, t1);
1124
xr[1][idx] = REAL_MUL_15(v, t2);
1125
}
1126
}
1127
} /* end for(lwin; .. ; . ) */
1128
1129
/* also check l-part, if ALL bands in the three windows are 'empty' and mode = mixed_mode */
1130
if(do_l)
1131
{
1132
int sfb = gr_info->maxbandl;
1133
int idx;
1134
if(sfb > 21) return; /* similarity fix related to CVE-2006-1655 */
1135
1136
idx = bi->longIdx[sfb];
1137
for( ; sfb<8; sfb++ )
1138
{
1139
int sb = bi->longDiff[sfb];
1140
int is_p = scalefac[sfb]; /* scale: 0-15 */
1141
if(is_p != 7)
1142
{
1143
real t1,t2;
1144
t1 = tab1[is_p]; t2 = tab2[is_p];
1145
for( ; sb > 0; sb--,idx++)
1146
{
1147
real v = xr[0][idx];
1148
xr[0][idx] = REAL_MUL_15(v, t1);
1149
xr[1][idx] = REAL_MUL_15(v, t2);
1150
}
1151
}
1152
else idx += sb;
1153
}
1154
}
1155
}
1156
else
1157
{ /* ((gr_info->block_type != 2)) */
1158
int sfb = gr_info->maxbandl;
1159
int is_p,idx;
1160
if(sfb > 21) return; /* tightened fix for CVE-2006-1655 */
1161
1162
idx = bi->longIdx[sfb];
1163
for ( ; sfb<21; sfb++)
1164
{
1165
int sb = bi->longDiff[sfb];
1166
is_p = scalefac[sfb]; /* scale: 0-15 */
1167
if(is_p != 7)
1168
{
1169
real t1,t2;
1170
t1 = tab1[is_p]; t2 = tab2[is_p];
1171
for( ; sb > 0; sb--,idx++)
1172
{
1173
real v = xr[0][idx];
1174
xr[0][idx] = REAL_MUL_15(v, t1);
1175
xr[1][idx] = REAL_MUL_15(v, t2);
1176
}
1177
}
1178
else idx += sb;
1179
}
1180
1181
is_p = scalefac[20];
1182
if(is_p != 7)
1183
{ /* copy l-band 20 to l-band 21 */
1184
int sb;
1185
real t1 = tab1[is_p],t2 = tab2[is_p];
1186
1187
for( sb = bi->longDiff[21]; sb > 0; sb--,idx++ )
1188
{
1189
real v = xr[0][idx];
1190
xr[0][idx] = REAL_MUL_15(v, t1);
1191
xr[1][idx] = REAL_MUL_15(v, t2);
1192
}
1193
}
1194
}
1195
}
1196
1197
1198
static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info)
1199
{
1200
int sblim;
1201
1202
if(gr_info->block_type == 2)
1203
{
1204
if(!gr_info->mixed_block_flag) return;
1205
1206
sblim = 1;
1207
}
1208
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
{
1214
int sb;
1215
real *xr1=(real *) xr[1];
1216
1217
for(sb=sblim; sb; sb--,xr1+=10)
1218
{
1219
int ss;
1220
const real *cs=aa_cs,*ca=aa_ca;
1221
real *xr2 = xr1;
1222
1223
for(ss=7;ss>=0;ss--)
1224
{ /* upper and lower butterfly inputs */
1225
register real bu = *--xr2,bd = *xr1;
1226
*xr2 = REAL_MUL(bu, *cs) - REAL_MUL(bd, *ca);
1227
*xr1++ = REAL_MUL(bd, *cs++) + REAL_MUL(bu, *ca++);
1228
}
1229
}
1230
}
1231
}
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
{
1269
real tmp[18];
1270
1271
{
1272
register real *in = inbuf;
1273
1274
in[17]+=in[16]; in[16]+=in[15]; in[15]+=in[14];
1275
in[14]+=in[13]; in[13]+=in[12]; in[12]+=in[11];
1276
in[11]+=in[10]; in[10]+=in[9]; in[9] +=in[8];
1277
in[8] +=in[7]; in[7] +=in[6]; in[6] +=in[5];
1278
in[5] +=in[4]; in[4] +=in[3]; in[3] +=in[2];
1279
in[2] +=in[1]; in[1] +=in[0];
1280
1281
in[17]+=in[15]; in[15]+=in[13]; in[13]+=in[11]; in[11]+=in[9];
1282
in[9] +=in[7]; in[7] +=in[5]; in[5] +=in[3]; in[3] +=in[1];
1283
1284
#if 1
1285
{
1286
real t3;
1287
{
1288
real t0, t1, t2;
1289
1290
t0 = REAL_MUL(COS6_2, (in[8] + in[16] - in[4]));
1291
t1 = REAL_MUL(COS6_2, in[12]);
1292
1293
t3 = in[0];
1294
t2 = t3 - t1 - t1;
1295
tmp[1] = tmp[7] = t2 - t0;
1296
tmp[4] = t2 + t0 + t0;
1297
t3 += t1;
1298
1299
t2 = REAL_MUL(COS6_1, (in[10] + in[14] - in[2]));
1300
tmp[1] -= t2;
1301
tmp[7] += t2;
1302
}
1303
{
1304
real t0, t1, t2;
1305
1306
t0 = REAL_MUL(cos9[0], (in[4] + in[8] ));
1307
t1 = REAL_MUL(cos9[1], (in[8] - in[16]));
1308
t2 = REAL_MUL(cos9[2], (in[4] + in[16]));
1309
1310
tmp[2] = tmp[6] = t3 - t0 - t2;
1311
tmp[0] = tmp[8] = t3 + t0 + t1;
1312
tmp[3] = tmp[5] = t3 - t1 + t2;
1313
}
1314
}
1315
{
1316
real t1, t2, t3;
1317
1318
t1 = REAL_MUL(cos18[0], (in[2] + in[10]));
1319
t2 = REAL_MUL(cos18[1], (in[10] - in[14]));
1320
t3 = REAL_MUL(COS6_1, in[6]);
1321
1322
{
1323
real t0 = t1 + t2 + t3;
1324
tmp[0] += t0;
1325
tmp[8] -= t0;
1326
}
1327
1328
t2 -= t3;
1329
t1 -= t3;
1330
1331
t3 = REAL_MUL(cos18[2], (in[2] + in[14]));
1332
1333
t1 += t3;
1334
tmp[3] += t1;
1335
tmp[5] -= t1;
1336
1337
t2 -= t3;
1338
tmp[2] += t2;
1339
tmp[6] -= t2;
1340
}
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
{
1387
real t0, t1, t2, t3, t4, t5, t6, t7;
1388
1389
t1 = REAL_MUL(COS6_2, in[13]);
1390
t2 = REAL_MUL(COS6_2, (in[9] + in[17] - in[5]));
1391
1392
t3 = in[1] + t1;
1393
t4 = in[1] - t1 - t1;
1394
t5 = t4 - t2;
1395
1396
t0 = REAL_MUL(cos9[0], (in[5] + in[9]));
1397
t1 = REAL_MUL(cos9[1], (in[9] - in[17]));
1398
1399
tmp[13] = REAL_MUL((t4 + t2 + t2), INT123_tfcos36[17-13]);
1400
t2 = REAL_MUL(cos9[2], (in[5] + in[17]));
1401
1402
t6 = t3 - t0 - t2;
1403
t0 += t3 + t1;
1404
t3 += t2 - t1;
1405
1406
t2 = REAL_MUL(cos18[0], (in[3] + in[11]));
1407
t4 = REAL_MUL(cos18[1], (in[11] - in[15]));
1408
t7 = REAL_MUL(COS6_1, in[7]);
1409
1410
t1 = t2 + t4 + t7;
1411
tmp[17] = REAL_MUL((t0 + t1), INT123_tfcos36[17-17]);
1412
tmp[9] = REAL_MUL((t0 - t1), INT123_tfcos36[17-9]);
1413
t1 = REAL_MUL(cos18[2], (in[3] + in[15]));
1414
t2 += t1 - t7;
1415
1416
tmp[14] = REAL_MUL((t3 + t2), INT123_tfcos36[17-14]);
1417
t0 = REAL_MUL(COS6_1, (in[11] + in[15] - in[3]));
1418
tmp[12] = REAL_MUL((t3 - t2), INT123_tfcos36[17-12]);
1419
1420
t4 -= t1 + t7;
1421
1422
tmp[16] = REAL_MUL((t5 - t0), INT123_tfcos36[17-16]);
1423
tmp[10] = REAL_MUL((t5 + t0), INT123_tfcos36[17-10]);
1424
tmp[15] = REAL_MUL((t6 + t4), INT123_tfcos36[17-15]);
1425
tmp[11] = REAL_MUL((t6 - t4), INT123_tfcos36[17-11]);
1426
}
1427
1428
#define MACRO(v) { \
1429
real tmpval; \
1430
tmpval = tmp[(v)] + tmp[17-(v)]; \
1431
out2[9+(v)] = REAL_MUL(tmpval, w[27+(v)]); \
1432
out2[8-(v)] = REAL_MUL(tmpval, w[26-(v)]); \
1433
tmpval = tmp[(v)] - tmp[17-(v)]; \
1434
ts[SBLIMIT*(8-(v))] = out1[8-(v)] + REAL_MUL(tmpval, w[8-(v)]); \
1435
ts[SBLIMIT*(9+(v))] = out1[9+(v)] + REAL_MUL(tmpval, w[9+(v)]); }
1436
1437
{
1438
register real *out2 = o2;
1439
register const real *w = wintab;
1440
register real *out1 = o1;
1441
register real *ts = tsbuf;
1442
1443
MACRO(0);
1444
MACRO(1);
1445
MACRO(2);
1446
MACRO(3);
1447
MACRO(4);
1448
MACRO(5);
1449
MACRO(6);
1450
MACRO(7);
1451
MACRO(8);
1452
}
1453
1454
}
1455
}
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
static void asmfunc ## _wrap(real *inbuf,real *o1,real *o2,const real *wintab,real *tsbuf) \
1468
{ \
1469
asmfunc(inbuf, o1, o2, wintab, tsbuf); \
1470
}
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
{
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
return 0;
1509
}
1510
1511
void INT123_dct36_choose(mpg123_handle *fr)
1512
{
1513
switch(fr->cpu_opts.type)
1514
{
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
#ifdef OPT_AVX
1531
case avx:
1532
fr->cpu_opts.the_dct36 = INT123_dct36_avx_wrap;
1533
break;
1534
#endif
1535
#ifdef OPT_X86_64
1536
case x86_64:
1537
fr->cpu_opts.the_dct36 = INT123_dct36_x86_64_wrap;
1538
break;
1539
#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
default:
1551
fr->cpu_opts.the_dct36 = INT123_dct36;
1552
}
1553
}
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
{
1560
#define DCT12_PART1 \
1561
in5 = in[5*3]; \
1562
in5 += (in4 = in[4*3]); \
1563
in4 += (in3 = in[3*3]); \
1564
in3 += (in2 = in[2*3]); \
1565
in2 += (in1 = in[1*3]); \
1566
in1 += (in0 = in[0*3]); \
1567
\
1568
in5 += in3; in3 += in1; \
1569
\
1570
in2 = REAL_MUL(in2, COS6_1); \
1571
in3 = REAL_MUL(in3, COS6_1);
1572
1573
#define DCT12_PART2 \
1574
in0 += REAL_MUL(in4, COS6_2); \
1575
\
1576
in4 = in0 + in2; \
1577
in0 -= in2; \
1578
\
1579
in1 += REAL_MUL(in5, COS6_2); \
1580
\
1581
in5 = REAL_MUL((in1 + in3), tfcos12[0]); \
1582
in1 = REAL_MUL((in1 - in3), tfcos12[2]); \
1583
\
1584
in3 = in4 + in5; \
1585
in4 -= in5; \
1586
\
1587
in2 = in0 + in1; \
1588
in0 -= in1;
1589
1590
{
1591
real in0,in1,in2,in3,in4,in5;
1592
register real *out1 = rawout1;
1593
ts[SBLIMIT*0] = out1[0]; ts[SBLIMIT*1] = out1[1]; ts[SBLIMIT*2] = out1[2];
1594
ts[SBLIMIT*3] = out1[3]; ts[SBLIMIT*4] = out1[4]; ts[SBLIMIT*5] = out1[5];
1595
1596
DCT12_PART1
1597
1598
{
1599
real tmp0,tmp1 = (in0 - in4);
1600
{
1601
real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]);
1602
tmp0 = tmp1 + tmp2;
1603
tmp1 -= tmp2;
1604
}
1605
ts[(17-1)*SBLIMIT] = out1[17-1] + REAL_MUL(tmp0, wi[11-1]);
1606
ts[(12+1)*SBLIMIT] = out1[12+1] + REAL_MUL(tmp0, wi[6+1]);
1607
ts[(6 +1)*SBLIMIT] = out1[6 +1] + REAL_MUL(tmp1, wi[1]);
1608
ts[(11-1)*SBLIMIT] = out1[11-1] + REAL_MUL(tmp1, wi[5-1]);
1609
}
1610
1611
DCT12_PART2
1612
1613
ts[(17-0)*SBLIMIT] = out1[17-0] + REAL_MUL(in2, wi[11-0]);
1614
ts[(12+0)*SBLIMIT] = out1[12+0] + REAL_MUL(in2, wi[6+0]);
1615
ts[(12+2)*SBLIMIT] = out1[12+2] + REAL_MUL(in3, wi[6+2]);
1616
ts[(17-2)*SBLIMIT] = out1[17-2] + REAL_MUL(in3, wi[11-2]);
1617
1618
ts[(6 +0)*SBLIMIT] = out1[6+0] + REAL_MUL(in0, wi[0]);
1619
ts[(11-0)*SBLIMIT] = out1[11-0] + REAL_MUL(in0, wi[5-0]);
1620
ts[(6 +2)*SBLIMIT] = out1[6+2] + REAL_MUL(in4, wi[2]);
1621
ts[(11-2)*SBLIMIT] = out1[11-2] + REAL_MUL(in4, wi[5-2]);
1622
}
1623
1624
in++;
1625
1626
{
1627
real in0,in1,in2,in3,in4,in5;
1628
register real *out2 = rawout2;
1629
1630
DCT12_PART1
1631
1632
{
1633
real tmp0,tmp1 = (in0 - in4);
1634
{
1635
real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]);
1636
tmp0 = tmp1 + tmp2;
1637
tmp1 -= tmp2;
1638
}
1639
out2[5-1] = REAL_MUL(tmp0, wi[11-1]);
1640
out2[0+1] = REAL_MUL(tmp0, wi[6+1]);
1641
ts[(12+1)*SBLIMIT] += REAL_MUL(tmp1, wi[1]);
1642
ts[(17-1)*SBLIMIT] += REAL_MUL(tmp1, wi[5-1]);
1643
}
1644
1645
DCT12_PART2
1646
1647
out2[5-0] = REAL_MUL(in2, wi[11-0]);
1648
out2[0+0] = REAL_MUL(in2, wi[6+0]);
1649
out2[0+2] = REAL_MUL(in3, wi[6+2]);
1650
out2[5-2] = REAL_MUL(in3, wi[11-2]);
1651
1652
ts[(12+0)*SBLIMIT] += REAL_MUL(in0, wi[0]);
1653
ts[(17-0)*SBLIMIT] += REAL_MUL(in0, wi[5-0]);
1654
ts[(12+2)*SBLIMIT] += REAL_MUL(in4, wi[2]);
1655
ts[(17-2)*SBLIMIT] += REAL_MUL(in4, wi[5-2]);
1656
}
1657
1658
in++;
1659
1660
{
1661
real in0,in1,in2,in3,in4,in5;
1662
register real *out2 = rawout2;
1663
out2[12]=out2[13]=out2[14]=out2[15]=out2[16]=out2[17]=0.0;
1664
1665
DCT12_PART1
1666
1667
{
1668
real tmp0,tmp1 = (in0 - in4);
1669
{
1670
real tmp2 = REAL_MUL((in1 - in5), tfcos12[1]);
1671
tmp0 = tmp1 + tmp2;
1672
tmp1 -= tmp2;
1673
}
1674
out2[11-1] = REAL_MUL(tmp0, wi[11-1]);
1675
out2[6 +1] = REAL_MUL(tmp0, wi[6+1]);
1676
out2[0+1] += REAL_MUL(tmp1, wi[1]);
1677
out2[5-1] += REAL_MUL(tmp1, wi[5-1]);
1678
}
1679
1680
DCT12_PART2
1681
1682
out2[11-0] = REAL_MUL(in2, wi[11-0]);
1683
out2[6 +0] = REAL_MUL(in2, wi[6+0]);
1684
out2[6 +2] = REAL_MUL(in3, wi[6+2]);
1685
out2[11-2] = REAL_MUL(in3, wi[11-2]);
1686
1687
out2[0+0] += REAL_MUL(in0, wi[0]);
1688
out2[5-0] += REAL_MUL(in0, wi[5-0]);
1689
out2[0+2] += REAL_MUL(in4, wi[2]);
1690
out2[5-2] += REAL_MUL(in4, wi[5-2]);
1691
}
1692
}
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
{
1697
real (*block)[2][SBLIMIT*SSLIMIT] = fr->hybrid_block;
1698
int *blc = fr->hybrid_blc;
1699
1700
real *tspnt = (real *) tsOut;
1701
real *rawout1,*rawout2;
1702
int bt = 0;
1703
size_t sb = 0;
1704
1705
{
1706
int b = blc[ch];
1707
rawout1=block[b][ch];
1708
b=-b+1;
1709
rawout2=block[b][ch];
1710
blc[ch] = b;
1711
}
1712
1713
if(gr_info->mixed_block_flag)
1714
{
1715
sb = 2;
1716
opt_dct36(fr)(fsIn[0],rawout1,rawout2,win[0],tspnt);
1717
opt_dct36(fr)(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1);
1718
rawout1 += 36; rawout2 += 36; tspnt += 2;
1719
}
1720
1721
bt = gr_info->block_type;
1722
if(bt == 2)
1723
{
1724
for(; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36)
1725
{
1726
dct12(fsIn[sb] ,rawout1 ,rawout2 ,win[2] ,tspnt);
1727
dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1);
1728
}
1729
}
1730
else
1731
{
1732
for(; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36)
1733
{
1734
opt_dct36(fr)(fsIn[sb],rawout1,rawout2,win[bt],tspnt);
1735
opt_dct36(fr)(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1);
1736
}
1737
}
1738
1739
for(;sb<SBLIMIT;sb++,tspnt++)
1740
{
1741
int i;
1742
for(i=0;i<SSLIMIT;i++)
1743
{
1744
tspnt[i*SBLIMIT] = *rawout1++;
1745
*rawout2++ = DOUBLE_TO_REAL(0.0);
1746
}
1747
}
1748
}
1749
1750
#ifndef NO_MOREINFO
1751
static void fill_pinfo_side(mpg123_handle *fr, struct III_sideinfo *si, int gr, int stereo1)
1752
{
1753
int i, sb;
1754
float ifqstep; /* Why not double? */
1755
int ch, ss;
1756
1757
for(ch = 0; ch < stereo1; ++ch)
1758
{
1759
struct gr_info_s *gr_infos = &(si->ch[ch].gr[gr]);
1760
fr->pinfo->big_values[gr][ch] = gr_infos->big_values;
1761
fr->pinfo->scalefac_scale[gr][ch] = gr_infos->scalefac_scale;
1762
fr->pinfo->mixed[gr][ch] = gr_infos->mixed_block_flag;
1763
fr->pinfo->blocktype[gr][ch] = gr_infos->block_type;
1764
fr->pinfo->mainbits[gr][ch] = gr_infos->part2_3_length;
1765
fr->pinfo->preflag[gr][ch] = gr_infos->preflag;
1766
if(gr == 1)
1767
fr->pinfo->scfsi[ch] = gr_infos->scfsi;
1768
}
1769
1770
for(ch = 0; ch < stereo1; ++ch)
1771
{
1772
struct gr_info_s *gr_infos = &(si->ch[ch].gr[gr]);
1773
ifqstep = (fr->pinfo->scalefac_scale[gr][ch] == 0) ? .5 : 1.0;
1774
if(2 == gr_infos->block_type)
1775
{
1776
for(i = 0; i < 3; ++i)
1777
{
1778
for(sb = 0; sb < 12; ++sb)
1779
{
1780
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
fr->pinfo->sfb_s[gr][ch][j] = -ifqstep *
1786
fr->pinfo->sfb_s[gr][ch][j - gr_infos->mixed_block_flag];
1787
fr->pinfo->sfb_s[gr][ch][j] -= 2 *
1788
(fr->pinfo->sub_gain[gr][ch][i]);
1789
}
1790
fr->pinfo->sfb_s[gr][ch][3 * sb + i] =
1791
-2 * (fr->pinfo->sub_gain[gr][ch][i]);
1792
}
1793
} else
1794
{
1795
for(sb = 0; sb < 21; ++sb)
1796
{
1797
/* scalefac was copied into pinfo->sfb[] before */
1798
fr->pinfo->sfb[gr][ch][sb] = fr->pinfo->sfb_s[gr][ch][sb];
1799
if (gr_infos->preflag)
1800
fr->pinfo->sfb[gr][ch][sb] += pretab_choice[1][sb];
1801
fr->pinfo->sfb[gr][ch][sb] *= -ifqstep;
1802
}
1803
fr->pinfo->sfb[gr][ch][21] = 0;
1804
}
1805
}
1806
1807
1808
for(ch = 0; ch < stereo1; ++ch)
1809
{
1810
int j = 0;
1811
for(sb = 0; sb < SBLIMIT; ++sb)
1812
for (ss = 0; ss < SSLIMIT; ++ss, ++j)
1813
fr->pinfo->xr[gr][ch][j] = fr->layer3.hybrid_in[ch][sb][ss];
1814
}
1815
}
1816
#endif
1817
1818
/* And at the end... the main layer3 handler */
1819
int INT123_do_layer3(mpg123_handle *fr)
1820
{
1821
int gr, ch, ss,clip=0;
1822
int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
1823
struct III_sideinfo sideinfo;
1824
int stereo = fr->stereo;
1825
int single = fr->single;
1826
int ms_stereo,i_stereo;
1827
int sfreq = fr->hdr.sampling_frequency;
1828
int stereo1,granules;
1829
1830
if(stereo == 1)
1831
{ /* stream is mono */
1832
stereo1 = 1;
1833
single = SINGLE_LEFT;
1834
}
1835
else if(single != SINGLE_STEREO) /* stream is stereo, but force to mono */
1836
stereo1 = 1;
1837
else
1838
stereo1 = 2;
1839
1840
if(fr->hdr.mode == MPG_MD_JOINT_STEREO)
1841
{
1842
ms_stereo = (fr->hdr.mode_ext & 0x2)>>1;
1843
i_stereo = fr->hdr.mode_ext & 0x1;
1844
}
1845
else ms_stereo = i_stereo = 0;
1846
1847
granules = fr->hdr.lsf ? 1 : 2;
1848
1849
/* quick hack to keep the music playing */
1850
/* after having seen this nasty test file... */
1851
if(III_get_side_info(fr, &sideinfo,stereo,ms_stereo,sfreq,single))
1852
{
1853
if(NOQUIET) error("bad frame - unable to get valid sideinfo");
1854
return clip;
1855
}
1856
1857
INT123_set_pointer(fr, 1, sideinfo.main_data_begin);
1858
#ifndef NO_MOREINFO
1859
if(fr->pinfo)
1860
{
1861
fr->pinfo->maindata = sideinfo.main_data_begin;
1862
fr->pinfo->padding = fr->hdr.padding;
1863
}
1864
#endif
1865
for(gr=0;gr<granules;gr++)
1866
{
1867
/* hybridIn[2][SBLIMIT][SSLIMIT] */
1868
real (*hybridIn)[SBLIMIT][SSLIMIT] = fr->layer3.hybrid_in;
1869
/* hybridOut[2][SSLIMIT][SBLIMIT] */
1870
real (*hybridOut)[SSLIMIT][SBLIMIT] = fr->layer3.hybrid_out;
1871
1872
{
1873
struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
1874
long part2bits;
1875
if(gr_info->part2_3_length > fr->bits_avail)
1876
{
1877
if(NOQUIET)
1878
error2(
1879
"part2_3_length (%u) too large for available bit count (%li)"
1880
, gr_info->part2_3_length, fr->bits_avail );
1881
return clip;
1882
}
1883
if(fr->hdr.lsf)
1884
part2bits = III_get_scale_factors_2(fr, scalefacs[0],gr_info,0);
1885
else
1886
part2bits = III_get_scale_factors_1(fr, scalefacs[0],gr_info,0,gr);
1887
1888
if(part2bits < 0)
1889
{
1890
if(VERBOSE2)
1891
error("not enough bits for scale factors");
1892
return clip;
1893
}
1894
1895
#ifndef NO_MOREINFO
1896
if(fr->pinfo)
1897
{
1898
int i;
1899
fr->pinfo->sfbits[gr][0] = part2bits;
1900
for(i=0; i<39; ++i)
1901
fr->pinfo->sfb_s[gr][0][i] = scalefacs[0][i];
1902
}
1903
#endif
1904
1905
if(III_dequantize_sample(fr, hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits))
1906
{
1907
if(NOQUIET)
1908
error("dequantization failed!");
1909
return clip;
1910
}
1911
if(fr->bits_avail < 0)
1912
{
1913
if(NOQUIET)
1914
error("bit deficit after dequant");
1915
return clip;
1916
}
1917
}
1918
1919
if(stereo == 2)
1920
{
1921
struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
1922
long part2bits;
1923
if(fr->hdr.lsf)
1924
part2bits = III_get_scale_factors_2(fr, scalefacs[1],gr_info,i_stereo);
1925
else
1926
part2bits = III_get_scale_factors_1(fr, scalefacs[1],gr_info,1,gr);
1927
1928
if(part2bits < 0)
1929
{
1930
if(VERBOSE2)
1931
error("not enough bits for scale factors");
1932
return clip;
1933
}
1934
1935
#ifndef NO_MOREINFO
1936
if(fr->pinfo)
1937
{
1938
int i;
1939
fr->pinfo->sfbits[gr][1] = part2bits;
1940
for(i=0; i<39; ++i)
1941
fr->pinfo->sfb_s[gr][1][i] = scalefacs[1][i];
1942
}
1943
#endif
1944
1945
if(III_dequantize_sample(fr, hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits))
1946
{
1947
if(NOQUIET)
1948
error("dequantization failed!");
1949
return clip;
1950
}
1951
if(fr->bits_avail < 0)
1952
{
1953
if(NOQUIET)
1954
error("bit deficit after dequant");
1955
return clip;
1956
}
1957
1958
if(ms_stereo)
1959
{
1960
int i;
1961
unsigned int maxb = sideinfo.ch[0].gr[gr].maxb;
1962
if(sideinfo.ch[1].gr[gr].maxb > maxb) maxb = sideinfo.ch[1].gr[gr].maxb;
1963
1964
for(i=0;i<SSLIMIT*(int)maxb;i++)
1965
{
1966
real tmp0 = ((real *)hybridIn[0])[i];
1967
real tmp1 = ((real *)hybridIn[1])[i];
1968
((real *)hybridIn[0])[i] = tmp0 + tmp1;
1969
((real *)hybridIn[1])[i] = tmp0 - tmp1;
1970
}
1971
}
1972
1973
if(i_stereo) III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->hdr.lsf);
1974
1975
if(ms_stereo || i_stereo || (single == SINGLE_MIX) )
1976
{
1977
if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb)
1978
sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
1979
else
1980
gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
1981
}
1982
1983
switch(single)
1984
{
1985
case SINGLE_MIX:
1986
{
1987
register int i;
1988
register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
1989
for(i=0;i<SSLIMIT*(int)gr_info->maxb;i++,in0++)
1990
*in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */
1991
}
1992
break;
1993
case SINGLE_RIGHT:
1994
{
1995
register int i;
1996
register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
1997
for(i=0;i<SSLIMIT*(int)gr_info->maxb;i++)
1998
*in0++ = *in1++;
1999
}
2000
break;
2001
}
2002
}
2003
2004
#ifndef NO_MOREINFO
2005
if(fr->pinfo)
2006
fill_pinfo_side(fr, &sideinfo, gr, stereo1);
2007
#endif
2008
2009
for(ch=0;ch<stereo1;ch++)
2010
{
2011
struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
2012
III_antialias(hybridIn[ch],gr_info);
2013
III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info, fr);
2014
}
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
for(ss=0;ss<SSLIMIT;ss++)
2021
{
2022
if(single != SINGLE_STEREO)
2023
clip += (fr->synth_mono)(hybridOut[0][ss], fr);
2024
else
2025
clip += (fr->synth_stereo)(hybridOut[0][ss], hybridOut[1][ss], fr);
2026
2027
}
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
}
2048
2049
return clip;
2050
}
2051
2052