Mercurial > mplayer.hg
annotate mp3lib/decod386.c @ 5791:b584598afac9
changed back to AFMT_AC3 (but now libao2 drivers autodetect it and fallback to S16) - idea by Vincent.Mussard@lineae.net
author | arpi |
---|---|
date | Mon, 22 Apr 2002 22:34:37 +0000 |
parents | 63fb32311b3b |
children | 131497b1f6ad |
rev | line source |
---|---|
1 | 1 /* |
2 * Mpeg Layer-1,2,3 audio decoder | |
3 * ------------------------------ | |
4 * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved. | |
5 * See also 'README' | |
6 * | |
7 * slighlty optimized for machines without autoincrement/decrement. | |
8 * The performance is highly compiler dependend. Maybe | |
9 * the decode.c version for 'normal' processor may be faster | |
10 * even for Intel processors. | |
11 */ | |
12 | |
13 | |
1318
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
14 #include "../config.h" |
1 | 15 |
4321 | 16 #ifndef CAN_COMPILE_X86 |
17 #ifdef ARCH_X86 | |
18 #define CAN_COMPILE_X86 | |
19 #endif | |
20 #endif | |
21 | |
22 | |
1318
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
23 #if 0 |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
24 /* old WRITE_SAMPLE */ |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
25 /* is portable */ |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
26 #define WRITE_SAMPLE(samples,sum,clip) { \ |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
27 if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \ |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
28 else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; }\ |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
29 else { *(samples) = sum; } \ |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
30 } |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
31 #else |
1 | 32 /* new WRITE_SAMPLE */ |
1318
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
33 |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
34 /* |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
35 * should be the same as the "old WRITE_SAMPLE" macro above, but uses |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
36 * some tricks to avoid double->int conversions and floating point compares. |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
37 * |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
38 * Here's how it works: |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
39 * ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) is |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
40 * 0x0010000080000000LL in hex. It computes 0x0010000080000000LL + sum |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
41 * as a double IEEE fp value and extracts the low-order 32-bits from the |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
42 * IEEE fp representation stored in memory. The 2^56 bit in the constant |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
43 * is intended to force the bits of "sum" into the least significant bits |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
44 * of the double mantissa. After an integer substraction of 0x80000000 |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
45 * we have the original double value "sum" converted to an 32-bit int value. |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
46 * |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
47 * (Is that really faster than the clean and simple old version of the macro?) |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
48 */ |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
49 |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
50 /* |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
51 * On a SPARC cpu, we fetch the low-order 32-bit from the second 32-bit |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
52 * word of the double fp value stored in memory. On an x86 cpu, we fetch it |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
53 * from the first 32-bit word. |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
54 * I'm not sure if the WORDS_BIGENDIAN feature test covers all possible memory |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
55 * layouts of double floating point values an all cpu architectures. If |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
56 * it doesn't work for you, just enable the "old WRITE_SAMPLE" macro. |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
57 */ |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
58 #if WORDS_BIGENDIAN |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
59 #define MANTISSA_OFFSET 1 |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
60 #else |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
61 #define MANTISSA_OFFSET 0 |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
62 #endif |
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
63 |
1 | 64 /* sizeof(int) == 4 */ |
65 #define WRITE_SAMPLE(samples,sum,clip) { \ | |
1941
2668fc1b8839
Fix for mp3 decoding on alpha/64bit platforms wupposed by Bob McElrath.
atmos4
parents:
1318
diff
changeset
|
66 double dtemp; int v; \ |
1 | 67 dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) + (sum);\ |
1318
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
68 v = (((int *)&dtemp)[MANTISSA_OFFSET] - 0x80000000); \ |
1 | 69 if( v > 32767) { *(samples) = 0x7fff; (clip)++; } \ |
70 else if( v < -32768) { *(samples) = -0x8000; (clip)++; } \ | |
71 else { *(samples) = v; } \ | |
72 } | |
1318
2052e18abd9d
mp3 audio decoding didn't work on big-endian architectures
jkeil
parents:
1258
diff
changeset
|
73 #endif |
1 | 74 |
75 | |
76 /* | |
77 #define WRITE_SAMPLE(samples,sum,clip) { \ | |
78 double dtemp; int v; \ | |
79 dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) + (sum);\ | |
80 v = ((*(int *)&dtemp) - 0x80000000); \ | |
81 if( v > 32767) { *(samples) = 0x7fff; (clip)++; } \ | |
82 else if( v < -32768) { *(samples) = -0x8000; (clip)++; } \ | |
83 else { *(samples) = v; } \ | |
84 } | |
85 */ | |
86 | |
87 static int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt) | |
88 { | |
89 short samples_tmp[64]; | |
90 short *tmp1 = samples_tmp; | |
91 int i,ret; | |
92 int pnt1 = 0; | |
93 | |
94 ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); | |
95 samples += *pnt; | |
96 | |
97 for(i=0;i<32;i++) { | |
98 *( (short *) samples) = *tmp1; | |
99 samples += 2; | |
100 tmp1 += 2; | |
101 } | |
102 *pnt += 64; | |
103 | |
104 return ret; | |
105 } | |
106 | |
107 | |
108 static int synth_1to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) | |
109 { | |
110 int i,ret; | |
111 | |
112 ret = synth_1to1(bandPtr,0,samples,pnt); | |
113 samples = samples + *pnt - 128; | |
114 | |
115 for(i=0;i<32;i++) { | |
116 ((short *)samples)[1] = ((short *)samples)[0]; | |
117 samples+=4; | |
118 } | |
119 | |
120 return ret; | |
121 } | |
122 | |
123 | |
732
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
124 #ifdef USE_FAKE_MONO |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
125 static int synth_1to1_l(real *bandPtr,int channel,unsigned char *out,int *pnt) |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
126 { |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
127 int i,ret; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
128 |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
129 ret = synth_1to1(bandPtr,channel,out,pnt); |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
130 out = out + *pnt - 128; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
131 |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
132 for(i=0;i<32;i++) { |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
133 ((short *)out)[1] = ((short *)out)[0]; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
134 out+=4; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
135 } |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
136 |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
137 return ret; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
138 } |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
139 |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
140 |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
141 static int synth_1to1_r(real *bandPtr,int channel,unsigned char *out,int *pnt) |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
142 { |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
143 int i,ret; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
144 |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
145 ret = synth_1to1(bandPtr,channel,out,pnt); |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
146 out = out + *pnt - 128; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
147 |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
148 for(i=0;i<32;i++) { |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
149 ((short *)out)[0] = ((short *)out)[1]; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
150 out+=4; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
151 } |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
152 |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
153 return ret; |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
154 } |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
155 #endif |
e14114170e01
applied 'fakemono' patch by Bryan Chan scorpio@acm.org
arpi_esp
parents:
1
diff
changeset
|
156 |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
787
diff
changeset
|
157 synth_func_t synth_func; |
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
787
diff
changeset
|
158 |
4321 | 159 #if defined(CAN_COMPILE_X86_ASM) |
1942
853be3ebe862
Eeeh I need some sleep, accidently commited a wrong version of the files that had other changes, too.
atmos4
parents:
1941
diff
changeset
|
160 int synth_1to1_MMX( real *bandPtr,int channel,short * samples) |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
787
diff
changeset
|
161 { |
1942
853be3ebe862
Eeeh I need some sleep, accidently commited a wrong version of the files that had other changes, too.
atmos4
parents:
1941
diff
changeset
|
162 static short buffs[2][2][0x110]; |
853be3ebe862
Eeeh I need some sleep, accidently commited a wrong version of the files that had other changes, too.
atmos4
parents:
1941
diff
changeset
|
163 static int bo = 1; |
853be3ebe862
Eeeh I need some sleep, accidently commited a wrong version of the files that had other changes, too.
atmos4
parents:
1941
diff
changeset
|
164 synth_1to1_MMX_s(bandPtr, channel, samples, (short *) buffs, &bo); |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
787
diff
changeset
|
165 return 0; |
1258 | 166 } |
167 #endif | |
1 | 168 static int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt) |
169 { | |
170 static real buffs[2][2][0x110]; | |
171 static const int step = 2; | |
172 static int bo = 1; | |
173 short *samples = (short *) (out + *pnt); | |
174 | |
175 real *b0,(*buf)[0x110]; | |
176 int clip = 0; | |
177 int bo1; | |
4149 | 178 /* optimized for x86 */ |
4321 | 179 #if defined(CAN_COMPILE_X86_ASM) |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
787
diff
changeset
|
180 if ( synth_func ) |
787 | 181 { |
182 int ret; | |
1245
03b7e2955a20
Added newest MMX-optimized decore which speedups decoding at least on 13% for any cpu.
nick
parents:
787
diff
changeset
|
183 ret=(*synth_func)( bandPtr,channel,samples); |
736 | 184 *pnt+=128; |
185 return ret; | |
186 } | |
1258 | 187 #endif |
1 | 188 if(!channel) { /* channel=0 */ |
189 bo--; | |
190 bo &= 0xf; | |
191 buf = buffs[0]; | |
192 } | |
193 else { | |
194 samples++; | |
195 buf = buffs[1]; | |
196 } | |
197 | |
198 if(bo & 0x1) { | |
199 b0 = buf[0]; | |
200 bo1 = bo; | |
201 dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); | |
202 } | |
203 else { | |
204 b0 = buf[1]; | |
205 bo1 = bo+1; | |
206 dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); | |
207 } | |
208 | |
209 { | |
210 register int j; | |
211 real *window = decwin + 16 - bo1; | |
212 | |
213 for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) | |
214 { | |
215 real sum; | |
216 sum = window[0x0] * b0[0x0]; | |
217 sum -= window[0x1] * b0[0x1]; | |
218 sum += window[0x2] * b0[0x2]; | |
219 sum -= window[0x3] * b0[0x3]; | |
220 sum += window[0x4] * b0[0x4]; | |
221 sum -= window[0x5] * b0[0x5]; | |
222 sum += window[0x6] * b0[0x6]; | |
223 sum -= window[0x7] * b0[0x7]; | |
224 sum += window[0x8] * b0[0x8]; | |
225 sum -= window[0x9] * b0[0x9]; | |
226 sum += window[0xA] * b0[0xA]; | |
227 sum -= window[0xB] * b0[0xB]; | |
228 sum += window[0xC] * b0[0xC]; | |
229 sum -= window[0xD] * b0[0xD]; | |
230 sum += window[0xE] * b0[0xE]; | |
231 sum -= window[0xF] * b0[0xF]; | |
232 | |
233 WRITE_SAMPLE(samples,sum,clip); | |
234 } | |
235 | |
236 { | |
237 real sum; | |
238 sum = window[0x0] * b0[0x0]; | |
239 sum += window[0x2] * b0[0x2]; | |
240 sum += window[0x4] * b0[0x4]; | |
241 sum += window[0x6] * b0[0x6]; | |
242 sum += window[0x8] * b0[0x8]; | |
243 sum += window[0xA] * b0[0xA]; | |
244 sum += window[0xC] * b0[0xC]; | |
245 sum += window[0xE] * b0[0xE]; | |
246 WRITE_SAMPLE(samples,sum,clip); | |
247 b0-=0x10,window-=0x20,samples+=step; | |
248 } | |
249 window += bo1<<1; | |
250 | |
251 for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) | |
252 { | |
253 real sum; | |
254 sum = -window[-0x1] * b0[0x0]; | |
255 sum -= window[-0x2] * b0[0x1]; | |
256 sum -= window[-0x3] * b0[0x2]; | |
257 sum -= window[-0x4] * b0[0x3]; | |
258 sum -= window[-0x5] * b0[0x4]; | |
259 sum -= window[-0x6] * b0[0x5]; | |
260 sum -= window[-0x7] * b0[0x6]; | |
261 sum -= window[-0x8] * b0[0x7]; | |
262 sum -= window[-0x9] * b0[0x8]; | |
263 sum -= window[-0xA] * b0[0x9]; | |
264 sum -= window[-0xB] * b0[0xA]; | |
265 sum -= window[-0xC] * b0[0xB]; | |
266 sum -= window[-0xD] * b0[0xC]; | |
267 sum -= window[-0xE] * b0[0xD]; | |
268 sum -= window[-0xF] * b0[0xE]; | |
269 sum -= window[-0x0] * b0[0xF]; | |
270 | |
271 WRITE_SAMPLE(samples,sum,clip); | |
272 } | |
273 } | |
274 *pnt += 128; | |
275 | |
276 return clip; | |
277 | |
278 } | |
279 |