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
This commit is contained in:
Lucas 2020-05-14 00:54:51 +00:00
parent afbe512452
commit 06f6a4881c
4 changed files with 25 additions and 2 deletions

View File

@ -31,9 +31,15 @@ arngment: ${OBJ}
${OBJ}: ${HDR} ${OBJ}: ${HDR}
play: all play:
@${MAKE} _play_$$(uname)
_play_OpenBSD: all
./arngment ${ARNGMENT_ARGS} | aucat -e s16 -h raw -i - ./arngment ${ARNGMENT_ARGS} | aucat -e s16 -h raw -i -
_play_Linux: all
./arngment ${ARNGMENT_ARGS} | aplay -f dat -t raw -
clean: clean:
rm -f arngment ${OBJ} ${P}-${V}.tgz rm -f arngment ${OBJ} ${P}-${V}.tgz

View File

@ -30,6 +30,11 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>. * <http://creativecommons.org/publicdomain/zero/1.0/>.
*/ */
/* lrand48, visibility for glibc */
#if !defined(__OpenBSD__)
#define _DEFAULT_SOURCE
#endif
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>

5
main.c
View File

@ -13,6 +13,11 @@
* <http://creativecommons.org/publicdomain/zero/1.0/>. * <http://creativecommons.org/publicdomain/zero/1.0/>.
*/ */
/* getopt, srand48, visibility for glibc */
#if !defined(__OpenBSD__)
#define _DEFAULT_SOURCE
#endif
#include <limits.h> #include <limits.h>
#include <stdio.h> #include <stdio.h>
#include <stdint.h> #include <stdint.h>

View File

@ -15,6 +15,13 @@
#include <math.h> #include <math.h>
/*
* 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)) #define CLAMP(x, a, b) ((x) < (a) ? (a) : (x) > (b) ? (b) : (x))
double double
@ -27,7 +34,7 @@ synth_distortion(double gain, double x)
double double
synth_sinewave(double t, double a) synth_sinewave(double t, double a)
{ {
return sin(2.0 * M_PI * t * a); return sin(2.0 * JUST_PI * t * a);
} }
double double