From 51a880208a3a21cb6cb12a3385b260ad33c2b2b7 Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 20 Oct 2004 18:02:34 +0000 Subject: [PATCH] make filter size, int32/int16 and a few other things selectable at compiletime Originally committed as revision 3615 to svn://svn.ffmpeg.org/ffmpeg/trunk --- libavcodec/resample2.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/libavcodec/resample2.c b/libavcodec/resample2.c index 44761825cf..ad303a4498 100644 --- a/libavcodec/resample2.c +++ b/libavcodec/resample2.c @@ -31,10 +31,28 @@ #define PHASE_SHIFT 10 #define PHASE_COUNT (1<cubic, 1->blackman nuttall windowed sinc, 2->kaiser windowed sinc beta=16 */ -void av_build_filter(int16_t *filter, double factor, int tap_count, int phase_count, int scale, int type){ +void av_build_filter(FELEM *filter, double factor, int tap_count, int phase_count, int scale, int type){ int ph, i, v; double x, y, w, tab[tap_count]; const int center= (tap_count-1)/2; @@ -104,7 +122,7 @@ void av_build_filter(int16_t *filter, double factor, int tap_count, int phase_co /* normalize so that an uniform color remains the same */ for(i=0;ifilter_length= ceil(16.0/factor); - c->filter_bank= av_mallocz(c->filter_length*(PHASE_COUNT+1)*sizeof(short)); + 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(short)); + memcpy(&c->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; @@ -163,9 +181,9 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int int compensation_distance= c->compensation_distance; for(dst_index=0; dst_index < dst_size; dst_index++){ - short *filter= c->filter_bank + c->filter_length*(index & PHASE_MASK); + FELEM *filter= c->filter_bank + c->filter_length*(index & PHASE_MASK); int sample_index= index >> PHASE_SHIFT; - int val=0; + FELEM2 val=0; if(sample_index < 0){ for(i=0; ifilter_length; i++) @@ -173,17 +191,17 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int }else if(sample_index + c->filter_length > src_size){ break; }else{ -#if 0 +#ifdef LINEAR int64_t v=0; int sub_phase= (frac<<12) / c->src_incr; for(i=0; ifilter_length; i++){ - int64_t coeff= filter[i]*(4096 - sub_phase) + filter[i + c->filter_length]*sub_phase; + int64_t coeff= filter[i]*(FELEM2)(4096 - sub_phase) + filter[i + c->filter_length]*(FELEM2)sub_phase; v += src[sample_index + i] * coeff; } val= v>>12; #else for(i=0; ifilter_length; i++){ - val += src[sample_index + i] * filter[i]; + val += src[sample_index + i] * (FELEM2)filter[i]; } #endif }