From patchwork Thu May 11 22:01:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 41587 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dca6:b0:f3:34fa:f187 with SMTP id ky38csp4949122pzb; Thu, 11 May 2023 15:02:06 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4ZwAPa45TiSnloXqIHXe+1elSKuVKgmAX29VbAC73Yps/3rVIXXSJdU/yZM7mET//83gGk X-Received: by 2002:a05:6402:31e8:b0:50b:fbb5:f934 with SMTP id dy8-20020a05640231e800b0050bfbb5f934mr17211904edb.3.1683842525745; Thu, 11 May 2023 15:02:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683842525; cv=none; d=google.com; s=arc-20160816; b=Am77rSFyZ7R/Ax1MsTro0ySvU9ytro5T/XpIr4qE2pSfxg7xlZ5Kk8ZAeX9BL0Ql5d MONCxv5guXiaKz2D8FWoOzPAnToy3MUlunb2aIONypjWHklnrQVs5Z9+umJg1/rywH8B 7SiWRm1fXZh/12EiJH99N9v4AUmjBJ43+Z8AKfjROlimIQ6ijc4T/0erRXE/sgA3a5DK PhC+ecnEADwK6lmcYtt5OzACQEdWaPiS9Fljs4tJKT5ergyOGkkn1VmbfeMVnZbM4SA5 NJqDhjlC6XvxKVkaWyBzR2KkioxJUdncRgs5gUmYiQ97omQ4dE8HafaYArCZYjC8GSit s3OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=nF1PzJA8wtgMe75oEm13UfN21eBXL3sDH1xK2jdpFn0=; b=AlWOvqUrC8KuzDWb/10c/RQL+4EAt0dFYzwYbnQYDX4xowJn32If43fynt+MCKzWyy +CU8t+Q2KAT3VoAL3MAuAh0BBGDIYNXiskfYs/LLS1ijBV27D66p7/jRt5KilQn+TQKY BCyUUkx/5YRvOBf9zYYHYFYsbFFZmVqk0NXSUGExdjtB+4oB8Hnp41RkvOvBSJOyWLPo TscbmfD5oX+vihCwfRU6ZWHh3U/3A9dopQPAkHAH0ikRdvzoPtsTZQPKtB4GhUibmzeo GUMS3yG1CLOJBPnNVFgYlUgLAIKGnIplzwHXyRF1/nsZpPe5QN7EQsgg0w7RY3bMKJDf Wyaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=PiBGwvpz; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id ba11-20020a0564021acb00b0050bcb5686e3si5100041edb.411.2023.05.11.15.02.05; Thu, 11 May 2023 15:02:05 -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; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20221208 header.b=PiBGwvpz; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 6CEF368C118; Fri, 12 May 2023 01:02:01 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id D552768A92B for ; Fri, 12 May 2023 01:01:54 +0300 (EEST) Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-18f4a6d2822so53791028fac.1 for ; Thu, 11 May 2023 15:01:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683842513; x=1686434513; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=NK7i8OK1STTrDvwc9zlPCJNty5BRlOpGA8cNVM0lHfA=; b=PiBGwvpzphS6CVQul9gpG62EFDceFYpKmwVXGFeVxnlMvwSOzM3mL0YFtPlNt01p40 ODHkP4cva3qDztisyBAHvO6CJDZMsgOo4Fd6jm7SXPRdxHa95Lw9/9OcLsd50gZ+wPxQ esJ0rFkQhzTphrZ5dC69l/e9XdZhPO1Fml8/6ikzbAStVeXguitQ+u3/gWQJ0xru3YiC EiyyI4X4W+oqZPxiRyH7Czb8glYcB+u9eYxjIjH7+SzeS84rAYn9mT0LGNhgKnA35Iv/ R7VGZhgfju8bhvgwE6/eutuOlXEajOf9wz0IHf3DSjjyLPaH7u0eHJ/RE+zTFFxCRyzw +k0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683842513; x=1686434513; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=NK7i8OK1STTrDvwc9zlPCJNty5BRlOpGA8cNVM0lHfA=; b=gIZGo27H9V/pQ9ZpvNB1yF5oKBYkKSyoU81KjxMY7v9t96XuO57D3KDCvZAfIRRi7Q +I9V0L12NWlW4Z909JFh2qAdtkiQfDyRAXHBetNFftOCI0c2WMLOdi2r7bqpjX8nGju2 PPKDs1kbzGOatcXkv1OAuTVTwhlPidKZFtJ1+v/PrhDvNUpDJ26UqetGZbw6yzdwQ6xV Cg2jd10s8xHNktyMOBpfqo1tyTL9dmLGm28NxR1B+JuddSM+UBQCefOis6Ow0IqFk1ee biiYqs/QSeE2a9wXhwmnlTVmQPhbbFQ95vNyxWB4VFJy3UFXjHoRtdgPeIwHjqhILvzC CZ9Q== X-Gm-Message-State: AC+VfDwKocehUUqFuSulQXO31JTiuHD/rqYfonW2ymF9h9pYfzwXCTC6 lFBXJaLOhYvOZ0tnWEuep7TFk/kXIQA= X-Received: by 2002:a05:6870:d8a9:b0:188:b12:5db8 with SMTP id dv41-20020a056870d8a900b001880b125db8mr11960943oab.5.1683842512663; Thu, 11 May 2023 15:01:52 -0700 (PDT) Received: from localhost.localdomain (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id d13-20020a056871040d00b0019296ee9606sm8422867oag.4.2023.05.11.15.01.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 May 2023 15:01:52 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 11 May 2023 19:01:32 -0300 Message-Id: <20230511220132.15338-1-jamrial@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avfilter/af_surround: define M_PI and M_LN10 as a float values 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: ihXvx0QLW4dX This is cleaner than the approach in d1ded7310a. Signed-off-by: James Almer --- libavfilter/af_surround.c | 56 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/libavfilter/af_surround.c b/libavfilter/af_surround.c index bcc89053a4..8ba11c62e7 100644 --- a/libavfilter/af_surround.c +++ b/libavfilter/af_surround.c @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +// Override the values from libavutil/mathematics.h +#define M_LN10 2.3025850929f +#define M_PI 3.1415926535f + #include "libavutil/avassert.h" #include "libavutil/channel_layout.h" #include "libavutil/opt.h" @@ -330,16 +334,16 @@ static void angle_transform(float *x, float *y, float angle) if (angle == 90.f) return; - reference = angle * (float)M_PI / 180.f; + reference = angle * M_PI / 180.f; r = hypotf(*x, *y); a = atan2f(*x, *y); r /= r_distance(a); - if (fabsf(a) <= (float)M_PI_4) - a *= reference / (float)M_PI_2; + if (fabsf(a) <= M_PI_4) + a *= reference / M_PI_2; else - a = (float)M_PI + (-2.f * (float)M_PI + reference) * ((float)M_PI - fabsf(a)) * FFDIFFSIGN(a, 0.f) / (3.f * (float)M_PI_2); + a = M_PI + (-2.f * M_PI + reference) * (M_PI - fabsf(a)) * FFDIFFSIGN(a, 0.f) / (3.f * M_PI_2); r *= r_distance(a); @@ -366,16 +370,16 @@ static void focus_transform(float *x, float *y, float focus) static void stereo_position(float a, float p, float *x, float *y) { av_assert2(a >= -1.f && a <= 1.f); - av_assert2(p >= 0.f && p <= (float)M_PI); - *x = av_clipf(a+a*fmaxf(0.f, p*p-(float)M_PI_2), -1.f, 1.f); - *y = av_clipf(cosf(a*(float)M_PI_2+(float)M_PI)*cosf((float)M_PI_2-p/(float)M_PI)*(float)M_LN10+1.f, -1.f, 1.f); + av_assert2(p >= 0.f && p <= M_PI); + *x = av_clipf(a+a*fmaxf(0.f, p*p-M_PI_2), -1.f, 1.f); + *y = av_clipf(cosf(a*M_PI_2+M_PI)*cosf(M_PI_2-p/M_PI)*M_LN10+1.f, -1.f, 1.f); } static inline void get_lfe(int output_lfe, int n, float lowcut, float highcut, float *lfe_mag, float c_mag, float *mag_total, int lfe_mode) { if (output_lfe && n < highcut) { - *lfe_mag = n < lowcut ? 1.f : .5f*(1.f+cosf((float)M_PI*(lowcut-n)/(lowcut-highcut))); + *lfe_mag = n < lowcut ? 1.f : .5f*(1.f+cosf(M_PI*(lowcut-n)/(lowcut-highcut))); *lfe_mag *= c_mag; if (lfe_mode) *mag_total -= *lfe_mag; @@ -777,8 +781,8 @@ static void filter_stereo(AVFilterContext *ctx) mag_sum = mag_sum < MIN_MAG_SUM ? 1.f : mag_sum; mag_dif = (l_mag - r_mag) / mag_sum; - if (phase_dif > (float)M_PI) - phase_dif = 2.f * (float)M_PI - phase_dif; + if (phase_dif > M_PI) + phase_dif = 2.f * M_PI - phase_dif; stereo_position(mag_dif, phase_dif, &x, &y); angle_transform(&x, &y, angle); @@ -832,8 +836,8 @@ static void filter_2_1(AVFilterContext *ctx) mag_sum = mag_sum < MIN_MAG_SUM ? 1.f : mag_sum; mag_dif = (l_mag - r_mag) / mag_sum; - if (phase_dif > (float)M_PI) - phase_dif = 2.f * (float)M_PI - phase_dif; + if (phase_dif > M_PI) + phase_dif = 2.f * M_PI - phase_dif; stereo_position(mag_dif, phase_dif, &x, &y); angle_transform(&x, &y, angle); @@ -889,8 +893,8 @@ static void filter_surround(AVFilterContext *ctx) mag_sum = mag_sum < MIN_MAG_SUM ? 1.f : mag_sum; mag_dif = (l_mag - r_mag) / mag_sum; - if (phase_dif > (float)M_PI) - phase_dif = 2.f * (float)M_PI - phase_dif; + if (phase_dif > M_PI) + phase_dif = 2.f * M_PI - phase_dif; stereo_position(mag_dif, phase_dif, &x, &y); angle_transform(&x, &y, angle); @@ -946,11 +950,11 @@ static void filter_5_0_side(AVFilterContext *ctx) float xl, yl; float xr, yr; - if (phase_difl > (float)M_PI) - phase_difl = 2.f * (float)M_PI - phase_difl; + if (phase_difl > M_PI) + phase_difl = 2.f * M_PI - phase_difl; - if (phase_difr > (float)M_PI) - phase_difr = 2.f * (float)M_PI - phase_difr; + if (phase_difr > M_PI) + phase_difr = 2.f * M_PI - phase_difr; stereo_position(mag_difl, phase_difl, &xl, &yl); stereo_position(mag_difr, phase_difr, &xr, &yr); @@ -1005,11 +1009,11 @@ static void filter_5_1_side(AVFilterContext *ctx) float xl, yl; float xr, yr; - if (phase_difl > (float)M_PI) - phase_difl = 2.f * (float)M_PI - phase_difl; + if (phase_difl > M_PI) + phase_difl = 2.f * M_PI - phase_difl; - if (phase_difr > (float)M_PI) - phase_difr = 2.f * (float)M_PI - phase_difr; + if (phase_difr > M_PI) + phase_difr = 2.f * M_PI - phase_difr; stereo_position(mag_difl, phase_difl, &xl, &yl); stereo_position(mag_difr, phase_difr, &xr, &yr); @@ -1064,11 +1068,11 @@ static void filter_5_1_back(AVFilterContext *ctx) float xl, yl; float xr, yr; - if (phase_difl > (float)M_PI) - phase_difl = 2.f * (float)M_PI - phase_difl; + if (phase_difl > M_PI) + phase_difl = 2.f * M_PI - phase_difl; - if (phase_difr > (float)M_PI) - phase_difr = 2.f * (float)M_PI - phase_difr; + if (phase_difr > M_PI) + phase_difr = 2.f * M_PI - phase_difr; stereo_position(mag_difl, phase_difl, &xl, &yl); stereo_position(mag_difr, phase_difr, &xr, &yr);