562
|
1 /*
|
|
2 decode_2to1.c: ...with 2to1 downsampling
|
|
3
|
|
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.org
|
|
6 initially written by Michael Hipp
|
|
7 */
|
|
8
|
|
9 #include "mpg123lib_intern.h"
|
|
10
|
|
11 int synth_2to1_8bit(real *bandPtr, int channel, mpg123_handle *fr, int final)
|
|
12 {
|
|
13 sample_t samples_tmp[32];
|
|
14 sample_t *tmp1 = samples_tmp + channel;
|
|
15 int i,ret;
|
|
16
|
|
17 unsigned char *samples = fr->buffer.data;
|
|
18 int pnt = fr->buffer.fill;
|
|
19 fr->buffer.data = (unsigned char*) samples_tmp;
|
|
20 fr->buffer.fill = 0;
|
|
21 ret = synth_2to1(bandPtr,channel, fr, 0);
|
|
22 fr->buffer.data = samples;
|
|
23
|
|
24 samples += channel + pnt;
|
|
25 for(i=0;i<16;i++) {
|
|
26 #ifdef FLOATOUT
|
|
27 *samples = 0;
|
|
28 #else
|
|
29 *samples = fr->conv16to8[*tmp1>>AUSHIFT];
|
|
30 #endif
|
|
31 samples += 2;
|
|
32 tmp1 += 2;
|
|
33 }
|
|
34 fr->buffer.fill = pnt + (final ? 32 : 0);
|
|
35
|
|
36 return ret;
|
|
37 }
|
|
38
|
|
39 int synth_2to1_8bit_mono(real *bandPtr, mpg123_handle *fr)
|
|
40 {
|
|
41 sample_t samples_tmp[32];
|
|
42 sample_t *tmp1 = samples_tmp;
|
|
43 int i,ret;
|
|
44
|
|
45 unsigned char *samples = fr->buffer.data;
|
|
46 int pnt = fr->buffer.fill;
|
|
47 fr->buffer.data = (unsigned char*) samples_tmp;
|
|
48 fr->buffer.fill = 0;
|
|
49 ret = synth_2to1(bandPtr, 0, fr, 0);
|
|
50 fr->buffer.data = samples;
|
|
51
|
|
52 samples += pnt;
|
|
53 for(i=0;i<16;i++) {
|
|
54 #ifdef FLOATOUT
|
|
55 *samples++ = 0;
|
|
56 #else
|
|
57 *samples++ = fr->conv16to8[*tmp1>>AUSHIFT];
|
|
58 #endif
|
|
59 tmp1 += 2;
|
|
60 }
|
|
61 fr->buffer.fill = pnt + 16;
|
|
62
|
|
63 return ret;
|
|
64 }
|
|
65
|
|
66
|
|
67 int synth_2to1_8bit_mono2stereo(real *bandPtr, mpg123_handle *fr)
|
|
68 {
|
|
69 sample_t samples_tmp[32];
|
|
70 sample_t *tmp1 = samples_tmp;
|
|
71 int i,ret;
|
|
72
|
|
73 unsigned char *samples = fr->buffer.data;
|
|
74 int pnt = fr->buffer.fill;
|
|
75 fr->buffer.data = (unsigned char*) samples_tmp;
|
|
76 fr->buffer.fill = 0;
|
|
77 ret = synth_2to1(bandPtr,0, fr, 0);
|
|
78 fr->buffer.data = samples;
|
|
79
|
|
80 samples += pnt;
|
|
81 for(i=0;i<16;i++) {
|
|
82 #ifdef FLOATOUT
|
|
83 *samples++ = 0;
|
|
84 *samples++ = 0;
|
|
85 #else
|
|
86 *samples++ = fr->conv16to8[*tmp1>>AUSHIFT];
|
|
87 *samples++ = fr->conv16to8[*tmp1>>AUSHIFT];
|
|
88 #endif
|
|
89 tmp1 += 2;
|
|
90 }
|
|
91 fr->buffer.fill = pnt + 32;
|
|
92
|
|
93 return ret;
|
|
94 }
|
|
95
|
|
96 int synth_2to1_mono(real *bandPtr, mpg123_handle *fr)
|
|
97 {
|
|
98 sample_t samples_tmp[32];
|
|
99 sample_t *tmp1 = samples_tmp;
|
|
100 int i,ret;
|
|
101
|
|
102 unsigned char *samples = fr->buffer.data;
|
|
103 int pnt = fr->buffer.fill;
|
|
104 fr->buffer.data = (unsigned char*) samples_tmp;
|
|
105 fr->buffer.fill = 0;
|
|
106 ret = synth_2to1(bandPtr, 0, fr, 0);
|
|
107 fr->buffer.data = samples;
|
|
108
|
|
109 samples += pnt;
|
|
110 for(i=0;i<16;i++) {
|
|
111 *( (sample_t *) samples) = *tmp1;
|
|
112 samples += sizeof(sample_t);
|
|
113 tmp1 += 2;
|
|
114 }
|
|
115 fr->buffer.fill = pnt + 16*sizeof(sample_t);
|
|
116
|
|
117 return ret;
|
|
118 }
|
|
119
|
|
120 int synth_2to1_mono2stereo(real *bandPtr, mpg123_handle *fr)
|
|
121 {
|
|
122 int i,ret;
|
|
123 unsigned char *samples = fr->buffer.data;
|
|
124
|
|
125 ret = synth_2to1(bandPtr,0, fr, 1);
|
|
126 samples += fr->buffer.fill - 32*sizeof(sample_t);
|
|
127
|
|
128 for(i=0;i<16;i++) {
|
|
129 ((sample_t *)samples)[1] = ((sample_t *)samples)[0];
|
|
130 samples+=2*sizeof(sample_t);
|
|
131 }
|
|
132
|
|
133 return ret;
|
|
134 }
|
|
135
|
|
136 int synth_2to1(real *bandPtr,int channel, mpg123_handle *fr, int final)
|
|
137 {
|
|
138 static const int step = 2;
|
|
139 sample_t *samples = (sample_t *) (fr->buffer.data + fr->buffer.fill);
|
|
140
|
|
141 real *b0, **buf; /* (*buf)[0x110]; */
|
|
142 int clip = 0;
|
|
143 int bo1;
|
|
144
|
|
145 if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
|
|
146
|
|
147 if(!channel) {
|
|
148 fr->bo[0]--;
|
|
149 fr->bo[0] &= 0xf;
|
|
150 buf = fr->real_buffs[0];
|
|
151 }
|
|
152 else {
|
|
153 samples++;
|
|
154 buf = fr->real_buffs[1];
|
|
155 }
|
|
156
|
|
157 if(fr->bo[0] & 0x1) {
|
|
158 b0 = buf[0];
|
|
159 bo1 = fr->bo[0];
|
|
160 opt_dct64(fr)(buf[1]+((fr->bo[0]+1)&0xf),buf[0]+fr->bo[0],bandPtr);
|
|
161 }
|
|
162 else {
|
|
163 b0 = buf[1];
|
|
164 bo1 = fr->bo[0]+1;
|
|
165 opt_dct64(fr)(buf[0]+fr->bo[0],buf[1]+fr->bo[0]+1,bandPtr);
|
|
166 }
|
|
167
|
|
168 {
|
|
169 register int j;
|
|
170 real *window = opt_decwin(fr) + 16 - bo1;
|
|
171
|
|
172 for (j=8;j;j--,b0+=0x10,window+=0x30)
|
|
173 {
|
|
174 real sum;
|
|
175 sum = REAL_MUL(*window++, *b0++);
|
|
176 sum -= REAL_MUL(*window++, *b0++);
|
|
177 sum += REAL_MUL(*window++, *b0++);
|
|
178 sum -= REAL_MUL(*window++, *b0++);
|
|
179 sum += REAL_MUL(*window++, *b0++);
|
|
180 sum -= REAL_MUL(*window++, *b0++);
|
|
181 sum += REAL_MUL(*window++, *b0++);
|
|
182 sum -= REAL_MUL(*window++, *b0++);
|
|
183 sum += REAL_MUL(*window++, *b0++);
|
|
184 sum -= REAL_MUL(*window++, *b0++);
|
|
185 sum += REAL_MUL(*window++, *b0++);
|
|
186 sum -= REAL_MUL(*window++, *b0++);
|
|
187 sum += REAL_MUL(*window++, *b0++);
|
|
188 sum -= REAL_MUL(*window++, *b0++);
|
|
189 sum += REAL_MUL(*window++, *b0++);
|
|
190 sum -= REAL_MUL(*window++, *b0++);
|
|
191
|
|
192 WRITE_SAMPLE(samples,sum,clip); samples += step;
|
|
193 #if 0
|
|
194 WRITE_SAMPLE(samples,sum,clip); samples += step;
|
|
195 #endif
|
|
196 }
|
|
197
|
|
198 {
|
|
199 real sum;
|
|
200 sum = REAL_MUL(window[0x0], b0[0x0]);
|
|
201 sum += REAL_MUL(window[0x2], b0[0x2]);
|
|
202 sum += REAL_MUL(window[0x4], b0[0x4]);
|
|
203 sum += REAL_MUL(window[0x6], b0[0x6]);
|
|
204 sum += REAL_MUL(window[0x8], b0[0x8]);
|
|
205 sum += REAL_MUL(window[0xA], b0[0xA]);
|
|
206 sum += REAL_MUL(window[0xC], b0[0xC]);
|
|
207 sum += REAL_MUL(window[0xE], b0[0xE]);
|
|
208 WRITE_SAMPLE(samples,sum,clip); samples += step;
|
|
209 #if 0
|
|
210 WRITE_SAMPLE(samples,sum,clip); samples += step;
|
|
211 #endif
|
|
212 b0-=0x20,window-=0x40;
|
|
213 }
|
|
214 window += bo1<<1;
|
|
215
|
|
216 for (j=7;j;j--,b0-=0x30,window-=0x30)
|
|
217 {
|
|
218 real sum;
|
|
219 sum = REAL_MUL(-*(--window), *b0++);
|
|
220 sum -= REAL_MUL(*(--window), *b0++);
|
|
221 sum -= REAL_MUL(*(--window), *b0++);
|
|
222 sum -= REAL_MUL(*(--window), *b0++);
|
|
223 sum -= REAL_MUL(*(--window), *b0++);
|
|
224 sum -= REAL_MUL(*(--window), *b0++);
|
|
225 sum -= REAL_MUL(*(--window), *b0++);
|
|
226 sum -= REAL_MUL(*(--window), *b0++);
|
|
227 sum -= REAL_MUL(*(--window), *b0++);
|
|
228 sum -= REAL_MUL(*(--window), *b0++);
|
|
229 sum -= REAL_MUL(*(--window), *b0++);
|
|
230 sum -= REAL_MUL(*(--window), *b0++);
|
|
231 sum -= REAL_MUL(*(--window), *b0++);
|
|
232 sum -= REAL_MUL(*(--window), *b0++);
|
|
233 sum -= REAL_MUL(*(--window), *b0++);
|
|
234 sum -= REAL_MUL(*(--window), *b0++);
|
|
235
|
|
236 WRITE_SAMPLE(samples,sum,clip); samples += step;
|
|
237 #if 0
|
|
238 WRITE_SAMPLE(samples,sum,clip); samples += step;
|
|
239 #endif
|
|
240 }
|
|
241 }
|
|
242
|
|
243 if(final) fr->buffer.fill += 32*sizeof(sample_t);
|
|
244
|
|
245 return clip;
|
|
246 }
|
|
247
|
|
248
|