61
|
1
|
|
2 /*
|
|
3 * Mpeg Layer-1,2,3 audio decoder
|
|
4 * ------------------------------
|
|
5 * copyright (c) 1995,1996,1997 by Michael Hipp, All rights reserved.
|
|
6 * See also 'README'
|
|
7 *
|
|
8 * slighlty optimized for machines without autoincrement/decrement.
|
|
9 * The performance is highly compiler dependend. Maybe
|
|
10 * the decode.c version for 'normal' processor may be faster
|
|
11 * even for Intel processors.
|
|
12 */
|
|
13
|
|
14 #include <stdlib.h>
|
|
15 #include <math.h>
|
|
16 #include <string.h>
|
|
17
|
|
18 #include "mpg123.h"
|
|
19
|
|
20 int mpg123_synth_1to1_pent(real *, int, unsigned char *);
|
|
21
|
|
22 #if 0
|
|
23 /* old WRITE_SAMPLE */
|
|
24 #define WRITE_SAMPLE(samples,sum,clip) \
|
|
25 if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
|
|
26 else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
|
|
27 else { *(samples) = sum; }
|
|
28 #else
|
|
29 /* new WRITE_SAMPLE */
|
|
30 #define WRITE_SAMPLE(samples,sum,clip) { \
|
|
31 double dtemp; int v; /* sizeof(int) == 4 */ \
|
|
32 dtemp = ((((65536.0 * 65536.0 * 16)+(65536.0 * 0.5))* 65536.0)) + (sum); \
|
|
33 v = ((*(int *)&dtemp) - 0x80000000); \
|
|
34 if( v > 32767) { *(samples) = 0x7fff; (clip)++; } \
|
|
35 else if( v < -32768) { *(samples) = -0x8000; (clip)++; } \
|
|
36 else { *(samples) = v; } \
|
|
37 }
|
|
38 #endif
|
|
39
|
|
40 int
|
|
41 mpg123_synth_1to1_8bit(real * bandPtr, int channel,
|
|
42 unsigned char *samples, int *pnt)
|
|
43 {
|
|
44 short samples_tmp[64];
|
|
45 short *tmp1 = samples_tmp + channel;
|
|
46 int i, ret;
|
|
47 int pnt1 = 0;
|
|
48
|
|
49 ret =
|
|
50 mpg123_synth_1to1(bandPtr, channel, (unsigned char *) samples_tmp,
|
|
51 &pnt1);
|
|
52 samples += channel + *pnt;
|
|
53
|
|
54 for (i = 0; i < 32; i++) {
|
|
55 *samples = (*tmp1 >> 8) ^ 128;
|
|
56 samples += 2;
|
|
57 tmp1 += 2;
|
|
58 }
|
|
59 *pnt += 64;
|
|
60
|
|
61 return ret;
|
|
62 }
|
|
63
|
|
64 int
|
|
65 mpg123_synth_1to1_8bit_mono(real * bandPtr, unsigned char *samples, int *pnt)
|
|
66 {
|
|
67 short samples_tmp[64];
|
|
68 short *tmp1 = samples_tmp;
|
|
69 int i, ret;
|
|
70 int pnt1 = 0;
|
|
71
|
|
72 ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
|
|
73 samples += *pnt;
|
|
74
|
|
75 for (i = 0; i < 32; i++) {
|
|
76 *samples++ = (*tmp1 >> 8) ^ 128;
|
|
77 tmp1 += 2;
|
|
78 }
|
|
79 *pnt += 32;
|
|
80
|
|
81 return ret;
|
|
82 }
|
|
83
|
|
84 #if 0
|
|
85 int
|
|
86 mpg123_synth_1to1_8bit_mono2stereo(real * bandPtr,
|
|
87 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 = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
|
|
95 samples += *pnt;
|
|
96
|
|
97 for (i = 0; i < 32; i++) {
|
|
98 *samples++ = (*tmp1 >> 8) ^ 128;
|
|
99 *samples++ = (*tmp1 >> 8) ^ 128;
|
|
100 tmp1 += 2;
|
|
101 }
|
|
102 *pnt += 64;
|
|
103
|
|
104 return ret;
|
|
105 }
|
|
106 #endif
|
|
107
|
|
108 int
|
|
109 mpg123_synth_1to1_mono(real * bandPtr, unsigned char *samples, int *pnt)
|
|
110 {
|
|
111 short samples_tmp[64];
|
|
112 short *tmp1 = samples_tmp;
|
|
113 int i, ret;
|
|
114 int pnt1 = 0;
|
|
115
|
|
116 ret = mpg123_synth_1to1(bandPtr, 0, (unsigned char *) samples_tmp, &pnt1);
|
|
117 samples += *pnt;
|
|
118
|
|
119 for (i = 0; i < 32; i++) {
|
|
120 *((short *) samples) = *tmp1;
|
|
121 samples += 2;
|
|
122 tmp1 += 2;
|
|
123 }
|
|
124 *pnt += 64;
|
|
125
|
|
126 return ret;
|
|
127 }
|
|
128
|
|
129 #if 0
|
|
130 int
|
|
131 mpg123_synth_1to1_mono2stereo(real * bandPtr, unsigned char *samples,
|
|
132 int *pnt)
|
|
133 {
|
|
134 int i, ret;
|
|
135
|
|
136 ret = mpg123_synth_1to1(bandPtr, 0, samples, pnt);
|
|
137 samples = samples + *pnt - 128;
|
|
138
|
|
139 for (i = 0; i < 32; i++) {
|
|
140 ((short *) samples)[1] = ((short *) samples)[0];
|
|
141 samples += 4;
|
|
142 }
|
|
143
|
|
144 return ret;
|
|
145 }
|
|
146 #endif
|
|
147
|
|
148 int
|
|
149 mpg123_synth_1to1(real * bandPtr, int channel, unsigned char *out, int *pnt)
|
|
150 {
|
|
151 #ifndef I386_ASSEM
|
|
152 static real buffs[2][2][0x110];
|
|
153 static const int step = 2;
|
|
154 static int bo = 1;
|
|
155 short *samples = (short *) (out + *pnt);
|
|
156
|
|
157 real *b0, (*buf)[0x110];
|
|
158 int clip = 0;
|
|
159 int bo1;
|
|
160
|
|
161 if (!channel) {
|
|
162 bo--;
|
|
163 bo &= 0xf;
|
|
164 buf = buffs[0];
|
|
165 }
|
|
166 else {
|
|
167 samples++;
|
|
168 buf = buffs[1];
|
|
169 }
|
|
170
|
|
171 if (bo & 0x1) {
|
|
172 b0 = buf[0];
|
|
173 bo1 = bo;
|
|
174 mpg123_dct64(buf[1] + ((bo + 1) & 0xf), buf[0] + bo, bandPtr);
|
|
175 }
|
|
176 else {
|
|
177 b0 = buf[1];
|
|
178 bo1 = bo + 1;
|
|
179 mpg123_dct64(buf[0] + bo, buf[1] + bo + 1, bandPtr);
|
|
180 }
|
|
181
|
|
182 {
|
|
183 register int j;
|
|
184 real *window = mpg123_decwin + 16 - bo1;
|
|
185
|
|
186 for (j = 16; j; j--, b0 += 0x10, window += 0x20, samples += step) {
|
|
187 real sum;
|
|
188
|
|
189 sum = window[0x0] * b0[0x0];
|
|
190 sum -= window[0x1] * b0[0x1];
|
|
191 sum += window[0x2] * b0[0x2];
|
|
192 sum -= window[0x3] * b0[0x3];
|
|
193 sum += window[0x4] * b0[0x4];
|
|
194 sum -= window[0x5] * b0[0x5];
|
|
195 sum += window[0x6] * b0[0x6];
|
|
196 sum -= window[0x7] * b0[0x7];
|
|
197 sum += window[0x8] * b0[0x8];
|
|
198 sum -= window[0x9] * b0[0x9];
|
|
199 sum += window[0xA] * b0[0xA];
|
|
200 sum -= window[0xB] * b0[0xB];
|
|
201 sum += window[0xC] * b0[0xC];
|
|
202 sum -= window[0xD] * b0[0xD];
|
|
203 sum += window[0xE] * b0[0xE];
|
|
204 sum -= window[0xF] * b0[0xF];
|
|
205
|
|
206 WRITE_SAMPLE(samples, sum, clip);
|
|
207 }
|
|
208
|
|
209 {
|
|
210 real sum;
|
|
211
|
|
212 sum = window[0x0] * b0[0x0];
|
|
213 sum += window[0x2] * b0[0x2];
|
|
214 sum += window[0x4] * b0[0x4];
|
|
215 sum += window[0x6] * b0[0x6];
|
|
216 sum += window[0x8] * b0[0x8];
|
|
217 sum += window[0xA] * b0[0xA];
|
|
218 sum += window[0xC] * b0[0xC];
|
|
219 sum += window[0xE] * b0[0xE];
|
|
220 WRITE_SAMPLE(samples, sum, clip);
|
|
221 b0 -= 0x10, window -= 0x20, samples += step;
|
|
222 }
|
|
223 window += bo1 << 1;
|
|
224
|
|
225 for (j = 15; j; j--, b0 -= 0x10, window -= 0x20, samples += step) {
|
|
226 real sum;
|
|
227
|
|
228 sum = -window[-0x1] * b0[0x0];
|
|
229 sum -= window[-0x2] * b0[0x1];
|
|
230 sum -= window[-0x3] * b0[0x2];
|
|
231 sum -= window[-0x4] * b0[0x3];
|
|
232 sum -= window[-0x5] * b0[0x4];
|
|
233 sum -= window[-0x6] * b0[0x5];
|
|
234 sum -= window[-0x7] * b0[0x6];
|
|
235 sum -= window[-0x8] * b0[0x7];
|
|
236 sum -= window[-0x9] * b0[0x8];
|
|
237 sum -= window[-0xA] * b0[0x9];
|
|
238 sum -= window[-0xB] * b0[0xA];
|
|
239 sum -= window[-0xC] * b0[0xB];
|
|
240 sum -= window[-0xD] * b0[0xC];
|
|
241 sum -= window[-0xE] * b0[0xD];
|
|
242 sum -= window[-0xF] * b0[0xE];
|
|
243 sum -= window[-0x0] * b0[0xF];
|
|
244
|
|
245 WRITE_SAMPLE(samples, sum, clip);
|
|
246 }
|
|
247 }
|
|
248 *pnt += 128;
|
|
249
|
|
250 return clip;
|
|
251 #else
|
|
252 {
|
|
253 int ret;
|
|
254
|
|
255 ret = mpg123_synth_1to1_pent(bandPtr, channel, out + *pnt);
|
|
256 *pnt += 128;
|
|
257 return ret;
|
|
258 }
|
|
259 #endif
|
|
260 }
|
|
261
|
|
262 #ifdef USE_SIMD
|
|
263 int mpg123_synth_MMX(real *, int, short *, short *, int *);
|
|
264
|
|
265 int
|
|
266 mpg123_synth_1to1_mmx(real * bandPtr, int channel, unsigned char *out,
|
|
267 int *pnt)
|
|
268 {
|
|
269 static short buffs[2][2][0x110];
|
|
270 static int bo = 1;
|
|
271 short *samples = (short *) (out + *pnt);
|
|
272
|
|
273 mpg123_synth_MMX(bandPtr, channel, samples, (short *) buffs, &bo);
|
|
274 *pnt += 128;
|
|
275 return 0;
|
|
276 }
|
|
277 #endif
|