summaryrefslogtreecommitdiff
path: root/audio/cava/files/patch-sndio
diff options
context:
space:
mode:
Diffstat (limited to 'audio/cava/files/patch-sndio')
-rw-r--r--audio/cava/files/patch-sndio176
1 files changed, 176 insertions, 0 deletions
diff --git a/audio/cava/files/patch-sndio b/audio/cava/files/patch-sndio
new file mode 100644
index 000000000000..47fff0abd39e
--- /dev/null
+++ b/audio/cava/files/patch-sndio
@@ -0,0 +1,176 @@
+https://github.com/karlstav/cava/commit/76fa7c132da25f5499a0f1b5dc4b416a34dad737
+
+diff --git a/cava.c b/cava.c
+index 76197cd..64dff25 100644
+--- cava.c
++++ cava.c
+@@ -53,6 +53,10 @@
+ #include "input/pulse.c"
+ #endif
+
++#ifdef SNDIO
++#include "input/sndio.c"
++#endif
++
+ #include <iniparser.h>
+
+ #include "config.h"
+@@ -287,6 +291,9 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
+ #ifdef PULSE
+ strcat(supportedInput,", 'pulse'");
+ #endif
++ #ifdef SNDIO
++ strcat(supportedInput,", 'sndio'");
++ #endif
+
+ //fft: planning to rock
+ fftw_complex outl[M / 2 + 1][2];
+@@ -388,6 +395,13 @@ as of 0.4.0 all options are specified in config file, see in '/home/username/.co
+ }
+ #endif
+
++ #ifdef SNDIO
++ if (p.im == 4) {
++ thr_id = pthread_create(&p_thread, NULL, input_sndio, (void*)&audio);
++ audio.rate = 44100;
++ }
++ #endif
++
+ if (p.highcf > audio.rate / 2) {
+ cleanup();
+ fprintf(stderr,
+diff --git a/config.c b/config.c
+index 1da11cd..9f8465e 100644
+--- config.c
++++ config.c
+@@ -87,6 +87,13 @@ if (strcmp(inputMethod, "pulse") == 0) {
+ #endif
+
+ }
++if (strcmp(inputMethod, "sndio") == 0) {
++ p->im = 4;
++ #ifndef SNDIO
++ fprintf(stderr, "cava was built without sndio support\n");
++ exit(EXIT_FAILURE);
++ #endif
++}
+ if (p->im == 0) {
+ fprintf(stderr,
+ "input method '%s' is not supported, supported methods are: %s\n",
+@@ -325,6 +332,10 @@ inputMethod = (char *)iniparser_getstring(ini, "input:method", "fifo");
+ inputMethod = (char *)iniparser_getstring(ini, "input:method", "pulse");
+ #endif
+
++//setting sndio to defaualt if supported
++#ifdef SNDIO
++ inputMethod = (char *)iniparser_getstring(ini, "input:method", "sndio");
++#endif
+
+ #ifdef NCURSES
+ outputMethod = (char *)iniparser_getstring(ini, "output:method", "ncurses");
+@@ -402,6 +413,12 @@ if (strcmp(inputMethod, "pulse") == 0) {
+ p->im = 3;
+ p->audio_source = (char *)iniparser_getstring(ini, "input:source", "auto");
+ }
++#ifdef SNDIO
++if (strcmp(inputMethod, "sndio") == 0) {
++ p->im = 4;
++ p->audio_source = (char *)iniparser_getstring(ini, "input:source", SIO_DEVANY);
++}
++#endif
+
+ validate_config(supportedInput, params);
+ //iniparser_freedict(ini);
+diff --git a/configure.ac b/configure.ac
+index 6e3c291..92fa281 100644
+--- configure.ac
++++ configure.ac
+@@ -64,6 +64,19 @@ AC_CHECK_LIB(pulse-simple, pa_simple_new, have_pulse=yes, have_pulse=no)
+ AC_MSG_NOTICE([WARNING: No pusleaudio dev files found building without pulseaudio support])
+ fi
+
++dnl ######################
++dnl checking for sndio dev
++dnl ######################
++AC_CHECK_LIB(sndio, sio_open, have_sndio=yes, have_sndio=no)
++ if [[ $have_sndio = "yes" ]] ; then
++ LIBS="$LIBS -lsndio"
++ CPPFLAGS="$CPPFLAGS -DSNDIO"
++ fi
++
++ if [[ $have_sndio = "no" ]] ; then
++ AC_MSG_NOTICE([WARNING: No sndio dev files found building without sndio support])
++ fi
++
+ dnl ######################
+ dnl checking for math lib
+ dnl ######################
+diff --git a/input/sndio.c b/input/sndio.c
+new file mode 100644
+index 0000000..6142225
+--- /dev/null
++++ input/sndio.c
+@@ -0,0 +1,63 @@
++#include <assert.h>
++#include <errno.h>
++#include <sndio.h>
++#include <string.h>
++
++void* input_sndio(void* data)
++{
++ struct audio_data *audio = (struct audio_data *)data;
++ struct sio_par par;
++ struct sio_hdl *hdl;
++ int16_t buf[256];
++ unsigned int i, n, channels;
++
++ assert(audio->channels > 0);
++ channels = audio->channels;
++
++ sio_initpar(&par);
++ par.sig = 1;
++ par.bits = 16;
++ par.le = 1;
++ par.rate = 44100;
++ par.rchan = channels;
++ par.appbufsz = sizeof(buf) / channels;
++
++ if ((hdl = sio_open(audio->source, SIO_REC, 0)) == NULL) {
++ fprintf(stderr, __FILE__": Could not open sndio source: %s\n", audio->source);
++ exit(EXIT_FAILURE);
++ }
++
++ if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) || par.sig != 1 || par.le != 1 || par.rate != 44100 || par.rchan != channels) {
++ fprintf(stderr, __FILE__": Could not set required audio parameters\n");
++ exit(EXIT_FAILURE);
++ }
++
++ if (!sio_start(hdl)) {
++ fprintf(stderr, __FILE__": sio_start() failed\n");
++ exit(EXIT_FAILURE);
++ }
++
++ n = 0;
++ while (audio->terminate != 1) {
++ if (sio_read(hdl, buf, sizeof(buf)) == 0) {
++ fprintf(stderr, __FILE__": sio_read() failed: %s\n", strerror(errno));
++ exit(EXIT_FAILURE);
++ }
++
++ for (i = 0; i < sizeof(buf)/sizeof(buf[0]); i += 2) {
++ if (par.rchan == 1) {
++ // sndiod has already taken care of averaging the samples
++ audio->audio_out_l[n] = buf[i];
++ } else if (par.rchan == 2) {
++ audio->audio_out_l[n] = buf[i];
++ audio->audio_out_r[n] = buf[i + 1];
++ }
++ n = (n + 1) % 2048;
++ }
++ }
++
++ sio_stop(hdl);
++ sio_close(hdl);
++
++ return 0;
++}