Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: James Almer <jamrial@gmail.com>
To: ffmpeg-devel@ffmpeg.org
Subject: [FFmpeg-devel] [PATCH] avfilter/af_surround: define M_PI and M_LN10 as a float values
Date: Thu, 11 May 2023 19:01:32 -0300
Message-ID: <20230511220132.15338-1-jamrial@gmail.com> (raw)

This is cleaner than the approach in d1ded7310a.

Signed-off-by: James Almer <jamrial@gmail.com>
---
 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);
-- 
2.40.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".

                 reply	other threads:[~2023-05-11 22:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230511220132.15338-1-jamrial@gmail.com \
    --to=jamrial@gmail.com \
    --cc=ffmpeg-devel@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
		ffmpegdev@gitmailbox.com
	public-inbox-index ffmpegdev

Example config snippet for mirrors.


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git