2
decode_4to1.c: ...with 4to1 downsampling / decoding of every 4th sample
4
copyright 1995-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
5
see COPYING and AUTHORS files in distribution or http://mpg123.de
6
initially written by Michael Hipp
8
dunno why it sounds THIS annoying (maybe we should adapt the window?)
9
absolutely not optimized for this operation
19
#define WRITE_SAMPLE(samples,sum,clip) \
20
if( (sum) > 32767.0) { *(samples) = 0x7fff; (clip)++; } \
21
else if( (sum) < -32768.0) { *(samples) = -0x8000; (clip)++; } \
22
else { *(samples) = sum; }
24
int synth_4to1_8bit(real *bandPtr,int channel,unsigned char *samples,int *pnt)
26
short samples_tmp[16];
27
short *tmp1 = samples_tmp + channel;
31
ret = synth_4to1(bandPtr,channel,(unsigned char *) samples_tmp,&pnt1);
32
samples += channel + *pnt;
35
*samples = conv16to8[*tmp1>>AUSHIFT];
44
int synth_4to1_8bit_mono(real *bandPtr,unsigned char *samples,int *pnt)
46
short samples_tmp[16];
47
short *tmp1 = samples_tmp;
51
ret = synth_4to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
55
*samples++ = conv16to8[*tmp1>>AUSHIFT];
64
int synth_4to1_8bit_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
66
short samples_tmp[16];
67
short *tmp1 = samples_tmp;
71
ret = synth_4to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
75
*samples++ = conv16to8[*tmp1>>AUSHIFT];
76
*samples++ = conv16to8[*tmp1>>AUSHIFT];
84
int synth_4to1_mono(real *bandPtr,unsigned char *samples,int *pnt)
86
short samples_tmp[16];
87
short *tmp1 = samples_tmp;
91
ret = synth_4to1(bandPtr,0,(unsigned char *) samples_tmp,&pnt1);
95
*( (short *)samples) = *tmp1;
104
int synth_4to1_mono2stereo(real *bandPtr,unsigned char *samples,int *pnt)
108
ret = synth_4to1(bandPtr,0,samples,pnt);
109
samples = samples + *pnt - 32;
112
((short *)samples)[1] = ((short *)samples)[0];
119
int synth_4to1(real *bandPtr,int channel,unsigned char *out,int *pnt)
121
static real buffs[2][2][0x110];
122
static const int step = 2;
124
short *samples = (short *) (out + *pnt);
126
real *b0,(*buf)[0x110];
131
do_equalizer(bandPtr,channel);
146
dct64(buf[1]+((bo+1)&0xf),buf[0]+bo,bandPtr);
151
dct64(buf[0]+bo,buf[1]+bo+1,bandPtr);
156
real *window = decwin + 16 - bo1;
158
for (j=4;j;j--,b0+=0x30,window+=0x70)
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++;
174
sum -= *window++ * *b0++;
175
sum += *window++ * *b0++;
176
sum -= *window++ * *b0++;
178
WRITE_SAMPLE(samples,sum,clip); samples += step;
180
WRITE_SAMPLE(samples,sum,clip); samples += step;
181
WRITE_SAMPLE(samples,sum,clip); samples += step;
182
WRITE_SAMPLE(samples,sum,clip); samples += step;
188
sum = window[0x0] * b0[0x0];
189
sum += window[0x2] * b0[0x2];
190
sum += window[0x4] * b0[0x4];
191
sum += window[0x6] * b0[0x6];
192
sum += window[0x8] * b0[0x8];
193
sum += window[0xA] * b0[0xA];
194
sum += window[0xC] * b0[0xC];
195
sum += window[0xE] * b0[0xE];
196
WRITE_SAMPLE(samples,sum,clip); samples += step;
198
WRITE_SAMPLE(samples,sum,clip); samples += step;
199
WRITE_SAMPLE(samples,sum,clip); samples += step;
200
WRITE_SAMPLE(samples,sum,clip); samples += step;
202
b0-=0x40,window-=0x80;
206
for (j=3;j;j--,b0-=0x50,window-=0x70)
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++;
218
sum -= *(--window) * *b0++;
219
sum -= *(--window) * *b0++;
220
sum -= *(--window) * *b0++;
221
sum -= *(--window) * *b0++;
222
sum -= *(--window) * *b0++;
223
sum -= *(--window) * *b0++;
224
sum -= *(--window) * *b0++;
226
WRITE_SAMPLE(samples,sum,clip); samples += step;
228
WRITE_SAMPLE(samples,sum,clip); samples += step;
229
WRITE_SAMPLE(samples,sum,clip); samples += step;
230
WRITE_SAMPLE(samples,sum,clip); samples += step;