Mercurial > SDL_sound_CoreAudio
comparison decoders/libmpg123/decode_4to1.c @ 562:7e08477b0fc1
MP3 decoder upgrade work.
Ripped out SMPEG and mpglib support, replaced it with "mpg123.c" and libmpg123.
libmpg123 is a much better version of mpglib, so it should solve all the
problems about MP3's not seeking, or most modern MP3's not playing at all,
etc. Since you no longer have to make a tradeoff with SMPEG for features, and
SMPEG is basically rotting, I removed it from the project.
There is still work to be done with libmpg123...there are MMX, 3DNow, SSE,
Altivec, etc decoders which we don't have enabled at the moment, and the
build system could use some work to make this compile more cleanly, etc.
Still: huge win.
author | Ryan C. Gordon <icculus@icculus.org> |
---|---|
date | Fri, 30 Jan 2009 02:44:47 -0500 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
561:f2985e08589c | 562:7e08477b0fc1 |
---|---|
1 /* | |
2 decode_4to1.c: ...with 4to1 downsampling / decoding of every 4th sample | |
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 dunno why it sounds THIS annoying (maybe we should adapt the window?) | |
9 absolutely not optimized for this operation | |
10 */ | |
11 | |
12 #include "mpg123lib_intern.h" | |
13 | |
14 int synth_4to1_8bit(real *bandPtr, int channel, mpg123_handle *fr, int final) | |
15 { | |
16 sample_t samples_tmp[16]; | |
17 sample_t *tmp1 = samples_tmp + channel; | |
18 int i,ret; | |
19 | |
20 unsigned char *samples = fr->buffer.data; | |
21 int pnt = fr->buffer.fill; | |
22 fr->buffer.data = (unsigned char*) samples_tmp; | |
23 fr->buffer.fill = 0; | |
24 ret = synth_4to1(bandPtr,channel, fr, 0); | |
25 fr->buffer.data = samples; | |
26 | |
27 samples += channel + pnt; | |
28 for(i=0;i<8;i++) { | |
29 #ifdef FLOATOUT | |
30 *samples = 0; | |
31 #else | |
32 *samples = fr->conv16to8[*tmp1>>AUSHIFT]; | |
33 #endif | |
34 samples += 2; | |
35 tmp1 += 2; | |
36 } | |
37 fr->buffer.fill = pnt + (final ? 16 : 0); | |
38 | |
39 return ret; | |
40 } | |
41 | |
42 int synth_4to1_8bit_mono(real *bandPtr, mpg123_handle *fr) | |
43 { | |
44 sample_t samples_tmp[16]; | |
45 sample_t *tmp1 = samples_tmp; | |
46 int i,ret; | |
47 | |
48 unsigned char *samples = fr->buffer.data; | |
49 int pnt = fr->buffer.fill; | |
50 fr->buffer.data = (unsigned char*) samples_tmp; | |
51 fr->buffer.fill = 0; | |
52 ret = synth_4to1(bandPtr, 0, fr, 0); | |
53 fr->buffer.data = samples; | |
54 | |
55 samples += pnt; | |
56 for(i=0;i<8;i++) { | |
57 #ifdef FLOATOUT | |
58 *samples++ = 0; | |
59 #else | |
60 *samples++ = fr->conv16to8[*tmp1>>AUSHIFT]; | |
61 #endif | |
62 tmp1 += 2; | |
63 } | |
64 fr->buffer.fill = pnt + 8; | |
65 | |
66 return ret; | |
67 } | |
68 | |
69 | |
70 int synth_4to1_8bit_mono2stereo(real *bandPtr, mpg123_handle *fr) | |
71 { | |
72 sample_t samples_tmp[16]; | |
73 sample_t *tmp1 = samples_tmp; | |
74 int i,ret; | |
75 | |
76 unsigned char *samples = fr->buffer.data; | |
77 int pnt = fr->buffer.fill; | |
78 fr->buffer.data = (unsigned char*) samples_tmp; | |
79 fr->buffer.fill = 0; | |
80 ret = synth_4to1(bandPtr, 0, fr, 0); | |
81 fr->buffer.data = samples; | |
82 | |
83 samples += pnt; | |
84 for(i=0;i<8;i++) { | |
85 #ifdef FLOATOUT | |
86 *samples++ = 0; | |
87 *samples++ = 0; | |
88 #else | |
89 *samples++ = fr->conv16to8[*tmp1>>AUSHIFT]; | |
90 *samples++ = fr->conv16to8[*tmp1>>AUSHIFT]; | |
91 #endif | |
92 tmp1 += 2; | |
93 } | |
94 fr->buffer.fill = pnt + 16; | |
95 | |
96 return ret; | |
97 } | |
98 | |
99 int synth_4to1_mono(real *bandPtr, mpg123_handle *fr) | |
100 { | |
101 sample_t samples_tmp[16]; | |
102 sample_t *tmp1 = samples_tmp; | |
103 int i,ret; | |
104 | |
105 unsigned char *samples = fr->buffer.data; | |
106 int pnt = fr->buffer.fill; | |
107 fr->buffer.data = (unsigned char*) samples_tmp; | |
108 fr->buffer.fill = 0; | |
109 ret = synth_4to1(bandPtr, 0, fr, 0); | |
110 fr->buffer.data = samples; | |
111 | |
112 samples += pnt; | |
113 for(i=0;i<8;i++) { | |
114 *( (sample_t *)samples) = *tmp1; | |
115 samples += sizeof(sample_t); | |
116 tmp1 += 2; | |
117 } | |
118 fr->buffer.fill = pnt + 8*sizeof(sample_t); | |
119 | |
120 return ret; | |
121 } | |
122 | |
123 int synth_4to1_mono2stereo(real *bandPtr, mpg123_handle *fr) | |
124 { | |
125 int i,ret; | |
126 unsigned char *samples = fr->buffer.data; | |
127 | |
128 ret = synth_4to1(bandPtr, 0, fr, 1); | |
129 samples += fr->buffer.fill - 16*sizeof(sample_t); | |
130 | |
131 for(i=0;i<8;i++) { | |
132 ((sample_t *)samples)[1] = ((sample_t *)samples)[0]; | |
133 samples+=2*sizeof(sample_t); | |
134 } | |
135 | |
136 return ret; | |
137 } | |
138 | |
139 int synth_4to1(real *bandPtr,int channel, mpg123_handle *fr, int final) | |
140 { | |
141 static const int step = 2; | |
142 sample_t *samples = (sample_t *) (fr->buffer.data + fr->buffer.fill); | |
143 | |
144 real *b0, **buf; /* (*buf)[0x110]; */ | |
145 int clip = 0; | |
146 int bo1; | |
147 | |
148 if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer); | |
149 | |
150 if(!channel) { | |
151 fr->bo[0]--; | |
152 fr->bo[0] &= 0xf; | |
153 buf = fr->real_buffs[0]; | |
154 } | |
155 else { | |
156 samples++; | |
157 buf = fr->real_buffs[1]; | |
158 } | |
159 | |
160 if(fr->bo[0] & 0x1) { | |
161 b0 = buf[0]; | |
162 bo1 = fr->bo[0]; | |
163 opt_dct64(fr)(buf[1]+((fr->bo[0]+1)&0xf),buf[0]+fr->bo[0],bandPtr); | |
164 } | |
165 else { | |
166 b0 = buf[1]; | |
167 bo1 = fr->bo[0]+1; | |
168 opt_dct64(fr)(buf[0]+fr->bo[0],buf[1]+fr->bo[0]+1,bandPtr); | |
169 } | |
170 | |
171 { | |
172 register int j; | |
173 real *window = opt_decwin(fr) + 16 - bo1; | |
174 | |
175 for (j=4;j;j--,b0+=0x30,window+=0x70) | |
176 { | |
177 real sum; | |
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 sum -= REAL_MUL(*window++, *b0++); | |
192 sum += REAL_MUL(*window++, *b0++); | |
193 sum -= REAL_MUL(*window++, *b0++); | |
194 | |
195 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
196 #if 0 | |
197 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
198 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
199 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
200 #endif | |
201 } | |
202 | |
203 { | |
204 real sum; | |
205 sum = REAL_MUL(window[0x0], b0[0x0]); | |
206 sum += REAL_MUL(window[0x2], b0[0x2]); | |
207 sum += REAL_MUL(window[0x4], b0[0x4]); | |
208 sum += REAL_MUL(window[0x6], b0[0x6]); | |
209 sum += REAL_MUL(window[0x8], b0[0x8]); | |
210 sum += REAL_MUL(window[0xA], b0[0xA]); | |
211 sum += REAL_MUL(window[0xC], b0[0xC]); | |
212 sum += REAL_MUL(window[0xE], b0[0xE]); | |
213 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
214 #if 0 | |
215 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
216 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
217 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
218 #endif | |
219 b0-=0x40,window-=0x80; | |
220 } | |
221 window += bo1<<1; | |
222 | |
223 for (j=3;j;j--,b0-=0x50,window-=0x70) | |
224 { | |
225 real sum; | |
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 sum -= REAL_MUL(*(--window), *b0++); | |
236 sum -= REAL_MUL(*(--window), *b0++); | |
237 sum -= REAL_MUL(*(--window), *b0++); | |
238 sum -= REAL_MUL(*(--window), *b0++); | |
239 sum -= REAL_MUL(*(--window), *b0++); | |
240 sum -= REAL_MUL(*(--window), *b0++); | |
241 sum -= REAL_MUL(*(--window), *b0++); | |
242 | |
243 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
244 #if 0 | |
245 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
246 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
247 WRITE_SAMPLE(samples,sum,clip); samples += step; | |
248 #endif | |
249 } | |
250 } | |
251 | |
252 if(final) fr->buffer.fill += 16*sizeof(sample_t); | |
253 | |
254 return clip; | |
255 } | |
256 | |
257 |