diff mbox series

[FFmpeg-devel,1/2] swresample/resample: fix rounding errors with filter_size=1 and phase_shift=0

Message ID 20240227094810.1182-1-cus@passwd.hu
State Accepted
Commit 7b1b9bb31f04fb9ba06e79c767c1084f0e229bb6
Headers show
Series [FFmpeg-devel,1/2] swresample/resample: fix rounding errors with filter_size=1 and phase_shift=0 | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Marton Balint Feb. 27, 2024, 9:48 a.m. UTC
Depending on input chunk size noticable corrpution was hearable, here is an
example command line:

ffplay -f lavfi -i "sine=440:r=8000:samples_per_frame=32,aresample=24000:filter_size=1:phase_shift=0"

Fix this by rounding the fixed point fractions up instead of down.

Signed-off-by: Marton Balint <cus@passwd.hu>
---
 libswresample/resample.c     | 4 ++--
 tests/fate/libswresample.mak | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

Comments

Michael Niedermayer Feb. 27, 2024, 5:53 p.m. UTC | #1
On Tue, Feb 27, 2024 at 10:48:09AM +0100, Marton Balint wrote:
> Depending on input chunk size noticable corrpution was hearable, here is an
> example command line:
> 
> ffplay -f lavfi -i "sine=440:r=8000:samples_per_frame=32,aresample=24000:filter_size=1:phase_shift=0"
> 
> Fix this by rounding the fixed point fractions up instead of down.
> 
> Signed-off-by: Marton Balint <cus@passwd.hu>
> ---
>  libswresample/resample.c     | 4 ++--
>  tests/fate/libswresample.mak | 4 ++--
>  2 files changed, 4 insertions(+), 4 deletions(-)

probably ok

thx


[...]
diff mbox series

Patch

diff --git a/libswresample/resample.c b/libswresample/resample.c
index bd54a7002f..17cebad01b 100644
--- a/libswresample/resample.c
+++ b/libswresample/resample.c
@@ -357,8 +357,8 @@  static int multiple_resample(ResampleContext *c, AudioData *dst, int dst_size, A
     *consumed = 0;
 
     if (c->filter_length == 1 && c->phase_count == 1) {
-        int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*c->index;
-        int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr;
+        int64_t index2= (1LL<<32)*c->frac/c->src_incr + (1LL<<32)*c->index + 1;
+        int64_t incr= (1LL<<32) * c->dst_incr / c->src_incr + 1;
         int new_size = (src_size * (int64_t)c->src_incr - c->frac + c->dst_incr - 1) / c->dst_incr;
 
         dst_size = FFMAX(FFMIN(dst_size, new_size), 0);
diff --git a/tests/fate/libswresample.mak b/tests/fate/libswresample.mak
index 2fc55ea61a..0971a6b3ba 100644
--- a/tests/fate/libswresample.mak
+++ b/tests/fate/libswresample.mak
@@ -347,13 +347,13 @@  endef
 fate-swr-resample_nn-fltp-44100-8000: CMP_TARGET = 591.03
 fate-swr-resample_nn-fltp-44100-8000: SIZE_TOLERANCE = 529200 - 20486
 
-fate-swr-resample_nn-fltp-8000-44100: CMP_TARGET = 3163.32
+fate-swr-resample_nn-fltp-8000-44100: CMP_TARGET = 3156.61
 fate-swr-resample_nn-fltp-8000-44100: SIZE_TOLERANCE = 96000 - 20480
 
 fate-swr-resample_nn-s16p-44100-8000: CMP_TARGET = 590.98
 fate-swr-resample_nn-s16p-44100-8000: SIZE_TOLERANCE = 529200 - 20486
 
-fate-swr-resample_nn-s16p-8000-44100: CMP_TARGET = 3163.39
+fate-swr-resample_nn-s16p-8000-44100: CMP_TARGET = 3156.61
 fate-swr-resample_nn-s16p-8000-44100: SIZE_TOLERANCE = 96000 - 20480
 
 define ARESAMPLE_ASYNC