Mercurial > libavcodec.hg
comparison resample.c @ 396:fce0a2520551 libavcodec
removed useless header includes - use av memory functions
author | glantau |
---|---|
date | Sat, 18 May 2002 23:03:29 +0000 |
parents | 3007abcbc510 |
children | 718a22dc121f |
comparison
equal
deleted
inserted
replaced
395:80518daaab05 | 396:fce0a2520551 |
---|---|
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 "avcodec.h" | 19 #include "avcodec.h" |
20 #include <math.h> | |
21 | 20 |
22 typedef struct { | 21 typedef struct { |
23 /* fractional resampling */ | 22 /* fractional resampling */ |
24 UINT32 incr; /* fractional increment */ | 23 UINT32 incr; /* fractional increment */ |
25 UINT32 frac; | 24 UINT32 frac; |
191 static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples) | 190 static int mono_resample(ReSampleChannelContext *s, short *output, short *input, int nb_samples) |
192 { | 191 { |
193 short *buf1; | 192 short *buf1; |
194 short *buftmp; | 193 short *buftmp; |
195 | 194 |
196 buf1= (short*) malloc( nb_samples * sizeof(short) ); | 195 buf1= (short*)av_malloc( nb_samples * sizeof(short) ); |
197 | 196 |
198 /* first downsample by an integer factor with averaging filter */ | 197 /* first downsample by an integer factor with averaging filter */ |
199 if (s->iratio > 1) { | 198 if (s->iratio > 1) { |
200 buftmp = buf1; | 199 buftmp = buf1; |
201 nb_samples = integer_downsample(s, buftmp, input, nb_samples); | 200 nb_samples = integer_downsample(s, buftmp, input, nb_samples); |
207 if (s->incr != FRAC) { | 206 if (s->incr != FRAC) { |
208 nb_samples = fractional_resample(s, output, buftmp, nb_samples); | 207 nb_samples = fractional_resample(s, output, buftmp, nb_samples); |
209 } else { | 208 } else { |
210 memcpy(output, buftmp, nb_samples * sizeof(short)); | 209 memcpy(output, buftmp, nb_samples * sizeof(short)); |
211 } | 210 } |
212 free(buf1); | 211 av_free(buf1); |
213 return nb_samples; | 212 return nb_samples; |
214 } | 213 } |
215 | 214 |
216 ReSampleContext *audio_resample_init(int output_channels, int input_channels, | 215 ReSampleContext *audio_resample_init(int output_channels, int input_channels, |
217 int output_rate, int input_rate) | 216 int output_rate, int input_rate) |
258 memcpy(output, input, nb_samples * s->input_channels * sizeof(short)); | 257 memcpy(output, input, nb_samples * s->input_channels * sizeof(short)); |
259 return nb_samples; | 258 return nb_samples; |
260 } | 259 } |
261 | 260 |
262 /* XXX: move those malloc to resample init code */ | 261 /* XXX: move those malloc to resample init code */ |
263 bufin[0]= (short*) malloc( nb_samples * sizeof(short) ); | 262 bufin[0]= (short*) av_malloc( nb_samples * sizeof(short) ); |
264 bufin[1]= (short*) malloc( nb_samples * sizeof(short) ); | 263 bufin[1]= (short*) av_malloc( nb_samples * sizeof(short) ); |
265 | 264 |
266 /* make some zoom to avoid round pb */ | 265 /* make some zoom to avoid round pb */ |
267 lenout= (int)(nb_samples * s->ratio) + 16; | 266 lenout= (int)(nb_samples * s->ratio) + 16; |
268 bufout[0]= (short*) malloc( lenout * sizeof(short) ); | 267 bufout[0]= (short*) av_malloc( lenout * sizeof(short) ); |
269 bufout[1]= (short*) malloc( lenout * sizeof(short) ); | 268 bufout[1]= (short*) av_malloc( lenout * sizeof(short) ); |
270 | 269 |
271 if (s->input_channels == 2 && | 270 if (s->input_channels == 2 && |
272 s->output_channels == 1) { | 271 s->output_channels == 1) { |
273 buftmp2[0] = bufin[0]; | 272 buftmp2[0] = bufin[0]; |
274 buftmp3[0] = output; | 273 buftmp3[0] = output; |
297 mono_to_stereo(output, buftmp3[0], nb_samples1); | 296 mono_to_stereo(output, buftmp3[0], nb_samples1); |
298 } else if (s->output_channels == 2) { | 297 } else if (s->output_channels == 2) { |
299 stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1); | 298 stereo_mux(output, buftmp3[0], buftmp3[1], nb_samples1); |
300 } | 299 } |
301 | 300 |
302 free(bufin[0]); | 301 av_free(bufin[0]); |
303 free(bufin[1]); | 302 av_free(bufin[1]); |
304 | 303 |
305 free(bufout[0]); | 304 av_free(bufout[0]); |
306 free(bufout[1]); | 305 av_free(bufout[1]); |
307 return nb_samples1; | 306 return nb_samples1; |
308 } | 307 } |
309 | 308 |
310 void audio_resample_close(ReSampleContext *s) | 309 void audio_resample_close(ReSampleContext *s) |
311 { | 310 { |
312 free(s); | 311 av_free(s); |
313 } | 312 } |