2
* Mpeg Layer-1,2,3 audio decoder
3
* ------------------------------
4
* copyright (c) 1995 by Michael Hipp, All rights reserved. See also 'README'
5
* version for slower machines .. decodes only every second sample
6
* sounds like 24000,22050 or 16000 kHz .. (depending on original sample freq.)
16
#define WRITE_SAMPLE(samples,sum,clip) \
17
if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
18
else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
19
else { *(samples) = sum; }
21
int synth_2to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
23
short samples_tmp[32];
24
short *tmp1 = samples_tmp + channel;
28
ret = synth_2to1(bandPtr,channel,(unsigned char *) samples_tmp,&pnt1);
29
samples += channel + *pnt;
32
*samples = conv16to8[*tmp1>>AUSHIFT];
41
int synth_2to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt)
43
short samples_tmp[32];
44
short *tmp1 = samples_tmp;
48
ret = synth_2to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
52
*samples++ = conv16to8[*tmp1>>AUSHIFT];
61
int synth_2to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
63
short samples_tmp[32];
64
short *tmp1 = samples_tmp;
68
ret = synth_2to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
72
*samples++ = conv16to8[*tmp1>>AUSHIFT];
73
*samples++ = conv16to8[*tmp1>>AUSHIFT];
81
int synth_2to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
83
short samples_tmp[32];
84
short *tmp1 = samples_tmp;
88
ret = synth_2to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
92
*( (short *) samples) = *tmp1;
101
int synth_2to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
105
ret = synth_2to1(bandPtr,0,samples,pnt);
106
samples = samples + *pnt - 64;
109
((short *)samples)[1] = ((short *)samples)[0];
116
int synth_2to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
118
static real buffs[2][2][0x110];
119
static const int step = 2;
121
short *samples = (short *) (out + *pnt);
123
real *b0,(*buf)[0x110];
128
do_equalizer(bandPtr,channel);
143
dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
148
dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
153
real *window = decwin + 16 - bo1;
155
for (j=8;j;j--,b0+=0x10,window+=0x30)
158
sum = *window++ * *b0++;
159
sum -= *window++ * *b0++;
160
sum += *window++ * *b0++;
161
sum -= *window++ * *b0++;
162
sum += *window++ * *b0++;
163
sum -= *window++ * *b0++;
164
sum += *window++ * *b0++;
165
sum -= *window++ * *b0++;
166
sum += *window++ * *b0++;
167
sum -= *window++ * *b0++;
168
sum += *window++ * *b0++;
169
sum -= *window++ * *b0++;
170
sum += *window++ * *b0++;
171
sum -= *window++ * *b0++;
172
sum += *window++ * *b0++;
173
sum -= *window++ * *b0++;
175
WRITE_SAMPLE(samples,sum,clip); samples += step;
177
WRITE_SAMPLE(samples,sum,clip); samples += step;
183
sum = window[0x0] * b0[0x0];
184
sum += window[0x2] * b0[0x2];
185
sum += window[0x4] * b0[0x4];
186
sum += window[0x6] * b0[0x6];
187
sum += window[0x8] * b0[0x8];
188
sum += window[0xA] * b0[0xA];
189
sum += window[0xC] * b0[0xC];
190
sum += window[0xE] * b0[0xE];
191
WRITE_SAMPLE(samples,sum,clip); samples += step;
193
WRITE_SAMPLE(samples,sum,clip); samples += step;
195
b0-=0x20,window-=0x40;
199
for (j=7;j;j--,b0-=0x30,window-=0x30)
202
sum = -*(--window) * *b0++;
203
sum -= *(--window) * *b0++;
204
sum -= *(--window) * *b0++;
205
sum -= *(--window) * *b0++;
206
sum -= *(--window) * *b0++;
207
sum -= *(--window) * *b0++;
208
sum -= *(--window) * *b0++;
209
sum -= *(--window) * *b0++;
210
sum -= *(--window) * *b0++;
211
sum -= *(--window) * *b0++;
212
sum -= *(--window) * *b0++;
213
sum -= *(--window) * *b0++;
214
sum -= *(--window) * *b0++;
215
sum -= *(--window) * *b0++;
216
sum -= *(--window) * *b0++;
217
sum -= *(--window) * *b0++;
219
WRITE_SAMPLE(samples,sum,clip); samples += step;
221
WRITE_SAMPLE(samples,sum,clip); samples += step;