From 06f6a4881ccc5f86d36391ec7431af4d6be2795d Mon Sep 17 00:00:00 2001 From: Lucas Date: Thu, 14 May 2020 00:54:51 +0000 Subject: [PATCH] Run in Linux - Define Pi to avoid running into too many feature test macros - Define _DEFAULT_SOURCE if not in OpenBSD - Add a play target that works in Linux --- Makefile | 8 +++++++- lrand48_uniform.c | 5 +++++ main.c | 5 +++++ synth.c | 9 ++++++++- 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a3c78e0..6716d69 100644 --- a/Makefile +++ b/Makefile @@ -31,9 +31,15 @@ arngment: ${OBJ} ${OBJ}: ${HDR} -play: all +play: + @${MAKE} _play_$$(uname) + +_play_OpenBSD: all ./arngment ${ARNGMENT_ARGS} | aucat -e s16 -h raw -i - +_play_Linux: all + ./arngment ${ARNGMENT_ARGS} | aplay -f dat -t raw - + clean: rm -f arngment ${OBJ} ${P}-${V}.tgz diff --git a/lrand48_uniform.c b/lrand48_uniform.c index c52259e..6acb362 100644 --- a/lrand48_uniform.c +++ b/lrand48_uniform.c @@ -30,6 +30,11 @@ * . */ +/* lrand48, visibility for glibc */ +#if !defined(__OpenBSD__) +#define _DEFAULT_SOURCE +#endif + #include #include diff --git a/main.c b/main.c index 089c347..33639c7 100644 --- a/main.c +++ b/main.c @@ -13,6 +13,11 @@ * . */ +/* getopt, srand48, visibility for glibc */ +#if !defined(__OpenBSD__) +#define _DEFAULT_SOURCE +#endif + #include #include #include diff --git a/synth.c b/synth.c index e8f21fa..9d3bdc8 100644 --- a/synth.c +++ b/synth.c @@ -15,6 +15,13 @@ #include +/* + * Apparently, it's too hard for OSes to expose M_PI in a portable way. + * Definition taken from + * $OpenBSD: math.h,v 1.36 2018/03/10 20:52:58 kettenis Exp $ + */ +#define JUST_PI ((double)3.14159265358979323846) + #define CLAMP(x, a, b) ((x) < (a) ? (a) : (x) > (b) ? (b) : (x)) double @@ -27,7 +34,7 @@ synth_distortion(double gain, double x) double synth_sinewave(double t, double a) { - return sin(2.0 * M_PI * t * a); + return sin(2.0 * JUST_PI * t * a); } double