diff --git a/configure.ac b/configure.ac index 284a97c..7d3aca7 100644 --- a/configure.ac +++ b/configure.ac @@ -2,7 +2,14 @@ dnl AC_CONFIG_AUX_DIR(./scripts) AC_INIT 0>confdefs.h -AC_ARG_WITH(libxmp, [ --with-libxmp= libxmp prefix (optional)], +AC_ARG_ENABLE(oss, + [ --disable-oss don't compile OSS support]) +AC_ARG_ENABLE(alsa, + [ --disable-alsa don't compile ALSA support]) +AC_ARG_ENABLE(pulseaudio, + [ --enable-pulseaudio compile PulseAudio support]) +AC_ARG_WITH(libxmp, + [ --with-libxmp= libxmp prefix (optional)], libxmp_path="$withval") AC_CANONICAL_HOST @@ -44,15 +51,30 @@ powerpc64) ;; esac -AC_CHECK_HEADERS(sys/soundcard.h machine/soundcard.h alsa/asoundlib.h sys/audioio.h) -if test "${ac_cv_header_sys_soundcard_h}" = "yes" -o "${ac_cv_header_machine_soundcard_h}" = "yes"; then - AC_DEFINE(SOUND_OSS) - DRIVERS="${DRIVERS} sound_oss.o" +AC_CHECK_HEADERS(sys/audioio.h) + +if test "${enable_oss}" != "no"; then + AC_CHECK_HEADER(sys/soundcard.h machine/soundcard.h) + if test "${ac_cv_header_sys_soundcard_h}" = "yes" -o "${ac_cv_header_machine_soundcard_h}" = "yes"; then + AC_DEFINE(SOUND_OSS) + DRIVERS="${DRIVERS} sound_oss.o" + fi fi -if test "${ac_cv_header_alsa_asoundlib_h}" = "yes"; then - AC_DEFINE(SOUND_ALSA) - DRIVERS="${DRIVERS} sound_alsa.o" - LIBS="${LIBS} -lasound" +if test "${enable_alsa}" != "no"; then + AC_CHECK_HEADER(alsa/asoundlib.h) + if test "${ac_cv_header_alsa_asoundlib_h}" = "yes"; then + AC_DEFINE(SOUND_ALSA) + DRIVERS="${DRIVERS} sound_alsa.o" + LIBS="${LIBS} -lasound" + fi +fi +if test "${enable_pulseaudio}" = "yes"; then + AC_CHECK_HEADER(pulse/simple.h) + if test "${ac_cv_header_pulse_simple_h}" = "yes"; then + AC_DEFINE(SOUND_PULSEAUDIO) + DRIVERS="${DRIVERS} pulseaudio.o" + LIBS="${LIBS} -lpulse-simple -lpulse" + fi fi case "${host_os}" in diff --git a/src/Makefile b/src/Makefile index 63d0ada..1362b97 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,7 +5,7 @@ SRC_DFILES = Makefile xmp.1 $(SRC_OBJS:.o=.c) common.h getopt.h list.h \ sound.h sound_alsa.c sound_coreaudio.c sound_oss.c \ sound_sndio.c sound_netbsd.c sound_bsd.c sound_solaris.c \ sound_beos.c sound_ahi.c sound_dart.c sound_hpux.c \ - sound_aix.c + sound_aix.c sound_pulseaudio.c SRC_PATH = src SRC_OBJS += $(DRIVERS) diff --git a/src/drivers/pulseaudio.c b/src/drivers/pulseaudio.c deleted file mode 100644 index 20e2a90..0000000 --- a/src/drivers/pulseaudio.c +++ /dev/null @@ -1,101 +0,0 @@ -/* Extended Module Player - * Copyright (C) 1996-2012 Claudio Matsuoka and Hipolito Carraro Jr - * - * This file is part of the Extended Module Player and is distributed - * under the terms of the GNU General Public License. See doc/COPYING - * for more information. - */ - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -#include -#include -#include - -#include "common.h" -#include "driver.h" -#include "mixer.h" - -static pa_simple *s; - -static int init(struct context_data *); -static void bufdump(struct context_data *, void *, int); -static void myshutdown(struct context_data *); -static void flush(); - -static void dummy() -{ -} - -struct sound_driver sound_pulseaudio = { - "pulseaudio", /* driver ID */ - "PulseAudio", /* driver description */ - NULL, /* help */ - init, /* init */ - myshutdown, /* shutdown */ - dummy, /* starttimer */ - flush, /* flush */ - bufdump, /* bufdump */ -}; - -static int init(struct context_data *ctx) -{ - struct xmp_options *o = &ctx->o; - pa_sample_spec ss; - int error; - - ss.format = PA_SAMPLE_S16NE; - ss.channels = o->outfmt & XMP_FORMAT_MONO ? 1 : 2; - ss.rate = o->freq; - - s = pa_simple_new(NULL, /* Use the default server */ - "xmp", /* Our application's name */ - PA_STREAM_PLAYBACK, - NULL, /* Use the default device */ - "Music", /* Description of our stream */ - &ss, /* Our sample format */ - NULL, /* Use default channel map */ - NULL, /* Use default buffering attributes */ - &error); /* Ignore error code */ - - if (s == 0) { - fprintf(stderr, "pulseaudio error: %s\n", pa_strerror(error)); - return XMP_ERR_DINIT; - } - - return 0; -} - -static void flush() -{ - int error; - - if (pa_simple_drain(s, &error) < 0) { - fprintf(stderr, "pulseaudio error: %s\n", pa_strerror(error)); - } -} - -static void bufdump(struct context_data *ctx, void *b, int i) -{ - int j, error; - - do { - if ((j = pa_simple_write(s, b, i, &error)) > 0) { - i -= j; - b += j; - } else - break; - } while (i); - - if (j < 0) { - fprintf(stderr, "pulseaudio error: %s\n", pa_strerror(error)); - } -} - -static void myshutdown(struct context_data *ctx) -{ - if (s) - pa_simple_free(s); -} diff --git a/src/sound.c b/src/sound.c index 4acf038..fa15f9e 100644 --- a/src/sound.c +++ b/src/sound.c @@ -7,6 +7,7 @@ extern struct sound_driver sound_file; extern struct sound_driver sound_oss; extern struct sound_driver sound_alsa; extern struct sound_driver sound_win32; +extern struct sound_driver sound_pulseaudio; extern struct sound_driver sound_coreaudio; extern struct sound_driver sound_hpux; extern struct sound_driver sound_sndio; @@ -65,6 +66,9 @@ void init_sound_drivers() #endif #ifdef SOUND_ALSA register_sound_driver(&sound_alsa); +#endif +#ifdef SOUND_PULSEAUDIO + register_sound_driver(&sound_pulseaudio); #endif register_sound_driver(&sound_wav); register_sound_driver(&sound_file); diff --git a/src/sound_pulseaudio.c b/src/sound_pulseaudio.c new file mode 100644 index 0000000..9f6f6f1 --- /dev/null +++ b/src/sound_pulseaudio.c @@ -0,0 +1,88 @@ +#include +#include +#include +#include "sound.h" + +static pa_simple *s; + + +static int init(struct options *options) +{ + pa_sample_spec ss; + int error; + + options->format &= ~(XMP_FORMAT_UNSIGNED | XMP_FORMAT_8BIT); + + ss.format = PA_SAMPLE_S16NE; + ss.channels = options->format & XMP_FORMAT_MONO ? 1 : 2; + ss.rate = options->rate; + + s = pa_simple_new(NULL, /* Use the default server */ + "xmp", /* Our application's name */ + PA_STREAM_PLAYBACK, + NULL, /* Use the default device */ + "Music", /* Description of our stream */ + &ss, /* Our sample format */ + NULL, /* Use default channel map */ + NULL, /* Use default buffering attributes */ + &error); /* Ignore error code */ + + if (s == NULL) { + fprintf(stderr, "pulseaudio error: %s\n", pa_strerror(error)); + return -1; + } + + return 0; +} + +static void play(void *b, int i) +{ + int j, error; + + do { + if ((j = pa_simple_write(s, b, i, &error)) > 0) { + i -= j; + b += j; + } else + break; + } while (i); + + if (j < 0) { + fprintf(stderr, "pulseaudio error: %s\n", pa_strerror(error)); + } +} + +static void deinit() +{ + pa_simple_free(s); +} + +static void flush() +{ + int error; + + if (pa_simple_drain(s, &error) < 0) { + fprintf(stderr, "pulseaudio error: %s\n", pa_strerror(error)); + } +} + +static void onpause() +{ +} + +static void onresume() +{ +} + + +struct sound_driver sound_pulseaudio = { + "pulseaudio", + "PulseAudio", + NULL, + init, + deinit, + play, + flush, + onpause, + onresume +};