Re: [hatari-devel] Removing SDL use for byte order checks / conversions |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/hatari-devel Archives
]
- To: hatari-devel@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [hatari-devel] Removing SDL use for byte order checks / conversions
- From: David Savinkoff <dsavnkff@xxxxxxxxx>
- Date: Tue, 4 Oct 2022 14:55:56 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telus.net; s=google; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date; bh=g9NRBgd33D5uUiKZjU2mJoyaRsnxU8yI8S5JYIBDXh0=; b=FT67GNO5zdfsiVLEwNc9LccXUBGrW3kB9je9UGpZ9Tu2B0aupBSpfDoj0SaxIqFfzj jTEarevW/XLYBj57yMad+y1lM2f9QUOdnde4dnVs7rqTEu+jlYUx0oBlZxTxW92gVj9l 5IRA8+NBvm5VfTsmsse+qP0iWJ7MrT/Pl69Of322CURWv+1PJTshS9jjVBeymIiXiCUa EWYbGt4EGZO0d137YZqAiQml5V1+nroOKgp4NHfUYdPo7QGUr0EZvbjI1XrpDBrMqq9u zCt4RDl3PX/HLQeBh1mDKlwBadY8noT0Jbegfmc3sAbDtQgCN5Ld8bcf9NOpfxO2AvNy zTeg==
Dear Sirs:
An unused M_PI define in src/falcon/dsp_core.c is the only M_PI in
Hatari that is not my fault.
I have come to the conclusion that the entirety of computer science
has had decades to find a way of representing pi and has failed.
Thus, the correct way of defining pi on a computer in C is as follows:
#define pi 3.14159265358979323846264338327950 /* use more digits if needed */
Note that pi is lower case because pi is fundamentally more important than
C convention.
Here are three patches to purge M_PI
On Mon, Oct 3, 2022 at 9:25 AM Christian Zietz <
czietz@xxxxxxx> wrote:
David Savinkoff schrieb:
> I think MSFT is trying to be a trouble maker here, so use the force.
It's always easy and convenient to blame Microsoft, I know. But -- as
Thomas already wrote -- M_PI is *not* part of math.h in ANSI C. You will
find that glibc's math.h does not define it unconditionally either:
https://github.com/bminor/glibc/blob/b7bd94068e55d5fa8681e2ab4802d31852ea404e/math/math.h#L1144
.... it's just that __USE_MISC or __USE_XOPEN is set somewhere else.
> I would conditionally define M_PI most accurately in a future-proof way.
.... and, therefore, this suggestion might be good solution.
Regards
Christian
--
Christian Zietz - CHZ-Soft - czietz@xxxxxxx
WWW: https://www.chzsoft.de/
New GnuPG-Key-ID: 0x8708B34C827B159E
diff -ur a/src/sound.c b/src/sound.c
--- a/src/sound.c 2022-09-30 14:19:06.000000000 -0700
+++ b/src/sound.c 2022-10-04 13:39:26.323978687 -0700
@@ -410,7 +410,7 @@
/**
* Get coefficients for different Fs (C10 is in ST only):
- * Wc = 2*M_PI*4895.1;
+ * Wc = 2*pi*4895.1;
* Fs = 44100;
* warp = Wc/tanf((Wc/2)/Fs);
* b = Wc/(warp+Wc);
diff -ur a/src/falcon/dsp_core.c b/src/falcon/dsp_core.c
--- a/src/falcon/dsp_core.c 2022-09-25 12:14:13.000000000 -0700
+++ b/src/falcon/dsp_core.c 2022-10-04 14:13:22.571914992 -0700
@@ -37,9 +37,7 @@
dsp_core_t dsp_core;
/*--- Defines ---*/
-#ifndef M_PI
-#define M_PI 3.141592653589793238462643383279502
-#endif
+#define pi 3.1415926535897932384626433832795028842
/*--- Functions prototypes ---*/
static void dsp_core_dsp2host(void);
diff -ur a/src/dmaSnd.c b/src/dmaSnd.c
--- a/src/dmaSnd.c 2022-10-01 12:31:17.000000000 -0700
+++ b/src/dmaSnd.c 2022-10-04 14:14:02.795913734 -0700
@@ -95,7 +95,6 @@
const char DmaSnd_fileid[] = "Hatari dmaSnd.c";
-#include <SDL_stdinc.h> /* Required for M_PI */
#include "main.h"
#include "audio.h"
#include "configuration.h"
@@ -1355,6 +1354,7 @@
lmc1992.coef[4] = lmc1992.treb_table[set_treb].b1 * lmc1992.bass_table[set_bass].b1;
}
+#define pi 3.1415926535897932384626433832795028842
/**
* Compute the first order bass shelf
@@ -1366,9 +1366,9 @@
/* g, fc, Fs must be positive real numbers > 0.0 */
if (g < 1.0)
- bass.a1 = a1 = (tanf(M_PI*fc/Fs) - g ) / (tanf(M_PI*fc/Fs) + g );
+ bass.a1 = a1 = (tanf(pi*fc/Fs) - g ) / (tanf(pi*fc/Fs) + g );
else
- bass.a1 = a1 = (tanf(M_PI*fc/Fs) - 1.0) / (tanf(M_PI*fc/Fs) + 1.0);
+ bass.a1 = a1 = (tanf(pi*fc/Fs) - 1.0) / (tanf(pi*fc/Fs) + 1.0);
bass.b0 = (1.0 + a1) * (g - 1.0) / 2.0 + 1.0;
bass.b1 = (1.0 + a1) * (g - 1.0) / 2.0 + a1;
@@ -1387,9 +1387,9 @@
/* g, fc, Fs must be positive real numbers > 0.0 */
if (g < 1.0)
- treb.a1 = a1 = (g*tanf(M_PI*fc/Fs) - 1.0) / (g*tanf(M_PI*fc/Fs) + 1.0);
+ treb.a1 = a1 = (g*tanf(pi*fc/Fs) - 1.0) / (g*tanf(pi*fc/Fs) + 1.0);
else
- treb.a1 = a1 = (tanf(M_PI*fc/Fs) - 1.0) / (tanf(M_PI*fc/Fs) + 1.0);
+ treb.a1 = a1 = (tanf(pi*fc/Fs) - 1.0) / (tanf(pi*fc/Fs) + 1.0);
treb.b0 = 1.0 + (1.0 - a1) * (g - 1.0) / 2.0;
treb.b1 = a1 + (a1 - 1.0) * (g - 1.0) / 2.0;