diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h index e653d32161..3f91f5f162 100644 --- a/libavcodec/avcodec.h +++ b/libavcodec/avcodec.h @@ -17,7 +17,7 @@ extern "C" { #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 @@ ReSampleContext *audio_resample_init(int output_channels, int input_channels, 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 --git a/libavcodec/resample.c b/libavcodec/resample.c index 63371b0a1d..a5e1539993 100644 --- a/libavcodec/resample.c +++ b/libavcodec/resample.c @@ -160,7 +160,7 @@ ReSampleContext *audio_resample_init(int output_channels, int input_channels, 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 --git a/libavcodec/resample2.c b/libavcodec/resample2.c index 22f787dc16..05b12a0df1 100644 --- a/libavcodec/resample2.c +++ b/libavcodec/resample2.c @@ -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 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++){ - 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 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int 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 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int 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 @@ int av_resample(AVResampleContext *c, short *dst, short *src, int *consumed, int 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){