annotate mp3lib/layer3.c @ 17824:c3429282c9a8

10l to me, misarrangment of flags
author ods15
date Sun, 12 Mar 2006 13:21:04 +0000
parents 07e7a572bd84
children 0783dd397f74
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15167
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 12134
diff changeset
1 /*
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 12134
diff changeset
2 * Modified for use with MPlayer, for details see the CVS changelog at
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 12134
diff changeset
3 * http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 12134
diff changeset
4 * $Id$
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 12134
diff changeset
5 */
07e7a572bd84 Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents: 12134
diff changeset
6
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
7 /*
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
8 * Mpeg Layer-3 audio decoder
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
9 * --------------------------
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
10 * copyright (c) 1995-1999 by Michael Hipp.
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
11 * All rights reserved. See also 'README'
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
12 *
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
13 * Optimize-TODO: put short bands into the band-field without the stride
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
14 * of 3 reals
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
15 * Length-optimze: unify long and short band code where it is possible
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
16 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
17
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
18 #if 0
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
19 #define L3_DEBUG 1
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
20 #endif
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
21
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
22 #if 0
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
23 #define CUT_HF
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
24 #endif
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
25
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
26 # define REAL_MUL(x, y) ((x) * (y))
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
27
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
28 static real ispow[8207];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
29 static real aa_ca[8],aa_cs[8];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
30 static real COS1[12][6];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
31 static real win[4][36];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
32 static real win1[4][36];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
33 static real gainpow2[256+118+4];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
34
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
35 /* non static for external 3dnow functions */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
36 real COS9[9];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
37 static real COS6_1,COS6_2;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
38 real tfcos36[9];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
39
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
40 static real tfcos12[3];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
41 #define NEW_DCT9
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
42 #ifdef NEW_DCT9
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
43 static real cos9[3],cos18[3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
44 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
45
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
46 struct bandInfoStruct {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
47 int longIdx[23];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
48 int longDiff[22];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
49 int shortIdx[14];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
50 int shortDiff[13];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
51 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
52
12131
d155623271e3 fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents: 10388
diff changeset
53 static int longLimit[9][23];
d155623271e3 fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents: 10388
diff changeset
54 static int shortLimit[9][14];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
55
12131
d155623271e3 fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents: 10388
diff changeset
56 static struct bandInfoStruct bandInfo[9] = {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
57
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
58 /* MPEG 1.0 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
59 { {0,4,8,12,16,20,24,30,36,44,52,62,74, 90,110,134,162,196,238,288,342,418,576},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
60 {4,4,4,4,4,4,6,6,8, 8,10,12,16,20,24,28,34,42,50,54, 76,158},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
61 {0,4*3,8*3,12*3,16*3,22*3,30*3,40*3,52*3,66*3, 84*3,106*3,136*3,192*3},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
62 {4,4,4,4,6,8,10,12,14,18,22,30,56} } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
63
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
64 { {0,4,8,12,16,20,24,30,36,42,50,60,72, 88,106,128,156,190,230,276,330,384,576},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
65 {4,4,4,4,4,4,6,6,6, 8,10,12,16,18,22,28,34,40,46,54, 54,192},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
66 {0,4*3,8*3,12*3,16*3,22*3,28*3,38*3,50*3,64*3, 80*3,100*3,126*3,192*3},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
67 {4,4,4,4,6,6,10,12,14,16,20,26,66} } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
68
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
69 { {0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576} ,
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
70 {4,4,4,4,4,4,6,6,8,10,12,16,20,24,30,38,46,56,68,84,102, 26} ,
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
71 {0,4*3,8*3,12*3,16*3,22*3,30*3,42*3,58*3,78*3,104*3,138*3,180*3,192*3} ,
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
72 {4,4,4,4,6,8,12,16,20,26,34,42,12} } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
73
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
74 /* MPEG 2.0 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
75 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
76 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 } ,
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
77 {0,4*3,8*3,12*3,18*3,24*3,32*3,42*3,56*3,74*3,100*3,132*3,174*3,192*3} ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
78 {4,4,4,6,6,8,10,14,18,26,32,42,18 } } ,
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
79 /* changed 19th value fropm 330 to 332 */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
80 { {0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576},
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
81 {6,6,6,6,6,6,8,10,12,14,16,18,22,26,32,38,46,54,62,70,76,36 } ,
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
82 {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,136*3,180*3,192*3} ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
83 {4,4,4,6,8,10,12,14,18,24,32,44,12 } } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
84
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
85 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
86 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54 },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
87 {0,4*3,8*3,12*3,18*3,26*3,36*3,48*3,62*3,80*3,104*3,134*3,174*3,192*3},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
88 {4,4,4,6,8,10,12,14,18,24,30,40,18 } } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
89 /* MPEG 2.5 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
90 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
91 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
92 {0,12,24,36,54,78,108,144,186,240,312,402,522,576},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
93 {4,4,4,6,8,10,12,14,18,24,30,40,18} },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
94 { {0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576} ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
95 {6,6,6,6,6,6,8,10,12,14,16,20,24,28,32,38,46,52,60,68,58,54},
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
96 {0,12,24,36,54,78,108,144,186,240,312,402,522,576},
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
97 {4,4,4,6,8,10,12,14,18,24,30,40,18} },
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
98 { {0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
99 {12,12,12,12,12,12,16,20,24,28,32,40,48,56,64,76,90,2,2,2,2,2},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
100 {0, 24, 48, 72,108,156,216,288,372,480,486,492,498,576},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
101 {8,8,8,12,16,20,24,28,36,2,2,2,26} } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
102 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
103
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
104 static int mapbuf0[9][152];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
105 static int mapbuf1[9][156];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
106 static int mapbuf2[9][44];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
107 static int *map[9][3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
108 static int *mapend[9][3];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
109
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
110 static unsigned int n_slen2[512]; /* MPEG 2.0 slen for 'normal' mode */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
111 static unsigned int i_slen2[256]; /* MPEG 2.0 slen for intensity stereo */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
112
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
113 static real tan1_1[16],tan2_1[16],tan1_2[16],tan2_2[16];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
114 static real pow1_1[2][16],pow2_1[2][16],pow1_2[2][16],pow2_2[2][16];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
115
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
116 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
117 * init tables for layer-3
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
118 */
12131
d155623271e3 fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents: 10388
diff changeset
119 static void init_layer3(int down_sample_sblimit)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
120 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
121 int i,j,k,l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
122
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
123 for(i=-256;i<118+4;i++)
1245
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
124 {
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
125 if(_has_mmx)
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
126 gainpow2[i+256] = 16384.0 * pow((double)2.0,-0.25 * (double) (i+210) );
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
127 else
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
128 gainpow2[i+256] = pow((double)2.0,-0.25 * (double) (i+210) );
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
129 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
130 for(i=0;i<8207;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
131 ispow[i] = pow((double)i,(double)4.0/3.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
132
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
133 for (i=0;i<8;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
134 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
135 static double Ci[8]={-0.6,-0.535,-0.33,-0.185,-0.095,-0.041,-0.0142,-0.0037};
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
136 double sq=sqrt(1.0+Ci[i]*Ci[i]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
137 aa_cs[i] = 1.0/sq;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
138 aa_ca[i] = Ci[i]/sq;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
139 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
140
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
141 for(i=0;i<18;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
142 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
143 win[0][i] = win[1][i] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+0) +1) ) / cos ( M_PI * (double) (2*(i+0) +19) / 72.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
144 win[0][i+18] = win[3][i+18] = 0.5 * sin( M_PI / 72.0 * (double) (2*(i+18)+1) ) / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
145 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
146 for(i=0;i<6;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
147 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
148 win[1][i+18] = 0.5 / cos ( M_PI * (double) (2*(i+18)+19) / 72.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
149 win[3][i+12] = 0.5 / cos ( M_PI * (double) (2*(i+12)+19) / 72.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
150 win[1][i+24] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+13) ) / cos ( M_PI * (double) (2*(i+24)+19) / 72.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
151 win[1][i+30] = win[3][i] = 0.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
152 win[3][i+6 ] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*(i+6 )+19) / 72.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
153 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
154
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
155 for(i=0;i<9;i++)
1245
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
156 COS9[i] = cos( M_PI / 18.0 * (double) i);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
157
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
158 for(i=0;i<9;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
159 tfcos36[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 36.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
160 for(i=0;i<3;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
161 tfcos12[i] = 0.5 / cos ( M_PI * (double) (i*2+1) / 12.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
162
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
163 COS6_1 = cos( M_PI / 6.0 * (double) 1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
164 COS6_2 = cos( M_PI / 6.0 * (double) 2);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
165
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
166 #ifdef NEW_DCT9
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
167 cos9[0] = cos(1.0*M_PI/9.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
168 cos9[1] = cos(5.0*M_PI/9.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
169 cos9[2] = cos(7.0*M_PI/9.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
170 cos18[0] = cos(1.0*M_PI/18.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
171 cos18[1] = cos(11.0*M_PI/18.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
172 cos18[2] = cos(13.0*M_PI/18.0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
173 #endif
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
174
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
175 for(i=0;i<12;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
176 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
177 win[2][i] = 0.5 * sin( M_PI / 24.0 * (double) (2*i+1) ) / cos ( M_PI * (double) (2*i+7) / 24.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
178 for(j=0;j<6;j++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
179 COS1[i][j] = cos( M_PI / 24.0 * (double) ((2*i+7)*(2*j+1)) );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
180 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
181
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
182 for(j=0;j<4;j++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
183 static int len[4] = { 36,36,12,36 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
184 for(i=0;i<len[j];i+=2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
185 win1[j][i] = + win[j][i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
186 for(i=1;i<len[j];i+=2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
187 win1[j][i] = - win[j][i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
188 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
189
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
190 for(i=0;i<16;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
191 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
192 double t = tan( (double) i * M_PI / 12.0 );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
193 tan1_1[i] = t / (1.0+t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
194 tan2_1[i] = 1.0 / (1.0 + t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
195 tan1_2[i] = M_SQRT2 * t / (1.0+t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
196 tan2_2[i] = M_SQRT2 / (1.0 + t);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
197
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
198 for(j=0;j<2;j++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
199 double base = pow(2.0,-0.25*(j+1.0));
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
200 double p1=1.0,p2=1.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
201 if(i > 0) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
202 if( i & 1 )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
203 p1 = pow(base,(i+1.0)*0.5);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
204 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
205 p2 = pow(base,i*0.5);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
206 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
207 pow1_1[j][i] = p1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
208 pow2_1[j][i] = p2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
209 pow1_2[j][i] = M_SQRT2 * p1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
210 pow2_2[j][i] = M_SQRT2 * p2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
211 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
212 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
213
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
214 for(j=0;j<9;j++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
215 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
216 struct bandInfoStruct *bi = &bandInfo[j];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
217 int *mp;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
218 int cb,lwin;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
219 int *bdf;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
220
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
221 mp = map[j][0] = mapbuf0[j];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
222 bdf = bi->longDiff;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
223 for(i=0,cb = 0; cb < 8 ; cb++,i+=*bdf++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
224 *mp++ = (*bdf) >> 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
225 *mp++ = i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
226 *mp++ = 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
227 *mp++ = cb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
228 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
229 bdf = bi->shortDiff+3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
230 for(cb=3;cb<13;cb++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
231 int l = (*bdf++) >> 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
232 for(lwin=0;lwin<3;lwin++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
233 *mp++ = l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
234 *mp++ = i + lwin;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
235 *mp++ = lwin;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
236 *mp++ = cb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
237 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
238 i += 6*l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
239 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
240 mapend[j][0] = mp;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
241
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
242 mp = map[j][1] = mapbuf1[j];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
243 bdf = bi->shortDiff+0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
244 for(i=0,cb=0;cb<13;cb++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
245 int l = (*bdf++) >> 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
246 for(lwin=0;lwin<3;lwin++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
247 *mp++ = l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
248 *mp++ = i + lwin;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
249 *mp++ = lwin;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
250 *mp++ = cb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
251 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
252 i += 6*l;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
253 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
254 mapend[j][1] = mp;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
255
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
256 mp = map[j][2] = mapbuf2[j];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
257 bdf = bi->longDiff;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
258 for(cb = 0; cb < 22 ; cb++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
259 *mp++ = (*bdf++) >> 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
260 *mp++ = cb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
261 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
262 mapend[j][2] = mp;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
263
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
264 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
265
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
266 for(j=0;j<9;j++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
267 for(i=0;i<23;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
268 longLimit[j][i] = (bandInfo[j].longIdx[i] - 1 + 8) / 18 + 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
269 if(longLimit[j][i] > (down_sample_sblimit) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
270 longLimit[j][i] = down_sample_sblimit;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
271 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
272 for(i=0;i<14;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
273 shortLimit[j][i] = (bandInfo[j].shortIdx[i] - 1) / 18 + 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
274 if(shortLimit[j][i] > (down_sample_sblimit) )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
275 shortLimit[j][i] = down_sample_sblimit;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
276 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
277 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
278
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
279 for(i=0;i<5;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
280 for(j=0;j<6;j++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
281 for(k=0;k<6;k++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
282 int n = k + j * 6 + i * 36;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
283 i_slen2[n] = i|(j<<3)|(k<<6)|(3<<12);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
284 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
285 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
286 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
287 for(i=0;i<4;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
288 for(j=0;j<4;j++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
289 for(k=0;k<4;k++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
290 int n = k + j * 4 + i * 16;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
291 i_slen2[n+180] = i|(j<<3)|(k<<6)|(4<<12);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
292 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
293 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
294 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
295 for(i=0;i<4;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
296 for(j=0;j<3;j++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
297 int n = j + i * 3;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
298 i_slen2[n+244] = i|(j<<3) | (5<<12);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
299 n_slen2[n+500] = i|(j<<3) | (2<<12) | (1<<15);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
300 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
301 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
302
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
303 for(i=0;i<5;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
304 for(j=0;j<5;j++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
305 for(k=0;k<4;k++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
306 for(l=0;l<4;l++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
307 int n = l + k * 4 + j * 16 + i * 80;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
308 n_slen2[n] = i|(j<<3)|(k<<6)|(l<<9)|(0<<12);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
309 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
310 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
311 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
312 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
313 for(i=0;i<5;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
314 for(j=0;j<5;j++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
315 for(k=0;k<4;k++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
316 int n = k + j * 4 + i * 20;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
317 n_slen2[n+400] = i|(j<<3)|(k<<6)|(1<<12);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
318 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
319 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
320 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
321 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
322
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
323 /*
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
324 * read additional side information (for MPEG 1 and MPEG 2)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
325 */
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
326 static int III_get_side_info(struct III_sideinfo *si,int stereo,
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
327 int ms_stereo,long sfreq,int single,int lsf)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
328 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
329 int ch, gr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
330 int powdiff = (single == 3) ? 4 : 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
331
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
332 static const int tabs[2][5] = { { 2,9,5,3,4 } , { 1,8,1,2,9 } };
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
333 const int *tab = tabs[lsf];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
334
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
335 si->main_data_begin = getbits(tab[1]);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
336 if (stereo == 1)
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
337 si->private_bits = getbits_fast(tab[2]);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
338 else
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
339 si->private_bits = getbits_fast(tab[3]);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
340
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
341 if(!lsf) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
342 for (ch=0; ch<stereo; ch++) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
343 si->ch[ch].gr[0].scfsi = -1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
344 si->ch[ch].gr[1].scfsi = getbits_fast(4);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
345 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
346 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
347
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
348 for (gr=0; gr<tab[0]; gr++) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
349 for (ch=0; ch<stereo; ch++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
350 register struct gr_info_s *gr_info = &(si->ch[ch].gr[gr]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
351
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
352 gr_info->part2_3_length = getbits(12);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
353 gr_info->big_values = getbits(9);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
354 if(gr_info->big_values > 288) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
355 fprintf(stderr,"big_values too large!\n");
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
356 gr_info->big_values = 288;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
357 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
358 gr_info->pow2gain = gainpow2+256 - getbits_fast(8) + powdiff;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
359 if(ms_stereo)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
360 gr_info->pow2gain += 2;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
361 gr_info->scalefac_compress = getbits(tab[4]);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
362
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
363 if(get1bit()) { /* window switch flag */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
364 int i;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
365 #ifdef L3_DEBUG
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
366 if(2*gr_info->big_values > bandInfo[sfreq].shortIdx[12])
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
367 fprintf(stderr,"L3: BigValues too large, doesn't make sense %d %d\n",2*gr_info->big_values,bandInfo[sfreq].shortIdx[12]);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
368 #endif
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
369
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
370 gr_info->block_type = getbits_fast(2);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
371 gr_info->mixed_block_flag = get1bit();
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
372 gr_info->table_select[0] = getbits_fast(5);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
373 gr_info->table_select[1] = getbits_fast(5);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
374 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
375 * table_select[2] not needed, because there is no region2,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
376 * but to satisfy some verifications tools we set it either.
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
377 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
378 gr_info->table_select[2] = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
379 for(i=0;i<3;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
380 gr_info->full_gain[i] = gr_info->pow2gain + (getbits_fast(3)<<3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
381
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
382 if(gr_info->block_type == 0) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
383 fprintf(stderr,"Blocktype == 0 and window-switching == 1 not allowed.\n");
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
384 return 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
385 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
386
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
387 /* region_count/start parameters are implicit in this case. */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
388 if(!lsf || gr_info->block_type == 2)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
389 gr_info->region1start = 36>>1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
390 else {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
391 /* check this again for 2.5 and sfreq=8 */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
392 if(sfreq == 8)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
393 gr_info->region1start = 108>>1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
394 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
395 gr_info->region1start = 54>>1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
396 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
397 gr_info->region2start = 576>>1;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
398 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
399 else {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
400 int i,r0c,r1c;
10349
d9141bcbb425 disable L3: BigValues too large message
faust3
parents: 10343
diff changeset
401 #ifdef L3_DEBUG
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
402 if(2*gr_info->big_values > bandInfo[sfreq].longIdx[21])
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
403 fprintf(stderr,"L3: BigValues too large, doesn't make sense %d %d\n",2*gr_info->big_values,bandInfo[sfreq].longIdx[21]);
10349
d9141bcbb425 disable L3: BigValues too large message
faust3
parents: 10343
diff changeset
404 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
405 for (i=0; i<3; i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
406 gr_info->table_select[i] = getbits_fast(5);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
407 r0c = getbits_fast(4);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
408 r1c = getbits_fast(3);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
409 gr_info->region1start = bandInfo[sfreq].longIdx[r0c+1] >> 1 ;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
410 if(r0c + r1c + 2 > 22)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
411 gr_info->region2start = 576>>1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
412 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
413 gr_info->region2start = bandInfo[sfreq].longIdx[r0c+1+r1c+1] >> 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
414 gr_info->block_type = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
415 gr_info->mixed_block_flag = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
416 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
417 if(!lsf)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
418 gr_info->preflag = get1bit();
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
419 gr_info->scalefac_scale = get1bit();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
420 gr_info->count1table_select = get1bit();
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
421 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
422 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
423
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
424 return !0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
425 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
426
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
427 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
428 * read scalefactors
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
429 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
430 static int III_get_scale_factors_1(int *scf,struct gr_info_s *gr_info)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
431 {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
432 static const unsigned char slen[2][16] = {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
433 {0, 0, 0, 0, 3, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4},
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
434 {0, 1, 2, 3, 0, 1, 2, 3, 1, 2, 3, 1, 2, 3, 2, 3}
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
435 };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
436 int numbits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
437 int num0 = slen[0][gr_info->scalefac_compress];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
438 int num1 = slen[1][gr_info->scalefac_compress];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
439
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
440 if (gr_info->block_type == 2) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
441 int i=18;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
442 numbits = (num0 + num1) * 18;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
443
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
444 if (gr_info->mixed_block_flag) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
445 for (i=8;i;i--)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
446 *scf++ = getbits_fast(num0);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
447 i = 9;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
448 numbits -= num0; /* num0 * 17 + num1 * 18 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
449 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
450
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
451 for (;i;i--)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
452 *scf++ = getbits_fast(num0);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
453 for (i = 18; i; i--)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
454 *scf++ = getbits_fast(num1);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
455 *scf++ = 0; *scf++ = 0; *scf++ = 0; /* short[13][0..2] = 0 */
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
456 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
457 else {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
458 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
459 int scfsi = gr_info->scfsi;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
460
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
461 if(scfsi < 0) { /* scfsi < 0 => granule == 0 */
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
462 for(i=11;i;i--)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
463 *scf++ = getbits_fast(num0);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
464 for(i=10;i;i--)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
465 *scf++ = getbits_fast(num1);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
466 numbits = (num0 + num1) * 10 + num0;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
467 *scf++ = 0;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
468 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
469 else {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
470 numbits = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
471 if(!(scfsi & 0x8)) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
472 for (i=0;i<6;i++)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
473 *scf++ = getbits_fast(num0);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
474 numbits += num0 * 6;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
475 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
476 else {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
477 scf += 6;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
478 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
479
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
480 if(!(scfsi & 0x4)) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
481 for (i=0;i<5;i++)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
482 *scf++ = getbits_fast(num0);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
483 numbits += num0 * 5;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
484 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
485 else {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
486 scf += 5;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
487 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
488
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
489 if(!(scfsi & 0x2)) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
490 for(i=0;i<5;i++)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
491 *scf++ = getbits_fast(num1);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
492 numbits += num1 * 5;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
493 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
494 else {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
495 scf += 5;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
496 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
497
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
498 if(!(scfsi & 0x1)) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
499 for (i=0;i<5;i++)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
500 *scf++ = getbits_fast(num1);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
501 numbits += num1 * 5;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
502 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
503 else {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
504 scf += 5;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
505 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
506 *scf++ = 0; /* no l[21] in original sources */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
507 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
508 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
509 return numbits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
510 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
511
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
512 static int III_get_scale_factors_2(int *scf,struct gr_info_s *gr_info,int i_stereo)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
513 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
514 unsigned char *pnt;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
515 int i,j;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
516 unsigned int slen;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
517 int n = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
518 int numbits = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
519
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
520 static unsigned char stab[3][6][4] = {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
521 { { 6, 5, 5,5 } , { 6, 5, 7,3 } , { 11,10,0,0} ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
522 { 7, 7, 7,0 } , { 6, 6, 6,3 } , { 8, 8,5,0} } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
523 { { 9, 9, 9,9 } , { 9, 9,12,6 } , { 18,18,0,0} ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
524 {12,12,12,0 } , {12, 9, 9,6 } , { 15,12,9,0} } ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
525 { { 6, 9, 9,9 } , { 6, 9,12,6 } , { 15,18,0,0} ,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
526 { 6,15,12,0 } , { 6,12, 9,6 } , { 6,18,9,0} } };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
527
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
528 if(i_stereo) /* i_stereo AND second channel -> do_layer3() checks this */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
529 slen = i_slen2[gr_info->scalefac_compress>>1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
530 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
531 slen = n_slen2[gr_info->scalefac_compress];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
532
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
533 gr_info->preflag = (slen>>15) & 0x1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
534
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
535 n = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
536 if( gr_info->block_type == 2 ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
537 n++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
538 if(gr_info->mixed_block_flag) n++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
539 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
540
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
541 pnt = stab[n][(slen>>12)&0x7];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
542
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
543 for(i=0;i<4;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
544 int num = slen & 0x7;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
545 slen >>= 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
546 if(num) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
547 for(j=0;j<(int)(pnt[i]);j++) *scf++ = getbits_fast(num);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
548 numbits += pnt[i] * num;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
549 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
550 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
551 for(j=0;j<(int)(pnt[i]);j++) *scf++ = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
552 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
553 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
554
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
555 n = (n << 1) + 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
556 for(i=0;i<n;i++) *scf++ = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
557
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
558 return numbits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
559 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
560
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
561 static int pretab1[22] = {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0};
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
562 static int pretab2[22] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
563
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
564 #define getbitoffset() ((-bitindex)&0x7)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
565 #define getbyte() (*wordpointer++)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
566
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
567 /*
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
568 * Dequantize samples (includes huffman decoding)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
569 */
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
570 /* 24 is enough because tab13 has max. a 19 bit huffvector */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
571 #define BITSHIFT ((sizeof(long)-1)*8)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
572 #define REFRESH_MASK \
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
573 while(num < BITSHIFT) { \
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
574 mask |= ((unsigned long)getbyte())<<(BITSHIFT-num); \
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
575 num += 8; \
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
576 part2remain -= 8; }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
577
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
578 static int III_dequantize_sample(real xr[SBLIMIT][SSLIMIT],int *scf,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
579 struct gr_info_s *gr_info,int sfreq,int part2bits)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
580 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
581 int shift = 1 + gr_info->scalefac_scale;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
582 real *xrpnt = (real *) xr;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
583 int l[3],l3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
584 int part2remain = gr_info->part2_3_length - part2bits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
585 int *me;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
586
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
587 int num=getbitoffset();
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
588 long mask;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
589 /* we must split this, because for num==0 the shift is undefined if you do it in one step */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
590 mask = ((unsigned long) getbits(num))<<BITSHIFT;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
591 mask <<= 8-num;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
592 part2remain -= num;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
593
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
594 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
595 int bv = gr_info->big_values;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
596 int region1 = gr_info->region1start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
597 int region2 = gr_info->region2start;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
598
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
599 l3 = ((576>>1)-bv)>>1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
600 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
601 * we may lose the 'odd' bit here !!
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
602 * check this later again
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
603 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
604 if(bv <= region1) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
605 l[0] = bv; l[1] = l[2] = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
606 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
607 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
608 l[0] = region1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
609 if(bv <= region2) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
610 l[1] = bv - l[0]; l[2] = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
611 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
612 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
613 l[1] = region2 - l[0]; l[2] = bv - region2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
614 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
615 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
616 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
617
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
618 if(gr_info->block_type == 2) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
619 /*
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
620 * decoding with short or mixed mode BandIndex table
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
621 */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
622 int i,max[4];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
623 int step=0,lwin=3,cb=0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
624 register real v = 0.0;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
625 register int *m,mc;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
626
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
627 if(gr_info->mixed_block_flag) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
628 max[3] = -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
629 max[0] = max[1] = max[2] = 2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
630 m = map[sfreq][0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
631 me = mapend[sfreq][0];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
632 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
633 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
634 max[0] = max[1] = max[2] = max[3] = -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
635 /* max[3] not really needed in this case */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
636 m = map[sfreq][1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
637 me = mapend[sfreq][1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
638 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
639
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
640 mc = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
641 for(i=0;i<2;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
642 int lp = l[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
643 struct newhuff *h = ht+gr_info->table_select[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
644 for(;lp;lp--,mc--) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
645 register int x,y;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
646 if( (!mc) ) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
647 mc = *m++;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
648 xrpnt = ((real *) xr) + (*m++);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
649 lwin = *m++;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
650 cb = *m++;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
651 if(lwin == 3) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
652 v = gr_info->pow2gain[(*scf++) << shift];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
653 step = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
654 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
655 else {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
656 v = gr_info->full_gain[lwin][(*scf++) << shift];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
657 step = 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
658 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
659 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
660 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
661 register short *val = h->table;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
662 REFRESH_MASK;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
663 while((y=*val++)<0) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
664 if (mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
665 val -= y;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
666 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
667 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
668 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
669 x = y >> 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
670 y &= 0xf;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
671 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
672 if(x == 15 && h->linbits) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
673 max[lwin] = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
674 REFRESH_MASK;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
675 x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
676 num -= h->linbits+1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
677 mask <<= h->linbits;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
678 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
679 *xrpnt = REAL_MUL(-ispow[x], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
680 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
681 *xrpnt = REAL_MUL(ispow[x], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
682 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
683 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
684 else if(x) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
685 max[lwin] = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
686 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
687 *xrpnt = REAL_MUL(-ispow[x], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
688 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
689 *xrpnt = REAL_MUL(ispow[x], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
690 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
691 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
692 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
693 else
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
694 *xrpnt = 0.0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
695 xrpnt += step;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
696 if(y == 15 && h->linbits) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
697 max[lwin] = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
698 REFRESH_MASK;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
699 y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
700 num -= h->linbits+1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
701 mask <<= h->linbits;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
702 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
703 *xrpnt = REAL_MUL(-ispow[y], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
704 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
705 *xrpnt = REAL_MUL(ispow[y], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
706 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
707 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
708 else if(y) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
709 max[lwin] = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
710 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
711 *xrpnt = REAL_MUL(-ispow[y], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
712 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
713 *xrpnt = REAL_MUL(ispow[y], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
714 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
715 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
716 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
717 else
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
718 *xrpnt = 0.0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
719 xrpnt += step;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
720 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
721 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
722
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
723 for(;l3 && (part2remain+num > 0);l3--) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
724 struct newhuff *h = htc+gr_info->count1table_select;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
725 register short *val = h->table,a;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
726
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
727 REFRESH_MASK;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
728 while((a=*val++)<0) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
729 if (mask < 0)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
730 val -= a;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
731 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
732 mask <<= 1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
733 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
734 if(part2remain+num <= 0) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
735 num -= part2remain+num;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
736 break;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
737 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
738
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
739 for(i=0;i<4;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
740 if(!(i & 1)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
741 if(!mc) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
742 mc = *m++;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
743 xrpnt = ((real *) xr) + (*m++);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
744 lwin = *m++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
745 cb = *m++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
746 if(lwin == 3) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
747 v = gr_info->pow2gain[(*scf++) << shift];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
748 step = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
749 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
750 else {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
751 v = gr_info->full_gain[lwin][(*scf++) << shift];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
752 step = 3;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
753 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
754 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
755 mc--;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
756 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
757 if( (a & (0x8>>i)) ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
758 max[lwin] = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
759 if(part2remain+num <= 0) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
760 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
761 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
762 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
763 *xrpnt = -v;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
764 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
765 *xrpnt = v;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
766 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
767 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
768 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
769 else
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
770 *xrpnt = 0.0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
771 xrpnt += step;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
772 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
773 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
774
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
775 if(lwin < 3) { /* short band? */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
776 while(1) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
777 for(;mc > 0;mc--) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
778 *xrpnt = 0.0; xrpnt += 3; /* short band -> step=3 */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
779 *xrpnt = 0.0; xrpnt += 3;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
780 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
781 if(m >= me)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
782 break;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
783 mc = *m++;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
784 xrpnt = ((real *) xr) + *m++;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
785 if(*m++ == 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
786 break; /* optimize: field will be set to zero at the end of the function */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
787 m++; /* cb */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
788 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
789 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
790
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
791 gr_info->maxband[0] = max[0]+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
792 gr_info->maxband[1] = max[1]+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
793 gr_info->maxband[2] = max[2]+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
794 gr_info->maxbandl = max[3]+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
795
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
796 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
797 int rmax = max[0] > max[1] ? max[0] : max[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
798 rmax = (rmax > max[2] ? rmax : max[2]) + 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
799 gr_info->maxb = rmax ? shortLimit[sfreq][rmax] : longLimit[sfreq][max[3]+1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
800 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
801
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
802 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
803 else {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
804 /*
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
805 * decoding with 'long' BandIndex table (block_type != 2)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
806 */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
807 int *pretab = gr_info->preflag ? pretab1 : pretab2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
808 int i,max = -1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
809 int cb = 0;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
810 int *m = map[sfreq][2];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
811 register real v = 0.0;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
812 int mc = 0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
813
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
814 /*
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
815 * long hash table values
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
816 */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
817 for(i=0;i<3;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
818 int lp = l[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
819 struct newhuff *h = ht+gr_info->table_select[i];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
820
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
821 for(;lp;lp--,mc--) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
822 int x,y;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
823
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
824 if(!mc) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
825 mc = *m++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
826 cb = *m++;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
827 #ifdef CUT_HF
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
828 if(cb == 21) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
829 fprintf(stderr,"c");
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
830 v = 0.0;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
831 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
832 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
833 #endif
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
834 v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
835
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
836 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
837 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
838 register short *val = h->table;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
839 REFRESH_MASK;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
840 while((y=*val++)<0) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
841 if (mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
842 val -= y;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
843 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
844 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
845 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
846 x = y >> 4;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
847 y &= 0xf;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
848 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
849
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
850 if (x == 15 && h->linbits) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
851 max = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
852 REFRESH_MASK;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
853 x += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
854 num -= h->linbits+1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
855 mask <<= h->linbits;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
856 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
857 *xrpnt++ = REAL_MUL(-ispow[x], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
858 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
859 *xrpnt++ = REAL_MUL(ispow[x], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
860 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
861 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
862 else if(x) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
863 max = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
864 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
865 *xrpnt++ = REAL_MUL(-ispow[x], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
866 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
867 *xrpnt++ = REAL_MUL(ispow[x], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
868 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
869 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
870 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
871 else
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
872 *xrpnt++ = 0.0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
873
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
874 if (y == 15 && h->linbits) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
875 max = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
876 REFRESH_MASK;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
877 y += ((unsigned long) mask) >> (BITSHIFT+8-h->linbits);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
878 num -= h->linbits+1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
879 mask <<= h->linbits;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
880 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
881 *xrpnt++ = REAL_MUL(-ispow[y], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
882 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
883 *xrpnt++ = REAL_MUL(ispow[y], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
884 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
885 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
886 else if(y) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
887 max = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
888 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
889 *xrpnt++ = REAL_MUL(-ispow[y], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
890 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
891 *xrpnt++ = REAL_MUL(ispow[y], v);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
892 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
893 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
894 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
895 else
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
896 *xrpnt++ = 0.0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
897 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
898 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
899
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
900 /*
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
901 * short (count1table) values
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
902 */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
903 for(;l3 && (part2remain+num > 0);l3--) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
904 struct newhuff *h = htc+gr_info->count1table_select;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
905 register short *val = h->table,a;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
906
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
907 REFRESH_MASK;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
908 while((a=*val++)<0) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
909 if (mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
910 val -= a;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
911 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
912 mask <<= 1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
913 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
914 if(part2remain+num <= 0) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
915 num -= part2remain+num;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
916 break;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
917 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
918
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
919 for(i=0;i<4;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
920 if(!(i & 1)) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
921 if(!mc) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
922 mc = *m++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
923 cb = *m++;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
924 #ifdef CUT_HF
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
925 if(cb == 21) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
926 fprintf(stderr,"c");
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
927 v = 0.0;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
928 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
929 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
930 #endif
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
931 v = gr_info->pow2gain[((*scf++) + (*pretab++)) << shift];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
932 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
933 mc--;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
934 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
935 if ( (a & (0x8>>i)) ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
936 max = cb;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
937 if(part2remain+num <= 0) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
938 break;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
939 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
940 if(mask < 0)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
941 *xrpnt++ = -v;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
942 else
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
943 *xrpnt++ = v;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
944 num--;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
945 mask <<= 1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
946 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
947 else
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
948 *xrpnt++ = 0.0;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
949 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
950 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
951
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
952 gr_info->maxbandl = max+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
953 gr_info->maxb = longLimit[sfreq][gr_info->maxbandl];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
954 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
955
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
956 part2remain += num;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
957 // backbits(num);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
958 bitindex -= num; wordpointer += (bitindex>>3); bitindex &= 0x7;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
959 num = 0;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
960
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
961 while(xrpnt < &xr[SBLIMIT][0])
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
962 *xrpnt++ = 0.0;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
963
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
964 while( part2remain > 16 ) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
965 getbits(16); /* Dismiss stuffing Bits */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
966 part2remain -= 16;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
967 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
968 if(part2remain > 0)
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
969 getbits(part2remain);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
970 else if(part2remain < 0) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
971 fprintf(stderr,"mpg123: Can't rewind stream by %d bits!\n",-part2remain);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
972 return 1; /* -> error */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
973 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
974 return 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
975 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
976
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
977
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
978
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
979
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
980 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
981 * III_stereo: calculate real channel values for Joint-I-Stereo-mode
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
982 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
983 static void III_i_stereo(real xr_buf[2][SBLIMIT][SSLIMIT],int *scalefac,
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
984 struct gr_info_s *gr_info,int sfreq,int ms_stereo,int lsf)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
985 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
986 real (*xr)[SBLIMIT*SSLIMIT] = (real (*)[SBLIMIT*SSLIMIT] ) xr_buf;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
987 struct bandInfoStruct *bi = &bandInfo[sfreq];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
988
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
989 const real *tab1,*tab2;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
990
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
991 int tab;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
992 static const real *tabs[3][2][2] = {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
993 { { tan1_1,tan2_1 } , { tan1_2,tan2_2 } },
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
994 { { pow1_1[0],pow2_1[0] } , { pow1_2[0],pow2_2[0] } } ,
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
995 { { pow1_1[1],pow2_1[1] } , { pow1_2[1],pow2_2[1] } }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
996 };
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
997
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
998 tab = lsf + (gr_info->scalefac_compress & lsf);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
999 tab1 = tabs[tab][ms_stereo][0];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1000 tab2 = tabs[tab][ms_stereo][1];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1001 #if 0
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1002 if(lsf) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1003 int p = gr_info->scalefac_compress & 0x1;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1004 if(ms_stereo) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1005 tab1 = pow1_2[p]; tab2 = pow2_2[p];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1006 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1007 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1008 tab1 = pow1_1[p]; tab2 = pow2_1[p];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1009 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1010 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1011 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1012 if(ms_stereo) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1013 tab1 = tan1_2; tab2 = tan2_2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1014 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1015 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1016 tab1 = tan1_1; tab2 = tan2_1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1017 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1018 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1019 #endif
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1020
10388
arpi
parents: 10349
diff changeset
1021 // printf("III_i_st: tab1=%p tab2=%p tab=%d ms=%d \n", tab1, tab2, tab, ms_stereo);
arpi
parents: 10349
diff changeset
1022
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1023 if (gr_info->block_type == 2) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1024 int lwin,do_l = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1025 if( gr_info->mixed_block_flag )
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1026 do_l = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1027
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1028 for (lwin=0;lwin<3;lwin++) { /* process each window */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1029 /* get first band with zero values */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1030 int is_p,sb,idx,sfb = gr_info->maxband[lwin]; /* sfb is minimal 3 for mixed mode */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1031 if(sfb > 3)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1032 do_l = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1033
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1034 for(;sfb<12;sfb++) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1035 is_p = scalefac[sfb*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1036 if(is_p != 7) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1037 real t1,t2;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1038 sb = bi->shortDiff[sfb];
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1039 idx = bi->shortIdx[sfb] + lwin;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1040 t1 = tab1[is_p]; t2 = tab2[is_p];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1041 for (; sb > 0; sb--,idx+=3) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1042 real v = xr[0][idx];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1043 xr[0][idx] = REAL_MUL(v, t1);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1044 xr[1][idx] = REAL_MUL(v, t2);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1045 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1046 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1047 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1048
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1049 #if 1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1050 /* in the original: copy 10 to 11 , here: copy 11 to 12
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1051 maybe still wrong??? (copy 12 to 13?) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1052 is_p = scalefac[11*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1053 sb = bi->shortDiff[12];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1054 idx = bi->shortIdx[12] + lwin;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1055 #else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1056 is_p = scalefac[10*3+lwin-gr_info->mixed_block_flag]; /* scale: 0-15 */
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1057 sb = bi->shortDiff[11];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1058 idx = bi->shortIdx[11] + lwin;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1059 #endif
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1060 if(is_p != 7) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1061 real t1,t2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1062 t1 = tab1[is_p]; t2 = tab2[is_p];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1063 for ( ; sb > 0; sb--,idx+=3 ) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1064 real v = xr[0][idx];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1065 xr[0][idx] = REAL_MUL(v, t1);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1066 xr[1][idx] = REAL_MUL(v, t2);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1067 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1068 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1069 } /* end for(lwin; .. ; . ) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1070
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1071 /* also check l-part, if ALL bands in the three windows are 'empty'
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1072 * and mode = mixed_mode
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1073 */
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1074 if (do_l) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1075 int sfb = gr_info->maxbandl;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1076 int idx = bi->longIdx[sfb];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1077
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1078 for ( ; sfb<8; sfb++ ) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1079 int sb = bi->longDiff[sfb];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1080 int is_p = scalefac[sfb]; /* scale: 0-15 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1081 if(is_p != 7) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1082 real t1,t2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1083 t1 = tab1[is_p]; t2 = tab2[is_p];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1084 for ( ; sb > 0; sb--,idx++) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1085 real v = xr[0][idx];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1086 xr[0][idx] = REAL_MUL(v, t1);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1087 xr[1][idx] = REAL_MUL(v, t2);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1088 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1089 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1090 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1091 idx += sb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1092 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1093 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1094 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1095 else { /* ((gr_info->block_type != 2)) */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1096 int sfb = gr_info->maxbandl;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1097 int is_p,idx = bi->longIdx[sfb];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1098
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1099 /* hmm ... maybe the maxbandl stuff for i-stereo is buggy? */
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1100 if(sfb <= 21) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1101 for ( ; sfb<21; sfb++) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1102 int sb = bi->longDiff[sfb];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1103 is_p = scalefac[sfb]; /* scale: 0-15 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1104 if(is_p != 7) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1105 real t1,t2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1106 t1 = tab1[is_p]; t2 = tab2[is_p];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1107 for ( ; sb > 0; sb--,idx++) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1108 real v = xr[0][idx];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1109 xr[0][idx] = REAL_MUL(v, t1);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1110 xr[1][idx] = REAL_MUL(v, t2);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1111 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1112 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1113 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1114 idx += sb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1115 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1116
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1117 is_p = scalefac[20];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1118 if(is_p != 7) { /* copy l-band 20 to l-band 21 */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1119 int sb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1120 real t1 = tab1[is_p],t2 = tab2[is_p];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1121
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1122 for ( sb = bi->longDiff[21]; sb > 0; sb--,idx++ ) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1123 real v = xr[0][idx];
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1124 xr[0][idx] = REAL_MUL(v, t1);
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1125 xr[1][idx] = REAL_MUL(v, t2);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1126 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1127 }
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1128 } /* end: if(sfb <= 21) */
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1129 } /* ... */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1130 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1131
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1132 static void III_antialias(real xr[SBLIMIT][SSLIMIT],struct gr_info_s *gr_info) {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1133 int sblim;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1134
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1135 if(gr_info->block_type == 2) {
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1136 if(!gr_info->mixed_block_flag)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1137 return;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1138 sblim = 1;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1139 }
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1140 else {
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1141 sblim = gr_info->maxb-1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1142 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1143
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1144 /* 31 alias-reduction operations between each pair of sub-bands */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1145 /* with 8 butterflies between each pair */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1146
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1147 {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1148 int sb;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1149 real *xr1=(real *) xr[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1150
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1151 for(sb=sblim;sb;sb--,xr1+=10) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1152 int ss;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1153 real *cs=aa_cs,*ca=aa_ca;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1154 real *xr2 = xr1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1155
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1156 for(ss=7;ss>=0;ss--) { /* upper and lower butterfly inputs */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1157 register real bu = *--xr2,bd = *xr1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1158 *xr2 = (bu * (*cs) ) - (bd * (*ca) );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1159 *xr1++ = (bd * (*cs++) ) + (bu * (*ca++) );
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1160 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1161 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1162
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1163 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1164 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1165
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1166 #include "dct64.c"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1167 #include "dct36.c"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1168 #include "dct12.c"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1169
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1170 #include "decod386.c"
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1171
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1172 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1173 * III_hybrid
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1174 */
1245
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
1175
12134
83822b2b0a17 some more globals
alex
parents: 12131
diff changeset
1176 static dct36_func_t dct36_func;
1245
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
1177
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1178 static void III_hybrid(real fsIn[SBLIMIT][SSLIMIT],real tsOut[SSLIMIT][SBLIMIT],
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1179 int ch,struct gr_info_s *gr_info)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1180 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1181 real *tspnt = (real *) tsOut;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1182 static real block[2][2][SBLIMIT*SSLIMIT] = { { { 0, } } };
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1183 static int blc[2]={0,0};
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1184 real *rawout1,*rawout2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1185 int bt;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1186 int sb = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1187
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1188 {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1189 int b = blc[ch];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1190 rawout1=block[b][ch];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1191 b=-b+1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1192 rawout2=block[b][ch];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1193 blc[ch] = b;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1194 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1195
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1196 if(gr_info->mixed_block_flag) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1197 sb = 2;
1245
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
1198 (*dct36_func)(fsIn[0],rawout1,rawout2,win[0],tspnt);
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
1199 (*dct36_func)(fsIn[1],rawout1+18,rawout2+18,win1[0],tspnt+1);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1200 rawout1 += 36; rawout2 += 36; tspnt += 2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1201 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1202
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1203 bt = gr_info->block_type;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1204 if(bt == 2) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1205 for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1206 dct12(fsIn[sb],rawout1,rawout2,win[2],tspnt);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1207 dct12(fsIn[sb+1],rawout1+18,rawout2+18,win1[2],tspnt+1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1208 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1209 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1210 else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1211 for (; sb<gr_info->maxb; sb+=2,tspnt+=2,rawout1+=36,rawout2+=36) {
1245
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
1212 (*dct36_func)(fsIn[sb],rawout1,rawout2,win[bt],tspnt);
03b7e2955a20 Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents: 716
diff changeset
1213 (*dct36_func)(fsIn[sb+1],rawout1+18,rawout2+18,win1[bt],tspnt+1);
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1214 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1215 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1216
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1217 for(;sb<SBLIMIT;sb++,tspnt++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1218 int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1219 for(i=0;i<SSLIMIT;i++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1220 tspnt[i*SBLIMIT] = *rawout1++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1221 *rawout2++ = 0.0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1222 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1223 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1224 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1225
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1226 /*
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1227 * main layer3 handler
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1228 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1229 /* int do_layer3(struct frame *fr,int outmode,struct audio_info_struct *ai) */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1230 static int do_layer3(struct frame *fr,int single){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1231 int gr, ch, ss,clip=0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1232 int scalefacs[2][39]; /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1233 struct III_sideinfo sideinfo;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1234 int stereo = fr->stereo;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1235 int ms_stereo,i_stereo;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1236 int sfreq = fr->sampling_frequency;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1237 int stereo1,granules;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1238
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1239 // if (fr->error_protection) getbits(16); /* skip crc */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1240
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1241 if(stereo == 1) { /* stream is mono */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1242 stereo1 = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1243 single = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1244 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1245 if(single >= 0) /* stream is stereo, but force to mono */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1246 stereo1 = 1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1247 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1248 stereo1 = 2;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1249
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1250 if(fr->mode == MPG_MD_JOINT_STEREO) {
10388
arpi
parents: 10349
diff changeset
1251 ms_stereo = (fr->mode_ext & 0x2)>>1;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1252 i_stereo = fr->mode_ext & 0x1;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1253 } else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1254 ms_stereo = i_stereo = 0;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1255
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1256 if(!III_get_side_info(&sideinfo,stereo,ms_stereo,sfreq,single,fr->lsf))
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1257 return -1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1258
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1259 set_pointer(sideinfo.main_data_begin);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1260
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1261 granules = (fr->lsf) ? 1 : 2;
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1262 for (gr=0;gr<granules;gr++){
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1263 static real hybridIn[2][SBLIMIT][SSLIMIT];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1264 static real hybridOut[2][SSLIMIT][SBLIMIT];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1265
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1266 { struct gr_info_s *gr_info = &(sideinfo.ch[0].gr[gr]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1267 long part2bits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1268 if(fr->lsf)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1269 part2bits = III_get_scale_factors_2(scalefacs[0],gr_info,0);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1270 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1271 part2bits = III_get_scale_factors_1(scalefacs[0],gr_info);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1272 if(III_dequantize_sample(hybridIn[0], scalefacs[0],gr_info,sfreq,part2bits))
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1273 return clip;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1274 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1275
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1276 if(stereo == 2) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1277 struct gr_info_s *gr_info = &(sideinfo.ch[1].gr[gr]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1278
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1279 long part2bits;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1280 if(fr->lsf)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1281 part2bits = III_get_scale_factors_2(scalefacs[1],gr_info,i_stereo);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1282 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1283 part2bits = III_get_scale_factors_1(scalefacs[1],gr_info);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1284
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1285 if(III_dequantize_sample(hybridIn[1],scalefacs[1],gr_info,sfreq,part2bits))
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1286 return clip;
10343
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1287
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1288 if(ms_stereo) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1289 int i;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1290 int maxb = sideinfo.ch[0].gr[gr].maxb;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1291 if(sideinfo.ch[1].gr[gr].maxb > maxb)
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1292 maxb = sideinfo.ch[1].gr[gr].maxb;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1293 for(i=0;i<SSLIMIT*maxb;i++) {
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1294 real tmp0 = ((real *)hybridIn[0])[i];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1295 real tmp1 = ((real *)hybridIn[1])[i];
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1296 ((real *)hybridIn[0])[i] = tmp0 + tmp1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1297 ((real *)hybridIn[1])[i] = tmp0 - tmp1;
b277842a74a2 merged with mpg123 0.59s-pre
arpi
parents: 10321
diff changeset
1298 }
1
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1299 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1300
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1301 if(i_stereo)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1302 III_i_stereo(hybridIn,scalefacs[1],gr_info,sfreq,ms_stereo,fr->lsf);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1303
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1304 if(ms_stereo || i_stereo || (single == 3) ) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1305 if(gr_info->maxb > sideinfo.ch[0].gr[gr].maxb)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1306 sideinfo.ch[0].gr[gr].maxb = gr_info->maxb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1307 else
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1308 gr_info->maxb = sideinfo.ch[0].gr[gr].maxb;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1309 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1310
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1311 switch(single) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1312 case 3: {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1313 register int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1314 register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1315 for(i=0;i<SSLIMIT*gr_info->maxb;i++,in0++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1316 *in0 = (*in0 + *in1++); /* *0.5 done by pow-scale */
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1317 break; }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1318 case 1: {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1319 register int i;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1320 register real *in0 = (real *) hybridIn[0],*in1 = (real *) hybridIn[1];
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1321 for(i=0;i<SSLIMIT*gr_info->maxb;i++)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1322 *in0++ = *in1++;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1323 break; }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1324 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1325
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1326 } // if(stereo == 2)
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1327
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1328 for(ch=0;ch<stereo1;ch++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1329 struct gr_info_s *gr_info = &(sideinfo.ch[ch].gr[gr]);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1330 III_antialias(hybridIn[ch],gr_info);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1331 III_hybrid(hybridIn[ch], hybridOut[ch], ch,gr_info);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1332 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1333
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1334 for(ss=0;ss<SSLIMIT;ss++) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1335 if(single >= 0) {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1336 clip += (fr->synth_mono)(hybridOut[0][ss],pcm_sample,&pcm_point);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1337 } else {
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1338 int p1 = pcm_point;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1339 clip += (fr->synth)(hybridOut[0][ss],0,pcm_sample,&p1);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1340 clip += (fr->synth)(hybridOut[1][ss],1,pcm_sample,&pcm_point);
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1341 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1342 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1343
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1344 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1345
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1346 return clip;
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1347 }
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1348
3b5f5d1c5041 Initial revision
arpi_esp
parents:
diff changeset
1349