[FFmpeg-cvslog] avfilter/asrc_sinc: Use av_bessel_i0()

Michael Niedermayer git at videolan.org
Mon May 29 02:00:46 EEST 2023


ffmpeg | branch: master | Michael Niedermayer <michael at niedermayer.cc> | Mon May 22 23:39:25 2023 +0200| [1e9c337e0f1f179b6fded7cbe62395ed5053ef5f] | committer: Michael Niedermayer

avfilter/asrc_sinc: Use av_bessel_i0()

The new function is much more precise
For default beta it is slightly slower, but its speed is already at the
worst case in that comparison
while the replaced function becomes much slower for larger beta

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=1e9c337e0f1f179b6fded7cbe62395ed5053ef5f
---

 libavfilter/asrc_sinc.c | 19 ++-----------------
 1 file changed, 2 insertions(+), 17 deletions(-)

diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c
index 258f7a139e..175f030f46 100644
--- a/libavfilter/asrc_sinc.c
+++ b/libavfilter/asrc_sinc.c
@@ -91,27 +91,12 @@ static int query_formats(AVFilterContext *ctx)
     return ff_set_common_samplerates_from_list(ctx, sample_rates);
 }
 
-static float bessel_I_0(float x)
-{
-    float term = 1, sum = 1, last_sum, x2 = x / 2;
-    int i = 1;
-
-    do {
-        float y = x2 / i++;
-
-        last_sum = sum;
-        sum += term *= y * y;
-    } while (sum != last_sum);
-
-    return sum;
-}
-
 static float *make_lpf(int num_taps, float Fc, float beta, float rho,
                        float scale, int dc_norm)
 {
     int i, m = num_taps - 1;
     float *h = av_calloc(num_taps, sizeof(*h)), sum = 0;
-    float mult = scale / bessel_I_0(beta), mult1 = 1.f / (.5f * m + rho);
+    float mult = scale / av_bessel_i0(beta), mult1 = 1.f / (.5f * m + rho);
 
     if (!h)
         return NULL;
@@ -121,7 +106,7 @@ static float *make_lpf(int num_taps, float Fc, float beta, float rho,
     for (i = 0; i <= m / 2; i++) {
         float z = i - .5f * m, x = z * M_PI, y = z * mult1;
         h[i] = x ? sinf(Fc * x) / x : Fc;
-        sum += h[i] *= bessel_I_0(beta * sqrtf(1.f - y * y)) * mult;
+        sum += h[i] *= av_bessel_i0(beta * sqrtf(1.f - y * y)) * mult;
         if (m - i != i) {
             h[m - i] = h[i];
             sum += h[i];



More information about the ffmpeg-cvslog mailing list