Recently Written · git

sad

sad (2f30.org simple audio daemon) with a Cygwin/OSS port on branch cygwin

git clone https://github.com/equwal/sad

Log | Files | Refs


commit a0ac7e311c5533c7cfa3fea010674dad41debd17
Spenser Truex <truex@equwal.com>
2021-01-21 06:11:15 -0800

Use #define macros to simplify configuration

The idea is to remove any need for duplicating user effort in
configuring. So if you want to enable a different sound card, for
example, you only change SOUNDSYS and not three hardcoded booleans.

 config.def.h | 39 +++++++++++++++++++++++++++++++++------
 sad.h        |  5 +++++
 2 files changed, 38 insertions(+), 6 deletions(-)
diff --git a/config.def.h b/config.def.h
index 7916f63..583d3d0 100644
--- a/config.def.h
+++ b/config.def.h
@@ -1,16 +1,43 @@
 #define RESAMPLEQUALITY SOXR_QQ
+#define BITRATE 48000
+#define BITDEPTH 16
+#define CHANNELS 2
+#define SOUNDSYS ALSA
+
+
+/*
+   Only need to edit below this line if you have multiple sound backends.
+*/
+
+#if SOUNDSYS == SNDIO
+#define SNDIOON 1
+#else
+#define SNDIOON 0
+#endif
+#if SOUNDSYS == ALSA
+#define ALSAON 1
+#else
+#define ALSAON 0
+#endif
+#if SOUNDSYS == FIFO
+#define FIFOON 1
+#else
+#define FIFOON 0
+#endif
+
 
 Outputcfg outputcfgs[] = {
     {.name = "sndio",
-     .fmt = {.bits = 16, .rate = 48000, .channels = 2},
-     .enabled = 0,
+     .fmt = {.bits = BITDEPTH, .rate = BITRATE, .channels = CHANNELS},
+     .enabled = SNDIOON,
      .output = &sndiooutput},
     {.name = "alsa",
-     .fmt = {.bits = 16, .rate = 48000, .channels = 2},
-     .enabled = 1,
+     .fmt = {.bits = BITDEPTH, .rate = BITRATE, .channels = CHANNELS},
+     .enabled = ALSAON,
      .output = &alsaoutput},
     {.name = "fifo",
-     .fmt = {.bits = 16, .rate = 48000, .channels = 2},
-     .enabled = 0,
+     .fmt = {.bits = BITDEPTH, .rate = BITRATE, .channels = CHANNELS},
+     .enabled = FIFOON,
      .output = &fifooutput},
 };
+
diff --git a/sad.h b/sad.h
index a58c1f3..65600d4 100644
--- a/sad.h
+++ b/sad.h
@@ -6,6 +6,10 @@
 #define PROTOCOLVERSION "0.0"
 #define DEFAULTVOL 100
 
+//Magic number flags to enable with.
+#define SNDIO 0
+#define ALSA 1
+#define FIFO 2
 typedef struct {
   char *name;
   void (*fn)(int, char *);
@@ -136,3 +140,4 @@ void s16monotostereo(short *, short *, size_t);
 void s16stereotomono(short *, short *, size_t);
 void s16tofloat(short *, float *, size_t);
 void floattos16(float *, short *, size_t);
+