From patchwork Mon May 22 23:35:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 41783 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp175116pzb; Mon, 22 May 2023 16:36:14 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5Qt3DuZhjMC+9vM+ra6DOkP9HyFoptJAvqjDPEWsrdBq8vI+xXq3EqsMO3AeB9CcEhItku X-Received: by 2002:a17:907:6e29:b0:969:813c:9868 with SMTP id sd41-20020a1709076e2900b00969813c9868mr13861695ejc.18.1684798574616; Mon, 22 May 2023 16:36:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684798574; cv=none; d=google.com; s=arc-20160816; b=TDPgJERP8/6UeJK8lGumt2VVeiEKeMe6CozERToSG8UywGCzmccSUJwDSpWjixAR8H iu077oTrUREMGUp6WKRekexXgBDxrHy+aWyZpW4aKOvtYcYRjt8yH3+5sTUGPkDCKtr5 lx1XYjc0nc2g5Fjil7PhfYBJST+IemDvF+0W0TIb8XToeH5C/uXT7ij3ePNmuBpqp69T UYJwFWaNs3klWq3e+I3MhoolZ+6Ba34vJTSmAB3bnRIv6o2b9IIkQoD1ky5CiJ/paHfH gTIlIKAxGe9cXCNlSu6QhDwPfvxTaRerpL9zFT3RPpO+7UuZMmCdEu5j2Tg/bzh+ur/R OuqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:message-id:date:to:from:delivered-to; bh=iVnkDBe8eft+DkXE5geWU2REdazaAxSI0GA6XYFso98=; b=m3ZpBUk6GHV7dBvknLjr9Swrya4hIA68ilxuOKuRS3+YiuCFRu+koxR66cYarQ9Klx uK5pgYEckEb1FvcLpd38yzjPjOX3yGrO/9jMxzGqQHtmVFw6nAxxiM6yPq913oI0gbtP 9+E4OkxHSoFnfhkHTmn+119ic6A0dmGAibF/QdgKvJjHlslbSVgU9DI5TNSrDVlVbyJd el0kpgsnzEMcuAFxqvvxDyagUyIvpWDvnsaPnyxfmwrqGkfGHbJV7+wwfeVJ4tPidp1V ee9jNiQCLsr4jJ/ieCOs2NRKHgDoxjMfU/ZGoi02zDd4VNTZ0W2lI12+dtvuu71eT56u S57w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id w22-20020a170907271600b0096f231529f1si1209599ejk.870.2023.05.22.16.36.13; Mon, 22 May 2023 16:36:14 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9CB4D68C08B; Tue, 23 May 2023 02:36:09 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E066A68BBA2 for ; Tue, 23 May 2023 02:36:02 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 1691DE0003 for ; Mon, 22 May 2023 23:36:01 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 23 May 2023 01:35:56 +0200 Message-Id: <20230522233601.20552-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/6] Move bessel_i0() from swresample/resample to avutil/mathematics X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: vDgXRIkBvJG/ 0th order modified bessel function of the first kind are used in multiple places, lets avoid having 3+ different implementations I picked this one as its accurate and quite fast, it can be replaced if a better one is found Signed-off-by: Michael Niedermayer --- doc/APIchanges | 3 ++ libavutil/mathematics.c | 104 ++++++++++++++++++++++++++++++++++++++ libavutil/mathematics.h | 4 ++ libswresample/resample.c | 106 +-------------------------------------- 4 files changed, 112 insertions(+), 105 deletions(-) diff --git a/doc/APIchanges b/doc/APIchanges index 130955ef02..b256df9c54 100644 --- a/doc/APIchanges +++ b/doc/APIchanges @@ -2,6 +2,9 @@ The last version increases of all libraries were on 2023-02-09 API changes, most recent first: +2023-xx-xx - xxxxxxxxxx - lavu 58.x.100 - mathematics.h + Add av_bessel_i0() + 2023-05-xx - xxxxxxxxxx - lavu 58.8.100 - frame.h Add av_frame_replace(). diff --git a/libavutil/mathematics.c b/libavutil/mathematics.c index b878317d63..61aeb7c029 100644 --- a/libavutil/mathematics.c +++ b/libavutil/mathematics.c @@ -213,3 +213,107 @@ int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t i return av_sat_add64(av_rescale_q(old + 1, inc_tb, ts_tb), ts - old_ts); } } + +static inline double eval_poly(const double *coeff, int size, double x) { + double sum = coeff[size-1]; + int i; + for (i = size-2; i >= 0; --i) { + sum *= x; + sum += coeff[i]; + } + return sum; +} + +/** + * 0th order modified bessel function of the first kind. + * Algorithm taken from the Boost project, source: + * https://searchcode.com/codesearch/view/14918379/ + * Use, modification and distribution are subject to the + * Boost Software License, Version 1.0 (see notice below). + * Boost Software License - Version 1.0 - August 17th, 2003 +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. + */ + +double av_bessel_i0(double x) { +// Modified Bessel function of the first kind of order zero +// minimax rational approximations on intervals, see +// Blair and Edwards, Chalk River Report AECL-4928, 1974 + static const double p1[] = { + -2.2335582639474375249e+15, + -5.5050369673018427753e+14, + -3.2940087627407749166e+13, + -8.4925101247114157499e+11, + -1.1912746104985237192e+10, + -1.0313066708737980747e+08, + -5.9545626019847898221e+05, + -2.4125195876041896775e+03, + -7.0935347449210549190e+00, + -1.5453977791786851041e-02, + -2.5172644670688975051e-05, + -3.0517226450451067446e-08, + -2.6843448573468483278e-11, + -1.5982226675653184646e-14, + -5.2487866627945699800e-18, + }; + static const double q1[] = { + -2.2335582639474375245e+15, + 7.8858692566751002988e+12, + -1.2207067397808979846e+10, + 1.0377081058062166144e+07, + -4.8527560179962773045e+03, + 1.0, + }; + static const double p2[] = { + -2.2210262233306573296e-04, + 1.3067392038106924055e-02, + -4.4700805721174453923e-01, + 5.5674518371240761397e+00, + -2.3517945679239481621e+01, + 3.1611322818701131207e+01, + -9.6090021968656180000e+00, + }; + static const double q2[] = { + -5.5194330231005480228e-04, + 3.2547697594819615062e-02, + -1.1151759188741312645e+00, + 1.3982595353892851542e+01, + -6.0228002066743340583e+01, + 8.5539563258012929600e+01, + -3.1446690275135491500e+01, + 1.0, + }; + double y, r, factor; + if (x == 0) + return 1.0; + x = fabs(x); + if (x <= 15) { + y = x * x; + return eval_poly(p1, FF_ARRAY_ELEMS(p1), y) / eval_poly(q1, FF_ARRAY_ELEMS(q1), y); + } + else { + y = 1 / x - 1.0 / 15; + r = eval_poly(p2, FF_ARRAY_ELEMS(p2), y) / eval_poly(q2, FF_ARRAY_ELEMS(q2), y); + factor = exp(x) / sqrt(x); + return factor * r; + } +} diff --git a/libavutil/mathematics.h b/libavutil/mathematics.h index 3e7b52eed6..e213bab68c 100644 --- a/libavutil/mathematics.h +++ b/libavutil/mathematics.h @@ -288,6 +288,10 @@ int64_t av_rescale_delta(AVRational in_tb, int64_t in_ts, AVRational fs_tb, int */ int64_t av_add_stable(AVRational ts_tb, int64_t ts, AVRational inc_tb, int64_t inc); +/** + * 0th order modified bessel function of the first kind. + */ +double av_bessel_i0(double x); /** * @} diff --git a/libswresample/resample.c b/libswresample/resample.c index 8f9efc3f21..bd54a7002f 100644 --- a/libswresample/resample.c +++ b/libswresample/resample.c @@ -30,110 +30,6 @@ #include "libavutil/cpu.h" #include "resample.h" -static inline double eval_poly(const double *coeff, int size, double x) { - double sum = coeff[size-1]; - int i; - for (i = size-2; i >= 0; --i) { - sum *= x; - sum += coeff[i]; - } - return sum; -} - -/** - * 0th order modified bessel function of the first kind. - * Algorithm taken from the Boost project, source: - * https://searchcode.com/codesearch/view/14918379/ - * Use, modification and distribution are subject to the - * Boost Software License, Version 1.0 (see notice below). - * Boost Software License - Version 1.0 - August 17th, 2003 -Permission is hereby granted, free of charge, to any person or organization -obtaining a copy of the software and accompanying documentation covered by -this license (the "Software") to use, reproduce, display, distribute, -execute, and transmit the Software, and to prepare derivative works of the -Software, and to permit third-parties to whom the Software is furnished to -do so, all subject to the following: - -The copyright notices in the Software and this entire statement, including -the above license grant, this restriction and the following disclaimer, -must be included in all copies of the Software, in whole or in part, and -all derivative works of the Software, unless such copies or derivative -works are solely in the form of machine-executable object code generated by -a source language processor. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT -SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE -FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER -DEALINGS IN THE SOFTWARE. - */ - -static double bessel(double x) { -// Modified Bessel function of the first kind of order zero -// minimax rational approximations on intervals, see -// Blair and Edwards, Chalk River Report AECL-4928, 1974 - static const double p1[] = { - -2.2335582639474375249e+15, - -5.5050369673018427753e+14, - -3.2940087627407749166e+13, - -8.4925101247114157499e+11, - -1.1912746104985237192e+10, - -1.0313066708737980747e+08, - -5.9545626019847898221e+05, - -2.4125195876041896775e+03, - -7.0935347449210549190e+00, - -1.5453977791786851041e-02, - -2.5172644670688975051e-05, - -3.0517226450451067446e-08, - -2.6843448573468483278e-11, - -1.5982226675653184646e-14, - -5.2487866627945699800e-18, - }; - static const double q1[] = { - -2.2335582639474375245e+15, - 7.8858692566751002988e+12, - -1.2207067397808979846e+10, - 1.0377081058062166144e+07, - -4.8527560179962773045e+03, - 1.0, - }; - static const double p2[] = { - -2.2210262233306573296e-04, - 1.3067392038106924055e-02, - -4.4700805721174453923e-01, - 5.5674518371240761397e+00, - -2.3517945679239481621e+01, - 3.1611322818701131207e+01, - -9.6090021968656180000e+00, - }; - static const double q2[] = { - -5.5194330231005480228e-04, - 3.2547697594819615062e-02, - -1.1151759188741312645e+00, - 1.3982595353892851542e+01, - -6.0228002066743340583e+01, - 8.5539563258012929600e+01, - -3.1446690275135491500e+01, - 1.0, - }; - double y, r, factor; - if (x == 0) - return 1.0; - x = fabs(x); - if (x <= 15) { - y = x * x; - return eval_poly(p1, FF_ARRAY_ELEMS(p1), y) / eval_poly(q1, FF_ARRAY_ELEMS(q1), y); - } - else { - y = 1 / x - 1.0 / 15; - r = eval_poly(p2, FF_ARRAY_ELEMS(p2), y) / eval_poly(q2, FF_ARRAY_ELEMS(q2), y); - factor = exp(x) / sqrt(x); - return factor * r; - } -} - /** * builds a polyphase filterbank. * @param factor resampling factor @@ -189,7 +85,7 @@ static int build_filter(ResampleContext *c, void *filter, double factor, int tap break; case SWR_FILTER_TYPE_KAISER: w = 2.0*x / (factor*tap_count*M_PI); - y *= bessel(kaiser_beta*sqrt(FFMAX(1-w*w, 0))); + y *= av_bessel_i0(kaiser_beta*sqrt(FFMAX(1-w*w, 0))); break; default: av_assert0(0); From patchwork Mon May 22 23:35:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 41784 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp175166pzb; Mon, 22 May 2023 16:36:25 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7NDQMWCMDO2wrVyd7YH7/7jS5Mcqq1ARrYk6RuGL5jfZGmdxyipqdAyqGjTVV5jUbOaN37 X-Received: by 2002:a17:906:80cf:b0:965:6199:cf60 with SMTP id a15-20020a17090680cf00b009656199cf60mr10578481ejx.42.1684798585262; Mon, 22 May 2023 16:36:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684798585; cv=none; d=google.com; s=arc-20160816; b=wjqnNwkTd75tHrFgvLMuQGVVfiGhNuIpfkaT/5HGddo2JOr9V/rPDuWfafHxbiQvXR 32tNtLs7pdeuvIvMSqrgmRbTDMXHn3xptCI4/nLOA03H3ATyOzZ6tZgWxXoEpPL8GKoQ AvyHQ/HzFvvhzUTzb3jWyFSeDWkYr2ZfHZ14Gcml03gucBdDivygv4VLNIo+K2dFjgoc qgABq8AaANa8mleG76LCeVbHzk920fCEGJYO3x3we4oqYLJUk8Ic57Tp04kAsWOVuUWD 4W+0k8dsa7Z5h3ApmtfqyDm5y/c4pEj7EPxzSNdfedPzBwAV7eEoiVPVYZDdQMtludhO d0Kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=RwaEiD2DqL4sD4q4TDLquGqehdFeugrbTZXhsh7vZxI=; b=j72M/8SaQPZS4+aQhMdpCtuT+JUbo8gXpdfcnYH56bqgXEoQoG1weZkIbSmf1zIf0n U/NLMYlRTfow7qmLmNP6by4bwAD771kqyyA9Kk+N6BDO2BFeQxhQBd63g1dXVj39lIwU cwJuFHRCiBopoQSeaZIS3e76KgRRd1TqpD2lu5/Kh7kRGr8MIRDFko9niedV7+brGqzi 3e4TQToMD1S6r0LdIjlq9VrgYemgUQK4fcTll0MK13qSV/kPkmOdL6G6Y67CtLBfv9O2 +Ifx8zdHNHDq+PtwlN3v4R0eVgeH8HPJgM7ioE5XizJTnZGWpi2ksw1dq9ulJkLj//J8 dY3A== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id rk11-20020a170907214b00b0096f0365aa54si11824ejb.290.2023.05.22.16.36.24; Mon, 22 May 2023 16:36:25 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5AD0A68C0E4; Tue, 23 May 2023 02:36:11 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CAE9568C030 for ; Tue, 23 May 2023 02:36:03 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 116831BF203 for ; Mon, 22 May 2023 23:36:02 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 23 May 2023 01:35:57 +0200 Message-Id: <20230522233601.20552-2-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230522233601.20552-1-michael@niedermayer.cc> References: <20230522233601.20552-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 2/6] avfilter/asrc_sinc: Use av_bessel_i0() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: FQmmlO1ZuRpz 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 --- libavfilter/asrc_sinc.c | 21 ++------------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/libavfilter/asrc_sinc.c b/libavfilter/asrc_sinc.c index 258f7a139e..ba22f69889 100644 --- a/libavfilter/asrc_sinc.c +++ b/libavfilter/asrc_sinc.c @@ -91,43 +91,26 @@ 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; av_assert0(Fc >= 0 && Fc <= 1); - 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]; } } - for (i = 0; dc_norm && i < num_taps; i++) h[i] *= scale / sum; From patchwork Mon May 22 23:35:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 41785 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp175218pzb; Mon, 22 May 2023 16:36:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6+kVoPbFKmrSGXew8kp+qmD3yE2ZHvC88kS1QjI9/j+fXDbBAyzz5i+oXGpeyz4SYnvS+k X-Received: by 2002:a17:907:7288:b0:957:28b2:560a with SMTP id dt8-20020a170907728800b0095728b2560amr11551763ejc.46.1684798593754; Mon, 22 May 2023 16:36:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684798593; cv=none; d=google.com; s=arc-20160816; b=wVBQFdv5hEPrIkfhGRe3biC8qOMrQNcIurPd3RBNu/g6DeofTDrxnjsnKE+I3En1nX 0PemwSUI32Etl0PMgpqIpsLvjMqJAA+NfbZP+XHiBZm2NKXVNuSBCV1oI2zaX1btJVDH 0hFnkTvONL20yx6sPhjWBATXa1yso1UcmlDyZ7M3yM53gxiZsBFtnIJSE9GtUB/ZSqCf p+K4GCUpolS5K2hmuenXcuauzkj+v++4a54FweWQPDkD8ob04LZy5GfpBrS21PZUqcSc EHd2heTQcdfPg8vKxUq/IpQrUmuzCYsy59KSIkI/eOuuhuUQeuv6ps7gPLn0TuIleXgN ovvg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=dK7XfbePb7o461ctFqJ2xGxAwvUTCRtYItdslEibZ1g=; b=BhC1Z7RzgWYh0FrjtLXMDODMQu+fxfjt8/eivn+fchWLRZVIzs6KolyFeokG4j+71m q1wh4pcFppIRH9SYvdAlUJXQ5wc1lBeqrHt89j9ICbzaFyHamupRiDe7rl2Kd6Y8EtZn Q/wK+UKpuZscOprjLMv3pBiUqOJn6qWqQPJwXY+rpER7Oy75O6doQI2qCi1/HtNCCQwZ Gj5kBUBOXhO34pxiSvBXyw4Kx8oz26x+CAJc5zIDQpX35lsGCyBSmSTuxKKq/2s/OSbP XtNtI39qSbgxsGKSCRregqVHb8XY+ENWMbfXW4+TQmxDQHi5ag+9wvQxoqgYjqzA+AbV 3OZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id n8-20020aa7c448000000b00506bd4fba2asi5363908edr.319.2023.05.22.16.36.33; Mon, 22 May 2023 16:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5FA3868C11D; Tue, 23 May 2023 02:36:13 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CE40868C0B9 for ; Tue, 23 May 2023 02:36:04 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 185A1FF804 for ; Mon, 22 May 2023 23:36:03 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 23 May 2023 01:35:58 +0200 Message-Id: <20230522233601.20552-3-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230522233601.20552-1-michael@niedermayer.cc> References: <20230522233601.20552-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 3/6] avfilter/window_func: Use av_bessel_i0() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ZUAPTxqGSQck Old code needed about 6 times as long as new with defaults in afftfilt Signed-off-by: Michael Niedermayer --- libavfilter/window_func.h | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/libavfilter/window_func.h b/libavfilter/window_func.h index 02b5def9dd..13236d8593 100644 --- a/libavfilter/window_func.h +++ b/libavfilter/window_func.h @@ -25,6 +25,7 @@ #include #include "libavutil/avassert.h" #include "libavutil/common.h" +#include "libavutil/timer.h" enum WindowFunc { WFUNC_RECT, WFUNC_HANNING, WFUNC_HAMMING, WFUNC_BLACKMAN, WFUNC_BARTLETT, WFUNC_WELCH, WFUNC_FLATTOP, @@ -59,19 +60,6 @@ enum WindowFunc { WFUNC_RECT, WFUNC_HANNING, WFUNC_HAMMING, WFUNC_BLACKMAN, { "bohman", "Bohman", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_BOHMAN}, 0, 0, flag, "win_func" }, \ { "kaiser", "Kaiser", 0, AV_OPT_TYPE_CONST, {.i64=WFUNC_KAISER}, 0, 0, flag, "win_func" } -static inline double get_i0(double x) -{ - double y = 1.0, prev = 1.0, i = 1.0; - - while (fabs(prev) > 1e-20) { - double summand = prev * x * x / (4 * i * i); - y += summand; - prev = summand; - i++; - } - - return y; -} static inline void generate_window_func(float *lut, int N, int win_func, float *overlap) @@ -232,13 +220,15 @@ static inline void generate_window_func(float *lut, int N, int win_func, *overlap = 0.75; break; case WFUNC_KAISER: + { + double scale = 1.0 / av_bessel_i0(12.); for (n = 0; n < N; n++) { double x = 2.0 / (double)(N - 1); - - lut[n] = get_i0(12. * sqrt(1. - SQR(n * x - 1.))) / get_i0(12.); + lut[n] = av_bessel_i0(12. * sqrt(1. - SQR(n * x - 1.))) * scale; } *overlap = 0.75; break; + } default: av_assert0(0); } From patchwork Mon May 22 23:35:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 41786 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp175268pzb; Mon, 22 May 2023 16:36:42 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6VZAww0BRoHGm18vzEz/FdUbFl0gMHnyf6iNDetMalBTdkKoQtYzpi1CpS1RFKKvdC9VS0 X-Received: by 2002:aa7:d9c3:0:b0:50b:cae1:d7a3 with SMTP id v3-20020aa7d9c3000000b0050bcae1d7a3mr10620795eds.14.1684798602628; Mon, 22 May 2023 16:36:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684798602; cv=none; d=google.com; s=arc-20160816; b=swi8S4D0XNMwpRlS7SKXaZJ9hlYndq2fLG+5b2A946vXA7NFPnHCDpSHp9ZPsVI8v2 WImQ1gYnp9LVhYw2ZI/EgSnIGC+3SMq5ujvQv5CbnwkzUImhjc4riZV1a4lJUz420DPm /62C44bWOaAS/NPXF/+9HmLuwfVlmo1bbkdLxnp+p/wMZtIOxYFlDZf4t0oo8gastfpj NZIZlrkKL7jjYHH5pmQ0Fzp2Ylw7mDEiG4L9mAX7anJVWLiFgjW5wnQ3NcQoeiV//1Aa kiDu8RQJtoCmVTSvEcuGUPUYMsohY1nG7/emXhYZlzgd2wls0ZZzFMPc+s8zYhK9qwYR 26/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=a0JiF1FaN1gvn023tIlcW6abT8jigMXLahuDMgMTgEE=; b=zNe3tVEjPbHzLDVlDDU0gcIOeQavN5wlm7bImFyu+KWvIMZGJZ93scYoNKWiVTQ20Y GCCqxEOipMDy8Fx6r5JHbskivUYFfHIjZESuZtxETmwDS03HVVRAqEYTDpgEXrzBhYJK byg2fWZfPXGIvq8GqXVDYtnd1N5ZQzmQgRLhoz0kVoGqNuHlWtCkR838WYPww97WpvJ7 F1xvYLHYirzJC0froaNfael4+b2FNCgLrN8GdHgleDV4Ug7PsC3BBnPHPpOTALG87cPL +sx7abOeWJj7qCo9Trc6qxXo0z5BNsvcEYnB5WASmm/CGZTy1Pj+2o9cj0lZbRU+v1MD n7iQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id b19-20020aa7df93000000b0050de22010a3si347306edy.456.2023.05.22.16.36.42; Mon, 22 May 2023 16:36:42 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 5DD5868C0B4; Tue, 23 May 2023 02:36:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B891168C0C1 for ; Tue, 23 May 2023 02:36:05 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id F3D9360004 for ; Mon, 22 May 2023 23:36:04 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 23 May 2023 01:35:59 +0200 Message-Id: <20230522233601.20552-4-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230522233601.20552-1-michael@niedermayer.cc> References: <20230522233601.20552-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 4/6] avcodec/kbdwin: Use av_bessel_i0() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: gBF3769RzR+W Old code used about 7 times as many cpu cycles as new Signed-off-by: Michael Niedermayer --- libavcodec/kbdwin.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c index bf32aeb317..5dff334250 100644 --- a/libavcodec/kbdwin.c +++ b/libavcodec/kbdwin.c @@ -21,8 +21,6 @@ #include "libavutil/attributes.h" #include "kbdwin.h" -#define BESSEL_I0_ITER 50 // default: 50 iterations of Bessel I0 approximation - av_cold void ff_kbd_window_init(float *window, float alpha, int n) { int i, j; @@ -34,9 +32,7 @@ av_cold void ff_kbd_window_init(float *window, float alpha, int n) for (i = 0; i < n; i++) { tmp = i * (n - i) * alpha2; - bessel = 1.0; - for (j = BESSEL_I0_ITER; j > 0; j--) - bessel = bessel * tmp / (j * j) + 1; + bessel = av_bessel_i0(sqrt(tmp) * 2); sum += bessel; local_window[i] = sum; } From patchwork Mon May 22 23:36:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 41787 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp175334pzb; Mon, 22 May 2023 16:36:52 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7sjrlkhhFGMAz9ODqGOpnAn6t7wR8qZE1w2kkZDg5kOyAcqmhULW+pERVjT57TPOoAHxdB X-Received: by 2002:aa7:c0d5:0:b0:50b:c9d4:8804 with SMTP id j21-20020aa7c0d5000000b0050bc9d48804mr10687754edp.4.1684798612177; Mon, 22 May 2023 16:36:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684798612; cv=none; d=google.com; s=arc-20160816; b=qaSigRjB2aq3HULfxJbcUqOdjgeY5WOqgmvGeLc0eniZ2I9vld+vRPEzELMkjGaU2H L1krKs/4PNkE+EnjSCMZp1NJnzE6H4KcMTk2LN3SRPkiQs4UqU7XTsXMCaZ6WIUZ+OGF /vVYVJ0Juq+kJagycxFC/NEFXdg4zBjM7DQT94rgV9w1j4LXj0TMXtpbfwtJ7DKk+6F1 Widm3H2pGB+K7E5yLZzPs601b+0NRUF+GbLk+iQXX4wE5n1KPnsaMCyP0+M+b+lQQOw2 XkTi6uxAe7r1yd7R1FjiyB+0qmEvoL3d5J4f6d0EHx/5vCHDYCcUtEVh6OJXi03aG6zr 0F9Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=I0PxEEyRtFuAoVmKlEpRr2xSKMBWAlwqGYvJmSMzKt0=; b=U63IYXbCaEhbFtj9Kv0QRUNunp4l8ru+i3SQB4CyqjwNR4iaSbHOfZ4PPr3okwOAt6 y4xc0UxLL++9BbU8NxRqtUppQ5TYajcqgRcJSncRQrRcvowg9rALTxom4A2oZofPBO5C 0Hr6qVdwg0clOLWA7WfbyFS2O9+TdXHtgaSnF+tcIHZwAu9EFjQ+BELggNMEmNc/RV3S 8SP70zRWuP6er7DAgnE6njof0kllr8x4spGwJiUqpMz97gfyd5mAjEM8+1O/wrqnpW9c qQTkIRRFNlUmv5+ZWKhKTF3/uYfQdSLPf0az5czifSAbXhV2OCJ7Q2V9fJN8OGUJ3TYQ hgmw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id v13-20020aa7cd4d000000b0050bc9115cacsi4432599edw.293.2023.05.22.16.36.51; Mon, 22 May 2023 16:36:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 588AB68C126; Tue, 23 May 2023 02:36:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 59F0A68C095 for ; Tue, 23 May 2023 02:36:06 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id BE2D91BF205 for ; Mon, 22 May 2023 23:36:05 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 23 May 2023 01:36:00 +0200 Message-Id: <20230522233601.20552-5-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230522233601.20552-1-michael@niedermayer.cc> References: <20230522233601.20552-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 5/6] avcodec/kbdwin: Avoid computing bessel values twice X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: GU6Fmw26tkGJ Also reduce neeeded temporary storage by half Signed-off-by: Michael Niedermayer --- libavcodec/kbdwin.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c index 5dff334250..e2f6491124 100644 --- a/libavcodec/kbdwin.c +++ b/libavcodec/kbdwin.c @@ -23,23 +23,29 @@ av_cold void ff_kbd_window_init(float *window, float alpha, int n) { - int i, j; - double sum = 0.0, bessel, tmp; - double local_window[FF_KBD_WINDOW_MAX]; - double alpha2 = (alpha * M_PI / n) * (alpha * M_PI / n); + int i; + double sum = 0.0, tmp; + double scale = 0.0; + double temp[FF_KBD_WINDOW_MAX / 2 + 1]; + double alpha2 = 4 * (alpha * M_PI / n) * (alpha * M_PI / n); av_assert0(n <= FF_KBD_WINDOW_MAX); - for (i = 0; i < n; i++) { + for (i = 0; i <= n / 2; i++) { tmp = i * (n - i) * alpha2; - bessel = av_bessel_i0(sqrt(tmp) * 2); - sum += bessel; - local_window[i] = sum; + temp[i] = av_bessel_i0(sqrt(tmp)); + scale += temp[i] * (1 + (i && i X-Patchwork-Id: 41788 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c51c:b0:10c:5e6f:955f with SMTP id gm28csp175388pzb; Mon, 22 May 2023 16:37:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ74tfnX7Q91mzUpHGeI4eOL9HLranc8QZpptSX4zmiQrnbuenRDJeH7QUpYLFQH96vzrvqE X-Received: by 2002:a17:907:6d07:b0:939:e870:2b37 with SMTP id sa7-20020a1709076d0700b00939e8702b37mr10825371ejc.70.1684798621756; Mon, 22 May 2023 16:37:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684798621; cv=none; d=google.com; s=arc-20160816; b=n6KMv1mwiMGZOSeC7khGisiN/f+XgkOb4Loayo3drTXiY+YWWqBibc3HWMuUzKezje Owk9g2dro2VbMo2gKnNQfS0uK17bI+50je22NYNinAfTgJe6Xwfy0EY6wT+5ZBd14hxA YoV4l2zKU32phUlBXQjVCW5tv+IhIb5CVgNcqfQZFZnatr4rE69gNzjKxIk0rgoHqL8Y FDKPD1yFiB3Ur0ny83mQJx47JD+HsDjNUx6RQ7hA027WUyxBlzVHIxzFtKaJ/xPueNC1 31hwBNdjBDiwcrQ7lYFyF4Fobls/xCra3o6xsieOqCj7PjzjBMCKQsCAfR6nE7GhMIAN naWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:delivered-to; bh=83yoayrvvhrI3qKNYOys4V4caRbl+DH3QJceFeBZ/m4=; b=Z7utYum7YnkTBg3P0dws/xG2GwcgAr6L/2MaiIAGi7c3bdB7uG4CBxODeUU/kWtvjX 6fMcSvsuLNFSyAvijHMXVAZf43ZK/SXAkZNsbXFPmCADSkQiod2bTKbVLpcDl3YiyGx/ hgxydK7MBYNIPiri9JQK4TUSuUTXBNcuc+AwLpr5Pz2WFk8jR+7Y2NauT/23mKvIyxff jtlLOEUP7EdYxCilE4y5M3qFWq1S84dWWWytINAMpWKiHrgL0EWIS52RYw2Zq04HXnud KOn04j0hGwj7QGHjVVXefrmZfj17wpoTfB3xaV06TMm+cB5sWJuHzwoLAM/rA2J7pV8H IfpA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o26-20020a1709062e9a00b009664e704c2dsi409160eji.132.2023.05.22.16.37.01; Mon, 22 May 2023 16:37:01 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 59B0168C13C; Tue, 23 May 2023 02:36:16 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A301268C0F4 for ; Tue, 23 May 2023 02:36:07 +0300 (EEST) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id DB311240003 for ; Mon, 22 May 2023 23:36:06 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 23 May 2023 01:36:01 +0200 Message-Id: <20230522233601.20552-6-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230522233601.20552-1-michael@niedermayer.cc> References: <20230522233601.20552-1-michael@niedermayer.cc> Subject: [FFmpeg-devel] [PATCH 6/6] avcodec/kbdwin: Remove low precision intermediate in ff_kbd_window_init_fixed() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: rGka/mP7mdUu Previously floats where scaled up to 32bit int, but floats do not have 32bits in their mantisse so a quarter of the bits where nonsense. It seems no fate test is affected by this change, which is interresting Signed-off-by: Michael Niedermayer --- libavcodec/kbdwin.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/libavcodec/kbdwin.c b/libavcodec/kbdwin.c index e2f6491124..163f9d5251 100644 --- a/libavcodec/kbdwin.c +++ b/libavcodec/kbdwin.c @@ -21,7 +21,7 @@ #include "libavutil/attributes.h" #include "kbdwin.h" -av_cold void ff_kbd_window_init(float *window, float alpha, int n) +av_cold static void kbd_window_init(float *float_window, int *int_window, float alpha, int n) { int i; double sum = 0.0, tmp; @@ -40,20 +40,22 @@ av_cold void ff_kbd_window_init(float *window, float alpha, int n) for (i = 0; i <= n / 2; i++) { sum += temp[i]; - window[i] = sqrt(sum * scale); + if (float_window) float_window[i] = sqrt(sum * scale); + else int_window[i] = lrint(2147483647 * sqrt(sum * scale)); } for (; i < n; i++) { sum += temp[n - i]; - window[i] = sqrt(sum * scale); + if (float_window) float_window[i] = sqrt(sum * scale); + else int_window[i] = lrint(2147483647 * sqrt(sum * scale)); } } -av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n) +av_cold void ff_kbd_window_init(float *window, float alpha, int n) { - int i; - float local_window[FF_KBD_WINDOW_MAX]; + kbd_window_init(window, NULL, alpha, n); +} - ff_kbd_window_init(local_window, alpha, n); - for (i = 0; i < n; i++) - window[i] = (int)floor(2147483647.0 * local_window[i] + 0.5); +av_cold void ff_kbd_window_init_fixed(int32_t *window, float alpha, int n) +{ + kbd_window_init(NULL, window, alpha, n); }