Mercurial > mplayer.hg
annotate mp3lib/layer2.c @ 25721:c0e76b0bb543
Don't oversize realchallenge buffers
author | rtogni |
---|---|
date | Sun, 13 Jan 2008 21:12:02 +0000 |
parents | 1b1fdac4a68c |
children | 0f1b5b68af32 |
rev | line source |
---|---|
15167
07e7a572bd84
Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents:
13336
diff
changeset
|
1 /* |
18783 | 2 * Modified for use with MPlayer, for details see the changelog at |
3 * http://svn.mplayerhq.hu/mplayer/trunk/ | |
15167
07e7a572bd84
Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents:
13336
diff
changeset
|
4 * $Id$ |
07e7a572bd84
Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents:
13336
diff
changeset
|
5 */ |
07e7a572bd84
Mark modified imported files as such to comply with (L)GPL ¡ø2a.
diego
parents:
13336
diff
changeset
|
6 |
1 | 7 /* |
8 * Mpeg Layer-2 audio decoder | |
9 * -------------------------- | |
10 * copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README' | |
11 * | |
12 */ | |
13 | |
14 //#include "mpg123.h" | |
15 #include "l2tables.h" | |
16 | |
17 static int grp_3tab[32 * 3] = { 0, }; /* used: 27 */ | |
18 static int grp_5tab[128 * 3] = { 0, }; /* used: 125 */ | |
19 static int grp_9tab[1024 * 3] = { 0, }; /* used: 729 */ | |
20 | |
21 static real muls[27][64]; /* also used by layer 1 */ | |
22 | |
23 static void init_layer2(void) | |
24 { | |
25 static double mulmul[27] = { | |
26 0.0 , -2.0/3.0 , 2.0/3.0 , | |
27 2.0/7.0 , 2.0/15.0 , 2.0/31.0, 2.0/63.0 , 2.0/127.0 , 2.0/255.0 , | |
28 2.0/511.0 , 2.0/1023.0 , 2.0/2047.0 , 2.0/4095.0 , 2.0/8191.0 , | |
29 2.0/16383.0 , 2.0/32767.0 , 2.0/65535.0 , | |
30 -4.0/5.0 , -2.0/5.0 , 2.0/5.0, 4.0/5.0 , | |
31 -8.0/9.0 , -4.0/9.0 , -2.0/9.0 , 2.0/9.0 , 4.0/9.0 , 8.0/9.0 }; | |
32 static int base[3][9] = { | |
33 { 1 , 0, 2 , } , | |
34 { 17, 18, 0 , 19, 20 , } , | |
35 { 21, 1, 22, 23, 0, 24, 25, 2, 26 } }; | |
36 int i,j,k,l,len; | |
37 real *table; | |
38 static int tablen[3] = { 3 , 5 , 9 }; | |
39 static int *itable,*tables[3] = { grp_3tab , grp_5tab , grp_9tab }; | |
40 | |
41 for(i=0;i<3;i++) | |
42 { | |
43 itable = tables[i]; | |
44 len = tablen[i]; | |
45 for(j=0;j<len;j++) | |
46 for(k=0;k<len;k++) | |
47 for(l=0;l<len;l++) | |
48 { | |
49 *itable++ = base[i][l]; | |
50 *itable++ = base[i][k]; | |
51 *itable++ = base[i][j]; | |
52 } | |
53 } | |
54 | |
55 for(k=0;k<27;k++) | |
56 { | |
57 double m=mulmul[k]; | |
58 table = muls[k]; | |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
1
diff
changeset
|
59 if(_has_mmx) |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
1
diff
changeset
|
60 { |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
1
diff
changeset
|
61 for(j=3,i=0;i<63;i++,j--) |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
1
diff
changeset
|
62 *table++ = 16384 * m * pow(2.0,(double) j / 3.0); |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
1
diff
changeset
|
63 } |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
1
diff
changeset
|
64 else |
1 | 65 for(j=3,i=0;i<63;i++,j--) |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
1
diff
changeset
|
66 { |
1 | 67 *table++ = m * pow(2.0,(double) j / 3.0); |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
1
diff
changeset
|
68 } |
1 | 69 *table++ = 0.0; |
70 } | |
71 } | |
72 | |
73 | |
74 static void II_step_one(unsigned int *bit_alloc,int *scale,struct frame *fr) | |
75 { | |
76 int stereo = fr->stereo-1; | |
77 int sblimit = fr->II_sblimit; | |
78 int jsbound = fr->jsbound; | |
79 int sblimit2 = fr->II_sblimit<<stereo; | |
80 struct al_table *alloc1 = fr->alloc; | |
81 int i; | |
82 static unsigned int scfsi_buf[64]; | |
83 unsigned int *scfsi,*bita; | |
84 int sc,step; | |
85 | |
86 bita = bit_alloc; | |
87 if(stereo) | |
88 { | |
13336
55174e3d2917
Index must be positive to prevent endless loop on bad data
rtognimp
parents:
12131
diff
changeset
|
89 for (i=jsbound;i>0;i--,alloc1+=(1<<step)) |
1 | 90 { |
91 *bita++ = (char) getbits(step=alloc1->bits); | |
92 *bita++ = (char) getbits(step); | |
93 } | |
13336
55174e3d2917
Index must be positive to prevent endless loop on bad data
rtognimp
parents:
12131
diff
changeset
|
94 for (i=sblimit-jsbound;i>0;i--,alloc1+=(1<<step)) |
1 | 95 { |
96 bita[0] = (char) getbits(step=alloc1->bits); | |
97 bita[1] = bita[0]; | |
98 bita+=2; | |
99 } | |
100 bita = bit_alloc; | |
101 scfsi=scfsi_buf; | |
13336
55174e3d2917
Index must be positive to prevent endless loop on bad data
rtognimp
parents:
12131
diff
changeset
|
102 for (i=sblimit2;i>0;i--) |
1 | 103 if (*bita++) |
104 *scfsi++ = (char) getbits_fast(2); | |
105 } | |
106 else /* mono */ | |
107 { | |
13336
55174e3d2917
Index must be positive to prevent endless loop on bad data
rtognimp
parents:
12131
diff
changeset
|
108 for (i=sblimit;i>0;i--,alloc1+=(1<<step)) |
1 | 109 *bita++ = (char) getbits(step=alloc1->bits); |
110 bita = bit_alloc; | |
111 scfsi=scfsi_buf; | |
13336
55174e3d2917
Index must be positive to prevent endless loop on bad data
rtognimp
parents:
12131
diff
changeset
|
112 for (i=sblimit;i>0;i--) |
1 | 113 if (*bita++) |
114 *scfsi++ = (char) getbits_fast(2); | |
115 } | |
116 | |
117 bita = bit_alloc; | |
118 scfsi=scfsi_buf; | |
13336
55174e3d2917
Index must be positive to prevent endless loop on bad data
rtognimp
parents:
12131
diff
changeset
|
119 for (i=sblimit2;i>0;i--) |
1 | 120 if (*bita++) |
121 switch (*scfsi++) | |
122 { | |
123 case 0: | |
124 *scale++ = getbits_fast(6); | |
125 *scale++ = getbits_fast(6); | |
126 *scale++ = getbits_fast(6); | |
127 break; | |
128 case 1 : | |
129 *scale++ = sc = getbits_fast(6); | |
130 *scale++ = sc; | |
131 *scale++ = getbits_fast(6); | |
132 break; | |
133 case 2: | |
134 *scale++ = sc = getbits_fast(6); | |
135 *scale++ = sc; | |
136 *scale++ = sc; | |
137 break; | |
138 default: /* case 3 */ | |
139 *scale++ = getbits_fast(6); | |
140 *scale++ = sc = getbits_fast(6); | |
141 *scale++ = sc; | |
142 break; | |
143 } | |
144 | |
145 } | |
146 | |
147 static void II_step_two(unsigned int *bit_alloc,real fraction[2][4][SBLIMIT],int *scale,struct frame *fr,int x1) | |
148 { | |
149 int i,j,k,ba; | |
150 int stereo = fr->stereo; | |
151 int sblimit = fr->II_sblimit; | |
152 int jsbound = fr->jsbound; | |
153 struct al_table *alloc2,*alloc1 = fr->alloc; | |
154 unsigned int *bita=bit_alloc; | |
155 int d1,step; | |
156 | |
157 for (i=0;i<jsbound;i++,alloc1+=(1<<step)) | |
158 { | |
159 step = alloc1->bits; | |
160 for (j=0;j<stereo;j++) | |
161 { | |
162 if ( (ba=*bita++) ) | |
163 { | |
164 k=(alloc2 = alloc1+ba)->bits; | |
165 if( (d1=alloc2->d) < 0) | |
166 { | |
167 real cm=muls[k][scale[x1]]; | |
168 fraction[j][0][i] = ((real) ((int)getbits(k) + d1)) * cm; | |
169 fraction[j][1][i] = ((real) ((int)getbits(k) + d1)) * cm; | |
170 fraction[j][2][i] = ((real) ((int)getbits(k) + d1)) * cm; | |
171 } | |
172 else | |
173 { | |
174 static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab }; | |
175 unsigned int idx,*tab,m=scale[x1]; | |
176 idx = (unsigned int) getbits(k); | |
177 tab = (unsigned int *) (table[d1] + idx + idx + idx); | |
178 fraction[j][0][i] = muls[*tab++][m]; | |
179 fraction[j][1][i] = muls[*tab++][m]; | |
180 fraction[j][2][i] = muls[*tab][m]; | |
181 } | |
182 scale+=3; | |
183 } | |
184 else | |
185 fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; | |
186 } | |
187 } | |
188 | |
189 for (i=jsbound;i<sblimit;i++,alloc1+=(1<<step)) | |
190 { | |
191 step = alloc1->bits; | |
192 bita++; /* channel 1 and channel 2 bitalloc are the same */ | |
193 if ( (ba=*bita++) ) | |
194 { | |
195 k=(alloc2 = alloc1+ba)->bits; | |
196 if( (d1=alloc2->d) < 0) | |
197 { | |
198 real cm; | |
199 cm=muls[k][scale[x1+3]]; | |
200 fraction[1][0][i] = (fraction[0][0][i] = (real) ((int)getbits(k) + d1) ) * cm; | |
201 fraction[1][1][i] = (fraction[0][1][i] = (real) ((int)getbits(k) + d1) ) * cm; | |
202 fraction[1][2][i] = (fraction[0][2][i] = (real) ((int)getbits(k) + d1) ) * cm; | |
203 cm=muls[k][scale[x1]]; | |
204 fraction[0][0][i] *= cm; fraction[0][1][i] *= cm; fraction[0][2][i] *= cm; | |
205 } | |
206 else | |
207 { | |
208 static int *table[] = { 0,0,0,grp_3tab,0,grp_5tab,0,0,0,grp_9tab }; | |
209 unsigned int idx,*tab,m1,m2; | |
210 m1 = scale[x1]; m2 = scale[x1+3]; | |
211 idx = (unsigned int) getbits(k); | |
212 tab = (unsigned int *) (table[d1] + idx + idx + idx); | |
213 fraction[0][0][i] = muls[*tab][m1]; fraction[1][0][i] = muls[*tab++][m2]; | |
214 fraction[0][1][i] = muls[*tab][m1]; fraction[1][1][i] = muls[*tab++][m2]; | |
215 fraction[0][2][i] = muls[*tab][m1]; fraction[1][2][i] = muls[*tab][m2]; | |
216 } | |
217 scale+=6; | |
218 } | |
219 else { | |
220 fraction[0][0][i] = fraction[0][1][i] = fraction[0][2][i] = | |
221 fraction[1][0][i] = fraction[1][1][i] = fraction[1][2][i] = 0.0; | |
222 } | |
223 /* | |
224 should we use individual scalefac for channel 2 or | |
225 is the current way the right one , where we just copy channel 1 to | |
226 channel 2 ?? | |
227 The current 'strange' thing is, that we throw away the scalefac | |
228 values for the second channel ...!! | |
229 -> changed .. now we use the scalefac values of channel one !! | |
230 */ | |
231 } | |
232 | |
233 if(sblimit > (fr->down_sample_sblimit) ) | |
234 sblimit = fr->down_sample_sblimit; | |
235 | |
236 for(i=sblimit;i<SBLIMIT;i++) | |
237 for (j=0;j<stereo;j++) | |
238 fraction[j][0][i] = fraction[j][1][i] = fraction[j][2][i] = 0.0; | |
239 | |
240 } | |
241 | |
242 static void II_select_table(struct frame *fr) | |
243 { | |
9152 | 244 static int translate[9][2][16] = |
9130 | 245 { { { 0,2,2,2,2,2,2,0,0,0,1,1,1,1,1,0 } , /*44.1 stereo*/ |
246 { 0,2,2,0,0,0,1,1,1,1,1,1,1,1,1,0 } } , /*44.1 mono*/ | |
247 { { 0,2,2,2,2,2,2,0,0,0,0,0,0,0,0,0 } , /*48 stereo*/ | |
248 { 0,2,2,0,0,0,0,0,0,0,0,0,0,0,0,0 } } , /*48 mono*/ | |
249 { { 0,3,3,3,3,3,3,0,0,0,1,1,1,1,1,0 } , /*32 stereo*/ | |
250 { 0,3,3,0,0,0,1,1,1,1,1,1,1,1,1,0 } } , /*32 mono*/ | |
251 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*22.05 stereo*/ | |
252 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*22.05 mono*/ | |
253 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*24 stereo*/ | |
254 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*24 mono*/ | |
255 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*16 stereo*/ | |
256 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*16 mono*/ | |
257 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*11.025 stereo*/ | |
258 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*11.025 mono*/ | |
259 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*12 stereo*/ | |
260 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } , /*12 mono*/ | |
261 { { 2,2,2,2,2,2,2,3,3,3,3,3,3,3,3,0 } , /*8 stereo*/ | |
262 { 2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,0 } } /*8 mono*/ | |
263 /* 0 48 64 96 128 192 256 384 */ | |
264 /* 32 56 80 112 160 224 320 XX*/ | |
265 }; | |
1 | 266 |
267 int table,sblim; | |
268 static struct al_table *tables[5] = | |
269 { alloc_0, alloc_1, alloc_2, alloc_3 , alloc_4 }; | |
270 static int sblims[5] = { 27 , 30 , 8, 12 , 30 }; | |
271 | |
272 if(fr->lsf) | |
273 table = 4; | |
274 else | |
275 table = translate[fr->sampling_frequency][2-fr->stereo][fr->bitrate_index]; | |
276 sblim = sblims[table]; | |
277 | |
278 fr->alloc = tables[table]; | |
279 fr->II_sblimit = sblim; | |
280 } | |
281 | |
282 | |
12131
d155623271e3
fix symbol clashes when linking with libmp3lame including mp3 decoder, man, mp3lib is so much bloated
alex
parents:
9152
diff
changeset
|
283 static int do_layer2(struct frame *fr,int outmode) |
1 | 284 { |
285 int clip=0; | |
286 int i,j; | |
287 int stereo = fr->stereo; | |
23464
1b1fdac4a68c
Align output pointer so that we can use movaps instead of movups in dct64_sse;
zuxy
parents:
18783
diff
changeset
|
288 DECLARE_ALIGNED(16, real, fraction[2][4][SBLIMIT]); /* pick_table clears unused subbands */ |
1 | 289 unsigned int bit_alloc[64]; |
290 int scale[192]; | |
291 int single = fr->single; | |
292 | |
293 II_select_table(fr); | |
294 fr->jsbound = (fr->mode == MPG_MD_JOINT_STEREO) ? | |
295 (fr->mode_ext<<2)+4 : fr->II_sblimit; | |
296 | |
297 if(stereo == 1 || single == 3) | |
298 single = 0; | |
299 | |
300 II_step_one(bit_alloc, scale, fr); | |
301 | |
302 for (i=0;i<SCALE_BLOCK;i++) | |
303 { | |
304 II_step_two(bit_alloc,fraction,scale,fr,i>>2); | |
305 for (j=0;j<3;j++) | |
306 { | |
307 if(single >= 0) | |
308 { | |
309 clip += (fr->synth_mono) (fraction[single][j],pcm_sample,&pcm_point); | |
310 } | |
311 else { | |
312 int p1 = pcm_point; | |
313 clip += (fr->synth) (fraction[0][j],0,pcm_sample,&p1); | |
314 clip += (fr->synth) (fraction[1][j],1,pcm_sample,&pcm_point); | |
315 } | |
316 | |
317 // if(pcm_point >= audiobufsize) audio_flush(outmode,ai); | |
318 } | |
319 } | |
320 | |
321 return clip; | |
322 } |