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