From 61926b6c3e560283ef6c015d6d85c32716942833 Mon Sep 17 00:00:00 2001 From: Muhammad Faiz Date: Wed, 1 Mar 2017 22:18:36 +0700 Subject: swresample/resample: use uniform normalization this gives better frequency response update swresample fate and other fates that depend on resampling Signed-off-by: Muhammad Faiz --- libswresample/resample.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'libswresample') diff --git a/libswresample/resample.c b/libswresample/resample.c index 8e2f76901a..b0d14d1e95 100644 --- a/libswresample/resample.c +++ b/libswresample/resample.c @@ -149,6 +149,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap double *tab = av_malloc_array(tap_count+1, sizeof(*tab)); double *sin_lut = av_malloc_array(ph_nb, sizeof(*sin_lut)); const int center= (tap_count-1)/2; + double norm = 0; int ret = AVERROR(ENOMEM); if (!tab || !sin_lut) @@ -160,10 +161,9 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap if (factor == 1.0) { for (ph = 0; ph < ph_nb; ph++) - sin_lut[ph] = sin(M_PI * ph / phase_count); + sin_lut[ph] = sin(M_PI * ph / phase_count) * (center & 1 ? 1 : -1); } for(ph = 0; ph < ph_nb; ph++) { - double norm = 0; s = sin_lut[ph]; for(i=0;i<=tap_count;i++) { x = M_PI * ((double)(i - center) - (double)ph / phase_count) * factor; @@ -194,7 +194,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap tab[i] = y; s = -s; - if (i < tap_count) + if (!ph && i < tap_count) norm += y; } @@ -211,7 +211,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap else { for (i = 1; i <= tap_count; i++) ((int16_t*)filter)[(phase_count-ph) * alloc + tap_count-i] = - av_clip_int16(lrintf(tab[i] * scale / (norm - tab[0] + tab[tap_count]))); + av_clip_int16(lrintf(tab[i] * scale / norm)); } break; case AV_SAMPLE_FMT_S32P: @@ -225,7 +225,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap else { for (i = 1; i <= tap_count; i++) ((int32_t*)filter)[(phase_count-ph) * alloc + tap_count-i] = - av_clipl_int32(llrint(tab[i] * scale / (norm - tab[0] + tab[tap_count]))); + av_clipl_int32(llrint(tab[i] * scale / norm)); } break; case AV_SAMPLE_FMT_FLTP: @@ -238,7 +238,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap } else { for (i = 1; i <= tap_count; i++) - ((float*)filter)[(phase_count-ph) * alloc + tap_count-i] = tab[i] * scale / (norm - tab[0] + tab[tap_count]); + ((float*)filter)[(phase_count-ph) * alloc + tap_count-i] = tab[i] * scale / norm; } break; case AV_SAMPLE_FMT_DBLP: @@ -251,7 +251,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap } else { for (i = 1; i <= tap_count; i++) - ((double*)filter)[(phase_count-ph) * alloc + tap_count-i] = tab[i] * scale / (norm - tab[0] + tab[tap_count]); + ((double*)filter)[(phase_count-ph) * alloc + tap_count-i] = tab[i] * scale / norm; } break; } -- cgit v1.2.3