Mercurial > mplayer.hg
comparison mp3lib/decod386.c @ 1:3b5f5d1c5041
Initial revision
author | arpi_esp |
---|---|
date | Sat, 24 Feb 2001 20:28:24 +0000 |
parents | |
children | e14114170e01 |
comparison
equal
deleted
inserted
replaced
0:c1bb2c071d63 | 1:3b5f5d1c5041 |
---|---|
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 | |
14 | |
15 /* new WRITE_SAMPLE */ | |
16 /* sizeof(int) == 4 */ | |
17 #define WRITE_SAMPLE(samples,sum,clip) { \ | |
18 double dtemp; long v; \ | |
19 dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) + (sum);\ | |
20 v = ((*(int *)&dtemp) - 0x80000000); \ | |
21 if( v > 32767) { *(samples) = 0x7fff; (clip)++; } \ | |
22 else if( v < -32768) { *(samples) = -0x8000; (clip)++; } \ | |
23 else { *(samples) = v; } \ | |
24 } | |
25 | |
26 | |
27 /* | |
28 #define WRITE_SAMPLE(samples,sum,clip) { \ | |
29 double dtemp; int v; \ | |
30 dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) + (sum);\ | |
31 v = ((*(int *)&dtemp) - 0x80000000); \ | |
32 if( v > 32767) { *(samples) = 0x7fff; (clip)++; } \ | |
33 else if( v < -32768) { *(samples) = -0x8000; (clip)++; } \ | |
34 else { *(samples) = v; } \ | |
35 } | |
36 */ | |
37 | |
38 static int synth_1to1_mono(real *bandPtr,unsigned char *samples,int *pnt) | |
39 { | |
40 short samples_tmp[64]; | |
41 short *tmp1 = samples_tmp; | |
42 int i,ret; | |
43 int pnt1 = 0; | |
44 | |
45 ret = synth_1to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1); | |
46 samples += *pnt; | |
47 | |
48 for(i=0;i<32;i++) { | |
49 *( (short *) samples) = *tmp1; | |
50 samples += 2; | |
51 tmp1 += 2; | |
52 } | |
53 *pnt += 64; | |
54 | |
55 return ret; | |
56 } | |
57 | |
58 | |
59 static int synth_1to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt) | |
60 { | |
61 int i,ret; | |
62 | |
63 ret = synth_1to1(bandPtr,0,samples,pnt); | |
64 samples = samples + *pnt - 128; | |
65 | |
66 for(i=0;i<32;i++) { | |
67 ((short *)samples)[1] = ((short *)samples)[0]; | |
68 samples+=4; | |
69 } | |
70 | |
71 return ret; | |
72 } | |
73 | |
74 | |
75 static int synth_1to1(real *bandPtr,int channel,unsigned char *out,int *pnt) | |
76 { | |
77 static real buffs[2][2][0x110]; | |
78 static const int step = 2; | |
79 static int bo = 1; | |
80 short *samples = (short *) (out + *pnt); | |
81 | |
82 real *b0,(*buf)[0x110]; | |
83 int clip = 0; | |
84 int bo1; | |
85 | |
86 #ifdef HAVE_3DNOW | |
87 if ( _3dnow ) | |
88 { | |
89 int ret; | |
90 ret=synth_1to1_3dnow( bandPtr,channel,out+*pnt ); | |
91 *pnt+=128; | |
92 return ret; | |
93 } | |
94 #endif | |
95 if ( _i586 ) | |
96 { | |
97 int ret; | |
98 ret=synth_1to1_pent( bandPtr,channel,out+*pnt ); | |
99 *pnt+=128; | |
100 return ret; | |
101 } | |
102 | |
103 if(!channel) { /* channel=0 */ | |
104 bo--; | |
105 bo &= 0xf; | |
106 buf = buffs[0]; | |
107 } | |
108 else { | |
109 samples++; | |
110 buf = buffs[1]; | |
111 } | |
112 | |
113 if(bo & 0x1) { | |
114 b0 = buf[0]; | |
115 bo1 = bo; | |
116 dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr); | |
117 } | |
118 else { | |
119 b0 = buf[1]; | |
120 bo1 = bo+1; | |
121 dct64(buf[0]+bo,buf[1]+bo+1,bandPtr); | |
122 } | |
123 | |
124 { | |
125 register int j; | |
126 real *window = decwin + 16 - bo1; | |
127 | |
128 for (j=16;j;j--,b0+=0x10,window+=0x20,samples+=step) | |
129 { | |
130 real sum; | |
131 sum = window[0x0] * b0[0x0]; | |
132 sum -= window[0x1] * b0[0x1]; | |
133 sum += window[0x2] * b0[0x2]; | |
134 sum -= window[0x3] * b0[0x3]; | |
135 sum += window[0x4] * b0[0x4]; | |
136 sum -= window[0x5] * b0[0x5]; | |
137 sum += window[0x6] * b0[0x6]; | |
138 sum -= window[0x7] * b0[0x7]; | |
139 sum += window[0x8] * b0[0x8]; | |
140 sum -= window[0x9] * b0[0x9]; | |
141 sum += window[0xA] * b0[0xA]; | |
142 sum -= window[0xB] * b0[0xB]; | |
143 sum += window[0xC] * b0[0xC]; | |
144 sum -= window[0xD] * b0[0xD]; | |
145 sum += window[0xE] * b0[0xE]; | |
146 sum -= window[0xF] * b0[0xF]; | |
147 | |
148 WRITE_SAMPLE(samples,sum,clip); | |
149 } | |
150 | |
151 { | |
152 real sum; | |
153 sum = window[0x0] * b0[0x0]; | |
154 sum += window[0x2] * b0[0x2]; | |
155 sum += window[0x4] * b0[0x4]; | |
156 sum += window[0x6] * b0[0x6]; | |
157 sum += window[0x8] * b0[0x8]; | |
158 sum += window[0xA] * b0[0xA]; | |
159 sum += window[0xC] * b0[0xC]; | |
160 sum += window[0xE] * b0[0xE]; | |
161 WRITE_SAMPLE(samples,sum,clip); | |
162 b0-=0x10,window-=0x20,samples+=step; | |
163 } | |
164 window += bo1<<1; | |
165 | |
166 for (j=15;j;j--,b0-=0x10,window-=0x20,samples+=step) | |
167 { | |
168 real sum; | |
169 sum = -window[-0x1] * b0[0x0]; | |
170 sum -= window[-0x2] * b0[0x1]; | |
171 sum -= window[-0x3] * b0[0x2]; | |
172 sum -= window[-0x4] * b0[0x3]; | |
173 sum -= window[-0x5] * b0[0x4]; | |
174 sum -= window[-0x6] * b0[0x5]; | |
175 sum -= window[-0x7] * b0[0x6]; | |
176 sum -= window[-0x8] * b0[0x7]; | |
177 sum -= window[-0x9] * b0[0x8]; | |
178 sum -= window[-0xA] * b0[0x9]; | |
179 sum -= window[-0xB] * b0[0xA]; | |
180 sum -= window[-0xC] * b0[0xB]; | |
181 sum -= window[-0xD] * b0[0xC]; | |
182 sum -= window[-0xE] * b0[0xD]; | |
183 sum -= window[-0xF] * b0[0xE]; | |
184 sum -= window[-0x0] * b0[0xF]; | |
185 | |
186 WRITE_SAMPLE(samples,sum,clip); | |
187 } | |
188 } | |
189 *pnt += 128; | |
190 | |
191 return clip; | |
192 | |
193 } | |
194 |