/*
* 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
*/
+
+/**
+ * @file resample.c
+ * Sample rate convertion for both audio and video.
+ */
+
#include "avcodec.h"
-#include <math.h>
+#include "os_support.h"
typedef struct {
/* fractional resampling */
- UINT32 incr; /* fractional increment */
- UINT32 frac;
+ uint32_t incr; /* fractional increment */
+ uint32_t frac;
int last_sample;
/* integer down sample */
int iratio; /* integer divison ratio */
static void init_mono_resample(ReSampleChannelContext *s, float ratio)
{
ratio = 1.0 / ratio;
- s->iratio = (int)floor(ratio);
+ s->iratio = (int)floorf(ratio);
if (s->iratio == 0)
s->iratio = 1;
s->incr = (int)((ratio / s->iratio) * FRAC);
*q++ = (l0 * (FRAC - frac) + l1 * frac) >> FRAC_BITS;
frac = frac + s->incr;
while (frac >= FRAC) {
+ frac -= FRAC;
if (p >= pend)
goto the_end;
- frac -= FRAC;
l0 = l1;
l1 = *p++;
}
short *buf1;
short *buftmp;
- buf1= (short*) malloc( nb_samples * sizeof(short) );
+ buf1= (short*)av_malloc( nb_samples * sizeof(short) );
/* first downsample by an integer factor with averaging filter */
if (s->iratio > 1) {
} else {
memcpy(output, buftmp, nb_samples * sizeof(short));
}
- free(buf1);
+ av_free(buf1);
return nb_samples;
}
}
/* XXX: move those malloc to resample init code */
- bufin[0]= (short*) malloc( nb_samples * sizeof(short) );
- bufin[1]= (short*) malloc( nb_samples * sizeof(short) );
+ 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*) malloc( lenout * sizeof(short) );
- bufout[1]= (short*) malloc( lenout * sizeof(short) );
+ 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) {
stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1);
}
- free(bufin[0]);
- free(bufin[1]);
+ av_free(bufin[0]);
+ av_free(bufin[1]);
- free(bufout[0]);
- free(bufout[1]);
+ av_free(bufout[0]);
+ av_free(bufout[1]);
return nb_samples1;
}
void audio_resample_close(ReSampleContext *s)
{
- free(s);
+ av_free(s);
}