# HG changeset patch # User michael # Date 1098328294 0 # Node ID 072fc321fbe697d0b1f9e9be1d48e59607ad8926 # Parent 9568c8880d964d618583409a717d8223120610e9 make most resample filter parameters selectable at runtime diff -r 9568c8880d96 -r 072fc321fbe6 avcodec.h --- a/avcodec.h Wed Oct 20 19:06:29 2004 +0000 +++ b/avcodec.h Thu Oct 21 03:11:34 2004 +0000 @@ -17,7 +17,7 @@ #define FFMPEG_VERSION_INT 0x000409 #define FFMPEG_VERSION "0.4.9-pre1" -#define LIBAVCODEC_BUILD 4725 +#define LIBAVCODEC_BUILD 4726 #define LIBAVCODEC_VERSION_INT FFMPEG_VERSION_INT #define LIBAVCODEC_VERSION FFMPEG_VERSION @@ -1942,7 +1942,7 @@ int audio_resample(ReSampleContext *s, short *output, short *input, int nb_samples); void audio_resample_close(ReSampleContext *s); -struct AVResampleContext *av_resample_init(int out_rate, int in_rate); +struct AVResampleContext *av_resample_init(int out_rate, int in_rate, int filter_length, int log2_phase_count, int linear); int av_resample(struct AVResampleContext *c, short *dst, short *src, int *consumed, int src_size, int dst_size, int update_ctx); void av_resample_compensate(struct AVResampleContext *c, int sample_delta, int compensation_distance); void av_resample_close(struct AVResampleContext *c); diff -r 9568c8880d96 -r 072fc321fbe6 resample.c --- a/resample.c Wed Oct 20 19:06:29 2004 +0000 +++ b/resample.c Thu Oct 21 03:11:34 2004 +0000 @@ -160,7 +160,7 @@ if(s->filter_channels>2) s->filter_channels = 2; - s->resample_context= av_resample_init(output_rate, input_rate); + s->resample_context= av_resample_init(output_rate, input_rate, 16, 10, 0); return s; } diff -r 9568c8880d96 -r 072fc321fbe6 resample2.c --- a/resample2.c Wed Oct 20 19:06:29 2004 +0000 +++ b/resample2.c Thu Oct 21 03:11:34 2004 +0000 @@ -28,12 +28,6 @@ #include "common.h" #include "dsputil.h" -#define PHASE_SHIFT 10 -#define PHASE_COUNT (1<phase_shift= phase_shift; + c->phase_mask= phase_count-1; + c->linear= linear; - c->filter_length= ceil(FILTER_SIZE/factor); - c->filter_bank= av_mallocz(c->filter_length*(PHASE_COUNT+1)*sizeof(FELEM)); - av_build_filter(c->filter_bank, factor, c->filter_length, PHASE_COUNT, 1<filter_bank[c->filter_length*PHASE_COUNT+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM)); - c->filter_bank[c->filter_length*PHASE_COUNT]= c->filter_bank[c->filter_length - 1]; + c->filter_length= ceil(filter_size/factor); + c->filter_bank= av_mallocz(c->filter_length*(phase_count+1)*sizeof(FELEM)); + av_build_filter(c->filter_bank, factor, c->filter_length, phase_count, 1<filter_bank[c->filter_length*phase_count+1], c->filter_bank, (c->filter_length-1)*sizeof(FELEM)); + c->filter_bank[c->filter_length*phase_count]= c->filter_bank[c->filter_length - 1]; c->src_incr= out_rate; - c->ideal_dst_incr= c->dst_incr= in_rate * PHASE_COUNT; - c->index= -PHASE_COUNT*((c->filter_length-1)/2); + c->ideal_dst_incr= c->dst_incr= in_rate * phase_count; + c->index= -phase_count*((c->filter_length-1)/2); return c; } @@ -181,8 +183,8 @@ int compensation_distance= c->compensation_distance; for(dst_index=0; dst_index < dst_size; dst_index++){ - FELEM *filter= c->filter_bank + c->filter_length*(index & PHASE_MASK); - int sample_index= index >> PHASE_SHIFT; + FELEM *filter= c->filter_bank + c->filter_length*(index & c->phase_mask); + int sample_index= index >> c->phase_shift; FELEM2 val=0; if(sample_index < 0){ @@ -190,8 +192,7 @@ val += src[ABS(sample_index + i) % src_size] * filter[i]; }else if(sample_index + c->filter_length > src_size){ break; - }else{ -#ifdef LINEAR + }else if(c->linear){ int64_t v=0; int sub_phase= (frac<<8) / c->src_incr; for(i=0; ifilter_length; i++){ @@ -199,11 +200,10 @@ v += src[sample_index + i] * coeff; } val= v>>8; -#else + }else{ for(i=0; ifilter_length; i++){ val += src[sample_index + i] * (FELEM2)filter[i]; } -#endif } val = (val + (1<<(FILTER_SHIFT-1)))>>FILTER_SHIFT; @@ -222,7 +222,7 @@ dst_incr= c->ideal_dst_incr / c->src_incr; } } - *consumed= FFMAX(index, 0) >> PHASE_SHIFT; + *consumed= FFMAX(index, 0) >> c->phase_shift; index= FFMIN(index, 0); if(compensation_distance){