comparison decoders/libmpg123/decode.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.c: decoding samples...
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 /* 8bit functions silenced for FLOATOUT */
12
13 int synth_1to1_8bit(real *bandPtr,int channel, mpg123_handle *fr, int final)
14 {
15 sample_t samples_tmp[64];
16 sample_t *tmp1 = samples_tmp + channel;
17 int i,ret;
18
19 /* save buffer stuff, trick samples_tmp into there, decode, restore */
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_1to1(bandPtr, channel, fr, 0);
25 fr->buffer.data = samples; /* restore original value */
26
27 samples += channel + pnt;
28 for(i=0;i<32;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 ? 64 : 0 );
38
39 return ret;
40 }
41
42 int synth_1to1_8bit_mono(real *bandPtr, mpg123_handle *fr)
43 {
44 sample_t samples_tmp[64];
45 sample_t *tmp1 = samples_tmp;
46 int i,ret;
47
48 /* save buffer stuff, trick samples_tmp into there, decode, restore */
49 unsigned char *samples = fr->buffer.data;
50 int pnt = fr->buffer.fill;
51 fr->buffer.data = (unsigned char*) samples_tmp;
52 fr->buffer.fill = 0;
53 ret = synth_1to1(bandPtr,0, fr, 0);
54 fr->buffer.data = samples; /* restore original value */
55
56 samples += pnt;
57 for(i=0;i<32;i++) {
58 #ifdef FLOATOUT
59 *samples++ = 0;
60 #else
61 *samples++ = fr->conv16to8[*tmp1>>AUSHIFT];
62 #endif
63 tmp1 += 2;
64 }
65 fr->buffer.fill = pnt + 32;
66
67 return ret;
68 }
69
70 int synth_1to1_8bit_mono2stereo(real *bandPtr, mpg123_handle *fr)
71 {
72 sample_t samples_tmp[64];
73 sample_t *tmp1 = samples_tmp;
74 int i,ret;
75
76 /* save buffer stuff, trick samples_tmp into there, decode, restore */
77 unsigned char *samples = fr->buffer.data;
78 int pnt = fr->buffer.fill;
79 fr->buffer.data = (unsigned char*) samples_tmp;
80 fr->buffer.fill = 0;
81 ret = synth_1to1(bandPtr, 0, fr, 0);
82 fr->buffer.data = samples; /* restore original value */
83
84 samples += pnt;
85 for(i=0;i<32;i++) {
86 #ifdef FLOATOUT
87 *samples++ = 0;
88 *samples++ = 0;
89 #else
90 *samples++ = fr->conv16to8[*tmp1>>AUSHIFT];
91 *samples++ = fr->conv16to8[*tmp1>>AUSHIFT];
92 #endif
93 tmp1 += 2;
94 }
95 fr->buffer.fill = pnt + 64;
96
97 return ret;
98 }
99
100 int synth_1to1_mono(real *bandPtr, mpg123_handle *fr)
101 {
102 sample_t samples_tmp[64];
103 sample_t *tmp1 = samples_tmp;
104 int i,ret;
105
106 /* save buffer stuff, trick samples_tmp into there, decode, restore */
107 unsigned char *samples = fr->buffer.data;
108 int pnt = fr->buffer.fill;
109 fr->buffer.data = (unsigned char*) samples_tmp;
110 fr->buffer.fill = 0;
111 ret = synth_1to1(bandPtr, 0, fr, 0); /* decode into samples_tmp */
112 fr->buffer.data = samples; /* restore original value */
113
114 /* now append samples from samples_tmp */
115 samples += pnt; /* just the next mem in frame buffer */
116 for(i=0;i<32;i++){
117 *( (sample_t *)samples) = *tmp1;
118 samples += sizeof(sample_t);
119 tmp1 += 2;
120 }
121 fr->buffer.fill = pnt + 32*sizeof(sample_t);
122
123 return ret;
124 }
125
126
127 int synth_1to1_mono2stereo(real *bandPtr, mpg123_handle *fr)
128 {
129 int i,ret;
130 unsigned char *samples = fr->buffer.data;
131
132 ret = synth_1to1(bandPtr,0,fr,1);
133 samples += fr->buffer.fill - 64*sizeof(sample_t);
134
135 for(i=0;i<32;i++) {
136 ((sample_t *)samples)[1] = ((sample_t *)samples)[0];
137 samples+=2*sizeof(sample_t);
138 }
139
140 return ret;
141 }
142
143
144 int synth_1to1(real *bandPtr,int channel,mpg123_handle *fr, int final)
145 {
146 static const int step = 2;
147 sample_t *samples = (sample_t *) (fr->buffer.data+fr->buffer.fill);
148
149 real *b0, **buf; /* (*buf)[0x110]; */
150 int clip = 0;
151 int bo1;
152
153 if(fr->have_eq_settings) do_equalizer(bandPtr,channel,fr->equalizer);
154
155 if(!channel) {
156 fr->bo[0]--;
157 fr->bo[0] &= 0xf;
158 buf = fr->real_buffs[0];
159 }
160 else {
161 samples++;
162 buf = fr->real_buffs[1];
163 }
164
165 if(fr->bo[0] & 0x1) {
166 b0 = buf[0];
167 bo1 = fr->bo[0];
168 dct64(buf[1]+((fr->bo[0]+1)&0xf),buf[0]+fr->bo[0],bandPtr);
169 }
170 else {
171 b0 = buf[1];
172 bo1 = fr->bo[0]+1;
173 dct64(buf[0]+fr->bo[0],buf[1]+fr->bo[0]+1,bandPtr);
174 }
175
176
177 {
178 register int j;
179 real *window = opt_decwin(fr) + 16 - bo1;
180
181 for (j=16;j;j--,window+=0x10,samples+=step)
182 {
183 real sum;
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 sum += REAL_MUL(*window++, *b0++);
195 sum -= REAL_MUL(*window++, *b0++);
196 sum += REAL_MUL(*window++, *b0++);
197 sum -= REAL_MUL(*window++, *b0++);
198 sum += REAL_MUL(*window++, *b0++);
199 sum -= REAL_MUL(*window++, *b0++);
200
201 WRITE_SAMPLE(samples,sum,clip);
202 }
203
204 {
205 real sum;
206 sum = REAL_MUL(window[0x0], b0[0x0]);
207 sum += REAL_MUL(window[0x2], b0[0x2]);
208 sum += REAL_MUL(window[0x4], b0[0x4]);
209 sum += REAL_MUL(window[0x6], b0[0x6]);
210 sum += REAL_MUL(window[0x8], b0[0x8]);
211 sum += REAL_MUL(window[0xA], b0[0xA]);
212 sum += REAL_MUL(window[0xC], b0[0xC]);
213 sum += REAL_MUL(window[0xE], b0[0xE]);
214 WRITE_SAMPLE(samples,sum,clip);
215 b0-=0x10,window-=0x20,samples+=step;
216 }
217 window += bo1<<1;
218
219 for (j=15;j;j--,b0-=0x20,window-=0x10,samples+=step)
220 {
221 real sum;
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 sum -= REAL_MUL(*(--window), *b0++);
236 sum -= REAL_MUL(*(--window), *b0++);
237 sum -= REAL_MUL(*(--window), *b0++);
238
239 WRITE_SAMPLE(samples,sum,clip);
240 }
241 }
242
243 if(final) fr->buffer.fill += 64*sizeof(sample_t);
244
245 return clip;
246 }