From 04ec9834d97aa0b3da6b3f9a46f6e2dcd2e6fc39 Mon Sep 17 00:00:00 2001 From: Ingo Feinerer Date: Tue, 30 Jul 2019 22:48:11 +0200 Subject: [PATCH] Add sndio sound back end --- configure.ac | 17 +++++- src/Makefile.am | 16 ++++-- src/sound.c | 5 ++ src/sound_sndio.c | 128 ++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 160 insertions(+), 6 deletions(-) create mode 100644 src/sound_sndio.c diff --git a/configure.ac b/configure.ac index 3e4840a8..e0459377 100644 --- a/configure.ac +++ b/configure.ac @@ -91,12 +91,12 @@ AM_CONDITIONAL(ENABLE_GNOME, test "x$enable_hints_gnome" = "xyes") AC_ARG_ENABLE(sound, AC_HELP_STRING([--enable-sound], - [compile with sound support (pulseaudio/esound/no)@<:@default=pulseaudio@:>@]),, + [compile with sound support (pulseaudio/esound/sndio/no)@<:@default=pulseaudio@:>@]),, enable_sound=pulseaudio) case x$enable_sound in xyes) enable_sound=pulseaudio;; -xpulseaudio|xesound) +xpulseaudio|xesound|xsndio) ;; *) enable_sound=no;; @@ -138,6 +138,19 @@ if test "x$enable_sound" = "xesound"; then fi AM_CONDITIONAL(USE_LIBESD, test "x$enable_sound" = "xesound") +if test "x$enable_sound" = "xsndio"; then + AC_CHECK_HEADERS(sndio.h,, enable_sound=no + AC_MSG_WARN([sndio sound support was requested but not found.])) + AC_CHECK_LIB(sndio, sio_open, SNDIO_LIBS="-lsndio", enable_sound=no) + AC_SUBST(SNDIO_LIBS) + if test "x$enable_sound" = "xsndio"; then + AC_DEFINE(HAVE_SOUND, 1, [Sound support]) + AC_DEFINE(HAVE_SOUND_SNDIO, 1, [Sndio sound support]) + enable_sound=sndio + fi +fi +AM_CONDITIONAL(USE_LIBSNDIO, test "x$enable_sound" = "xsndio") + if test "x$enable_sound" != "xno" -a "x$with_sndldr" = "xnone"; then AC_MSG_ERROR([Sound support requires a sound loader]) fi diff --git a/src/Makefile.am b/src/Makefile.am index 3be3f5a8..40534f96 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -172,7 +172,7 @@ MODULE_LIBS = $(DLOPEN_LIBS) libe16dir = $(pkglibdir) -libe16_LTLIBRARIES = $(LIBSND_ESD) $(LIBSND_PA) $(LIBFNT_IFT) $(LIBFNT_XFT) $(LIBFNT_PANGO) +libe16_LTLIBRARIES = $(LIBSND_ESD) $(LIBSND_PA) $(LIBSND_SNDIO) $(LIBFNT_IFT) $(LIBFNT_XFT) $(LIBFNT_PANGO) if USE_LIBESD LIBSND_ESD = libsound_esd.la @@ -190,6 +190,14 @@ libsound_pa_la_LIBADD = $(PA_LIBS) $(SNDLDR_LIBS) libsound_pa_la_LDFLAGS = -module -avoid-version endif +if USE_LIBSNDIO +LIBSND_SNDIO = libsound_sndio.la +libsound_sndio_la_SOURCES = sound_sndio.c sound_load.c +libsound_sndio_la_CFLAGS = $(SNDIO_CFLAGS) $(AUDIOFILE_CFLAGS) $(CWARNFLAGS) +libsound_sndio_la_LIBADD = $(SNDIO_LIBS) $(AUDIOFILE_LIBS) +libsound_sndio_la_LDFLAGS = -module -avoid-version +endif + LIBFNT_IFT = libfont_ift.la libfont_ift_la_SOURCES = ttfont.c libfont_ift_la_CFLAGS = $(IMLIB2_CFLAGS) @@ -214,9 +222,9 @@ endif else -MODULE_SRCS = sound_esd.c sound_pa.c sound_load.c ttfont.c text_xft.c text_pango.c -MODULE_LIBS = $(ESD_LIBS) $(PA_LIBS) $(SNDLDR_LIBS) $(PANGO_LIBS) $(XFT_LIBS) -MODULE_CFLAGS = $(ESD_CFLAGS) $(PA_CFLAGS) $(SNDLDR_CFLAGS) $(PANGO_CFLAGS) $(XFT_CFLAGS) +MODULE_SRCS = sound_esd.c sound_pa.c sound_sndio.c sound_load.c ttfont.c text_xft.c text_pango.c +MODULE_LIBS = $(ESD_LIBS) $(PA_LIBS) $(SNDIO_LIBS) $(SNDLDR_LIBS) $(PANGO_LIBS) $(XFT_LIBS) +MODULE_CFLAGS = $(ESD_CFLAGS) $(PA_CFLAGS) $(SNDIO_CFLAGS) $(SNDLDR_CFLAGS) $(PANGO_CFLAGS) $(XFT_CFLAGS) endif diff --git a/src/sound.c b/src/sound.c index 98cd4c95..b68aa5b3 100644 --- a/src/sound.c +++ b/src/sound.c @@ -34,6 +34,8 @@ #define SOUND_SERVER_NAME "esd" #elif HAVE_SOUND_PA #define SOUND_SERVER_NAME "pulseaudio" +#elif HAVE_SOUND_SNDIO +#define SOUND_SERVER_NAME "sndio" #else #error Invalid sound configuration #endif @@ -73,6 +75,9 @@ static const SoundOps *ops = &SoundOps_esd; #elif HAVE_SOUND_PA extern const SoundOps SoundOps_pa; static const SoundOps *ops = &SoundOps_pa; +#elif HAVE_SOUND_SNDIO +extern const SoundOps SoundOps_sndio; +static const SoundOps *ops = &SoundOps_sndio; #endif #endif diff --git a/src/sound_sndio.c b/src/sound_sndio.c new file mode 100644 index 00000000..2f557367 --- /dev/null +++ b/src/sound_sndio.c @@ -0,0 +1,128 @@ +/* + * Copyright (c) 2012 Jonathan Armani + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies of the Software, its documentation and marketing & publicity + * materials, and acknowledgment shall be given in the documentation, materials + * and software packages that this Software was used. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#include "E.h" +#if defined(HAVE_SOUND) && defined(HAVE_SOUND_SNDIO) +#include "sound.h" +#include + +#ifdef USE_MODULES +#define Estrdup strdup +#endif + +struct _sample { + SoundSampleData ssd; +}; + +static struct sio_hdl *hdl; + +static Sample * +_sound_sndio_Load(const char *file) +{ + Sample *s; + int err; + + if (hdl == NULL) + return NULL; + + s = ECALLOC(Sample, 1); + if (!s) + return NULL; + + err = SoundSampleGetData(file, &s->ssd); + if (err) + { + Efree(s); + return NULL; + } + + return s; +} + +static void +_sound_sndio_Destroy(Sample * s) +{ + if (!s) + return; + + EFREE_NULL(s->ssd.data); + Efree(s); +} + +static void +_sound_sndio_Play(Sample * s) +{ + struct sio_par params; + + if (hdl == NULL || !s) + return; + + sio_initpar(¶ms); + params.bits = s->ssd.bit_per_sample; + params.pchan = s->ssd.channels; + params.rate = s->ssd.rate; + + if (!sio_setpar(hdl, ¶ms)) + return; + if (!sio_getpar(hdl, ¶ms)) + return; + if (params.bits != s->ssd.bit_per_sample || + params.pchan != s->ssd.channels || params.rate != s->ssd.rate) + return; + + if (!sio_start(hdl)) + return; + + sio_write(hdl, s->ssd.data, s->ssd.size); + sio_stop(hdl); +} + +static int +_sound_sndio_Init(void) +{ + if (hdl != NULL) + return 0; + + hdl = sio_open(SIO_DEVANY, SIO_PLAY, 0); + + return (hdl == NULL); +} + +static void +_sound_sndio_Exit(void) +{ + if (hdl == NULL) + return; + + sio_close(hdl); + hdl = NULL; +} + +__EXPORT__ extern const SoundOps SoundOps_sndio; + +const SoundOps SoundOps_sndio = { + _sound_sndio_Init, _sound_sndio_Exit, _sound_sndio_Load, + _sound_sndio_Destroy, _sound_sndio_Play, +}; + +#endif /* HAVE_SOUND && HAVE_SOUND_SNDIO */