comparison resample.c @ 64:5aa6292a1660 libavcodec

win32 fixes
author glantau
date Mon, 13 Aug 2001 21:48:05 +0000
parents 986e461dc072
children 3007abcbc510
comparison
equal deleted inserted replaced
63:8e2d8dbf89a5 64:5aa6292a1660
14 * 14 *
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software 16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */ 18 */
19 #include <stdlib.h> 19 #include "avcodec.h"
20 #include <stdio.h>
21 #include <string.h>
22 #include <math.h> 20 #include <math.h>
23 #include "avcodec.h"
24
25 #define NDEBUG
26 #include <assert.h>
27 21
28 typedef struct { 22 typedef struct {
29 /* fractional resampling */ 23 /* fractional resampling */
30 UINT32 incr; /* fractional increment */ 24 UINT32 incr; /* fractional increment */
31 UINT32 frac; 25 UINT32 frac;
194 } 188 }
195 } 189 }
196 190
197 static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples) 191 static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples)
198 { 192 {
199 short buf1[nb_samples]; 193 short *buf1;
200 short *buftmp; 194 short *buftmp;
195
196 buf1= (short*) malloc( nb_samples * sizeof(short) );
201 197
202 /* first downsample by an integer factor with averaging filter */ 198 /* first downsample by an integer factor with averaging filter */
203 if (s->iratio > 1) { 199 if (s->iratio > 1) {
204 buftmp = buf1; 200 buftmp = buf1;
205 nb_samples = integer_downsample(s, buftmp, input, nb_samples); 201 nb_samples = integer_downsample(s, buftmp, input, nb_samples);
211 if (s->incr != FRAC) { 207 if (s->incr != FRAC) {
212 nb_samples = fractional_resample(s, output, buftmp, nb_samples); 208 nb_samples = fractional_resample(s, output, buftmp, nb_samples);
213 } else { 209 } else {
214 memcpy(output, buftmp, nb_samples * sizeof(short)); 210 memcpy(output, buftmp, nb_samples * sizeof(short));
215 } 211 }
212 free(buf1);
216 return nb_samples; 213 return nb_samples;
217 } 214 }
218 215
219 ReSampleContext *audio_resample_init(int output_channels, int input_channels, 216 ReSampleContext *audio_resample_init(int output_channels, int input_channels,
220 int output_rate, int input_rate) 217 int output_rate, int input_rate)
249 /* XXX: do it with polyphase filters, since the quality here is 246 /* XXX: do it with polyphase filters, since the quality here is
250 HORRIBLE. Return the number of samples available in output */ 247 HORRIBLE. Return the number of samples available in output */
251 int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples) 248 int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
252 { 249 {
253 int i, nb_samples1; 250 int i, nb_samples1;
254 short bufin[2][nb_samples]; 251 short *bufin[2];
255 short bufout[2][(int)(nb_samples * s->ratio) + 16]; /* make some zoom to avoid round pb */ 252 short *bufout[2];
256 short *buftmp2[2], *buftmp3[2]; 253 short *buftmp2[2], *buftmp3[2];
254 int lenout;
257 255
258 if (s->input_channels == s->output_channels && s->ratio == 1.0) { 256 if (s->input_channels == s->output_channels && s->ratio == 1.0) {
259 /* nothing to do */ 257 /* nothing to do */
260 memcpy(output, input, nb_samples * s->input_channels * sizeof(short)); 258 memcpy(output, input, nb_samples * s->input_channels * sizeof(short));
261 return nb_samples; 259 return nb_samples;
262 } 260 }
261
262 /* XXX: move those malloc to resample init code */
263 bufin[0]= (short*) malloc( nb_samples * sizeof(short) );
264 bufin[1]= (short*) malloc( nb_samples * sizeof(short) );
265
266 /* make some zoom to avoid round pb */
267 lenout= (int)(nb_samples * s->ratio) + 16;
268 bufout[0]= (short*) malloc( lenout * sizeof(short) );
269 bufout[1]= (short*) malloc( lenout * sizeof(short) );
263 270
264 if (s->input_channels == 2 && 271 if (s->input_channels == 2 &&
265 s->output_channels == 1) { 272 s->output_channels == 1) {
266 buftmp2[0] = bufin[0]; 273 buftmp2[0] = bufin[0];
267 buftmp3[0] = output; 274 buftmp3[0] = output;
290 mono_to_stereo(output, buftmp3[0], nb_samples1); 297 mono_to_stereo(output, buftmp3[0], nb_samples1);
291 } else if (s->output_channels == 2) { 298 } else if (s->output_channels == 2) {
292 stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1); 299 stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
293 } 300 }
294 301
302 free(bufin[0]);
303 free(bufin[1]);
304
305 free(bufout[0]);
306 free(bufout[1]);
295 return nb_samples1; 307 return nb_samples1;
296 } 308 }
297 309
298 void audio_resample_close(ReSampleContext *s) 310 void audio_resample_close(ReSampleContext *s)
299 { 311 {