From ee575acb8c8ca7a688dc22c54ed667201869f909 Mon Sep 17 00:00:00 2001 From: Muhammad Faiz Date: Fri, 17 Jun 2016 05:30:37 +0700 Subject: swresample/resample: add support for odd phase_count because exact_rational does not guarantee that phase_count is even Reviewed-by: Michael Niedermayer Signed-off-by: Muhammad Faiz --- libswresample/resample.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'libswresample') diff --git a/libswresample/resample.c b/libswresample/resample.c index 1b1d83e596..16c2a397bf 100644 --- a/libswresample/resample.c +++ b/libswresample/resample.c @@ -144,9 +144,10 @@ static double bessel(double x) { static int build_filter(ResampleContext *c, void *filter, double factor, int tap_count, int alloc, int phase_count, int scale, int filter_type, double kaiser_beta){ int ph, i; + int ph_nb = phase_count % 2 ? phase_count : phase_count / 2 + 1; double x, y, w, t, s; double *tab = av_malloc_array(tap_count+1, sizeof(*tab)); - double *sin_lut = av_malloc_array(phase_count / 2 + 1, sizeof(*sin_lut)); + double *sin_lut = av_malloc_array(ph_nb, sizeof(*sin_lut)); const int center= (tap_count-1)/2; if (!tab || !sin_lut) @@ -156,13 +157,11 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap if (factor > 1.0) factor = 1.0; - av_assert0(phase_count == 1 || phase_count % 2 == 0); - if (factor == 1.0) { - for (ph = 0; ph <= phase_count / 2; ph++) + for (ph = 0; ph < ph_nb; ph++) sin_lut[ph] = sin(M_PI * ph / phase_count); } - for(ph = 0; ph <= phase_count / 2; ph++) { + for(ph = 0; ph < ph_nb; ph++) { double norm = 0; s = sin_lut[ph]; for(i=0;i<=tap_count;i++) { @@ -203,6 +202,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap case AV_SAMPLE_FMT_S16P: for(i=0;i 1 && phase_count_exact < INT_MAX/2) - phase_count_exact *= 2; - if (phase_count_exact <= phase_count) { /* FIXME this is not required when soft compensation is disabled */ phase_count_exact *= phase_count / phase_count_exact; -- cgit v1.2.3