diff --git a/configure.ac b/configure.ac index 02f7905..1c6a5b8 100644 --- a/configure.ac +++ b/configure.ac @@ -15,7 +15,7 @@ fi AC_CHECK_HEADERS(xmp.h getopt.h signal.h termios.h) AC_CHECK_HEADER(windows.h,,[ AC_CHECK_HEADER(CoreAudio/CoreAudio.h,,[ - AC_CHECK_HEADERS(sys/soundcard.h alsa/asoundlib.h sndio.h) + AC_CHECK_HEADERS(sys/soundcard.h alsa/asoundlib.h sndio.h sys/audioio.h) ]) ]) @@ -40,6 +40,10 @@ else DRIVERS="${DRIVERS} sound_sndio.o" LIBS="${LIBS} -lsndio" fi + if test "${ac_cv_header_sys_audioio_h}" = "yes"; then + AC_DEFINE(SOUND_BSD) + DRIVERS="${DRIVERS} sound_bsd.o" + fi if test "${ac_cv_header_sys_soundcard_h}" = "yes"; then AC_DEFINE(SOUND_OSS) DRIVERS="${DRIVERS} sound_oss.o" diff --git a/src/Makefile b/src/Makefile index c24c0f1..3b6b2bd 100644 --- a/src/Makefile +++ b/src/Makefile @@ -2,7 +2,8 @@ SRC_OBJS = sound.o sound_null.o terminal.o info.o commands.o \ options.o getopt.o getopt1.o main.o SRC_DFILES = Makefile xmp.1 $(SRC_OBJS:.o=.c) common.h getopt.h \ - sound_alsa.c sound_coreaudio.c sound_oss.c sound_sndio.c + sound_alsa.c sound_coreaudio.c sound_oss.c sound_sndio.c \ + sound_bsd.c SRC_PATH = src SRC_OBJS += $(DRIVERS) diff --git a/src/sound.c b/src/sound.c index 1651f2f..75c2a27 100644 --- a/src/sound.c +++ b/src/sound.c @@ -7,6 +7,7 @@ extern struct sound_driver sound_alsa; extern struct sound_driver sound_win32; extern struct sound_driver sound_coreaudio; extern struct sound_driver sound_sndio; +extern struct sound_driver sound_bsd; LIST_HEAD(sound_driver_list); @@ -20,6 +21,9 @@ void init_sound_drivers() #ifdef SOUND_SNDIO register_sound_driver(&sound_sndio); #endif +#ifdef SOUND_BSD + register_sound_driver(&sound_bsd); +#endif #ifdef SOUND_COREAUDIO register_sound_driver(&sound_coreaudio); #endif diff --git a/src/drivers/bsd.c b/src/sound_bsd.c similarity index 52% rename from src/drivers/bsd.c rename to src/sound_bsd.c index 5d49f13..6f815aa 100644 --- a/src/drivers/bsd.c +++ b/src/sound_bsd.c @@ -6,10 +6,6 @@ * for more information. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include #include @@ -21,39 +17,15 @@ #include #include -#include "common.h" -#include "driver.h" -#include "mixer.h" - static int audio_fd; -static int init(struct context_data *); -static int setaudio(struct xmp_option *); -static void bufdump(struct context_data *, void *, int); -static void shutdown(struct context_data *); - -static void dummy() -{ -} - static char *help[] = { "gain=val", "Audio output gain (0 to 255)", "buffer=val", "Audio buffer size (default is 32768)", NULL }; -struct xmp_drv_info drv_bsd = { - "bsd", /* driver ID */ - "BSD PCM audio", /* driver description */ - help, /* help */ - init, /* init */ - shutdown, /* shutdown */ - dummy, /* starttimer */ - dummy, /* flush */ - bufdump, /* bufdump */ -}; - -static int setaudio(struct xmp_options *o) +static int init(int *rate, int *format) { audio_info_t ainfo; int gain = 128; @@ -70,41 +42,37 @@ static int setaudio(struct xmp_options *o) if (gain > AUDIO_MAX_GAIN) gain = AUDIO_MAX_GAIN; + if ((audio_fd = open("/dev/sound", O_WRONLY)) == -1) + return -1; + AUDIO_INITINFO(&ainfo); - ainfo.play.sample_rate = o->freq; - ainfo.play.channels = o->outfmt & XMP_FORMAT_MONO ? 1 : 2; - ainfo.play.precision = o->resol; - ainfo.play.encoding = o->resol > 8 ? - AUDIO_ENCODING_SLINEAR : AUDIO_ENCODING_ULINEAR; + ainfo.play.sample_rate = *rate; + ainfo.play.channels = *format & XMP_FORMAT_MONO ? 1 : 2; ainfo.play.gain = gain; ainfo.play.buffer_size = bsize; + if (*format & XMP_FORMAT_8BIT) { + ainfo.play.precision = 8; + ainfo.play.encoding = AUDIO_ENCODING_ULINEAR; + *format |= XMP_FORMAT_UNSIGNED; + } else { + ainfo.play.precision = 16; + ainfo.play.encoding = AUDIO_ENCODING_SLINEAR; + *format &= ~XMP_FORMAT_UNSIGNED; + } + if (ioctl(audio_fd, AUDIO_SETINFO, &ainfo) == -1) { close(audio_fd); - return XMP_ERR_DINIT; + return -1; } - - drv_bsd.description = "BSD PCM audio"; - - return 0; -} - -static int init(struct context_data *ctx) -{ - if ((audio_fd = open("/dev/sound", O_WRONLY)) == -1) - return XMP_ERR_DINIT; - if (setaudio(o) != 0) - return XMP_ERR_DINIT; + return -1; return 0; } -/* Build and write one tick (one PAL frame or 1/50 s in standard vblank - * timed mods) of audio data to the output device. - */ -static void bufdump(struct context_data *ctx, void *b, int i) +static void play(void *b, int i) { int j; @@ -117,7 +85,31 @@ static void bufdump(struct context_data *ctx, void *b, int i) }; } -static void shutdown(struct context_data *ctx) +static void deinit() { close(audio_fd); } + +static void flush() +{ +} + +static void onpause() +{ +} + +static void onresume() +{ +} + +struct sound_driver sound_bsd = { + "bsd", + "BSD PCM audio", + help, + init, + deinit, + play, + flush, + onpause, + onresume +};