/*
* Sample rate convertion for both audio and video
- * Copyright (c) 2000 Gerard Lantau.
+ * Copyright (c) 2000 Fabrice Bellard.
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
*
- * This program is distributed in the hope that it will be useful,
+ * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <math.h>
#include "avcodec.h"
-#define NDEBUG
-#include <assert.h>
-
typedef struct {
/* fractional resampling */
UINT32 incr; /* fractional increment */
if (s->iratio == 0)
s->iratio = 1;
s->incr = (int)((ratio / s->iratio) * FRAC);
- s->frac = 0;
+ s->frac = FRAC;
s->last_sample = 0;
s->icount = s->iratio;
s->isum = 0;
static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples)
{
- short buf1[nb_samples];
+ short *buf1;
short *buftmp;
+ buf1= (short*)av_malloc( nb_samples * sizeof(short) );
+
/* first downsample by an integer factor with averaging filter */
if (s->iratio > 1) {
buftmp = buf1;
} else {
memcpy(output, buftmp, nb_samples * sizeof(short));
}
+ av_free(buf1);
return nb_samples;
}
int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples)
{
int i, nb_samples1;
- short bufin[2][nb_samples];
- short bufout[2][(int)(nb_samples * s->ratio) + 16]; /* make some zoom to avoid round pb */
+ short *bufin[2];
+ short *bufout[2];
short *buftmp2[2], *buftmp3[2];
+ int lenout;
if (s->input_channels == s->output_channels && s->ratio == 1.0) {
/* nothing to do */
return nb_samples;
}
+ /* XXX: move those malloc to resample init code */
+ bufin[0]= (short*) av_malloc( nb_samples * sizeof(short) );
+ bufin[1]= (short*) av_malloc( nb_samples * sizeof(short) );
+
+ /* make some zoom to avoid round pb */
+ lenout= (int)(nb_samples * s->ratio) + 16;
+ bufout[0]= (short*) av_malloc( lenout * sizeof(short) );
+ bufout[1]= (short*) av_malloc( lenout * sizeof(short) );
+
if (s->input_channels == 2 &&
s->output_channels == 1) {
buftmp2[0] = bufin[0];
stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
}
+ av_free(bufin[0]);
+ av_free(bufin[1]);
+
+ av_free(bufout[0]);
+ av_free(bufout[1]);
return nb_samples1;
}
void audio_resample_close(ReSampleContext *s)
{
- free(s);
+ av_free(s);
}