From e2a6f21259925902b9dc78fa05cd98f41c5e1359 Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Fri, 30 Mar 2012 07:49:54 -0300 Subject: [PATCH] [xmp] Add HP-UX driver Signed-off-by: Claudio Matsuoka --- configure.ac | 7 ++ src/sound.c | 4 + src/{drivers/hpux.c => sound_hpux.c} | 138 +++++++++++++-------------- 3 files changed, 79 insertions(+), 70 deletions(-) rename src/{drivers/hpux.c => sound_hpux.c} (58%) diff --git a/configure.ac b/configure.ac index f0874d4..3507713 100644 --- a/configure.ac +++ b/configure.ac @@ -92,6 +92,13 @@ solaris*) DRIVERS="${DRIVERS} sound_solaris.o" fi ;; +hpux*) + AC_CHECK_HEADER(sys/audio.h) + if test "${ac_cv_header_sys_audio_h}" = "yes"; then + AC_DEFINE(DRIVER_HPUX) + DRIVERS="${DRIVERS} sound_hpux.o" + fi + ;; cygwin*|mingw*) AC_DEFINE(SOUND_WIN32) DRIVERS="${DRIVERS} sound_win32.o" diff --git a/src/sound.c b/src/sound.c index dd5efef..61e0886 100644 --- a/src/sound.c +++ b/src/sound.c @@ -7,6 +7,7 @@ extern struct sound_driver sound_oss; extern struct sound_driver sound_alsa; extern struct sound_driver sound_win32; extern struct sound_driver sound_coreaudio; +extern struct sound_driver sound_hpux; extern struct sound_driver sound_sndio; extern struct sound_driver sound_solaris; extern struct sound_driver sound_netbsd; @@ -41,6 +42,9 @@ void init_sound_drivers() #ifdef SOUND_SOLARIS register_sound_driver(&sound_solaris); #endif +#ifdef SOUND_HPUX + register_sound_driver(&sound_hpux); +#endif #ifdef SOUND_COREAUDIO register_sound_driver(&sound_coreaudio); #endif diff --git a/src/drivers/hpux.c b/src/sound_hpux.c similarity index 58% rename from src/drivers/hpux.c rename to src/sound_hpux.c index 171a5a6..a9c7950 100644 --- a/src/drivers/hpux.c +++ b/src/sound_hpux.c @@ -10,71 +10,39 @@ * 16 bit mono output. */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include #include #include #include #include - -#include "common.h" -#include "driver.h" -#include "mixer.h" +#include "sound.h" static int audio_fd; -static int init(struct context_data *); -static int setaudio(struct xmp_options *); -static void bufdump(struct context_data *, void *, int); -static void shutdown(struct context_data *); - -static void dummy() -{ -} - /* Standard sampling rates */ static int srate[] = { 44100, 32000, 22050, 16000, 11025, 8000, 0 }; -static char *help[] = { - "gain=val", "Audio output gain (0 to 255)", - "port={s|h|l}", "Audio port (s[peaker], h[eadphones], l[ineout])", - "buffer=val", "Audio buffer size", - NULL -}; - -struct sound_driver sound_hpux = { - "hpux", /* driver ID */ - "HP-UX 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(struct options *options) { + char **parm = options->driver_parm; int flags; int gain = 128; int bsize = 32 * 1024; int port = AUDIO_OUT_SPEAKER; + int nch = options->format & XMP_FORMAT_MONO ? 1 : 2; struct audio_gains agains; struct audio_describe adescribe; - char *token, **parm; int i; - parm_init(); + parm_init(parm); chkparm1("gain", gain = strtoul(token, NULL, 0)); chkparm1("buffer", bsize = strtoul(token, NULL, 0)); chkparm1("port", port = (int)*token) - parm_end(); + parm_end(); switch (port) { case 'h': @@ -87,65 +55,63 @@ static int setaudio(struct xmp_options *o) port = AUDIO_OUT_SPEAKER; } + if ((audio_fd = open("/dev/audio", O_WRONLY)) == -1) + goto err; + if ((flags = fcntl(audio_fd, F_GETFL, 0)) < 0) - return XMP_ERR_DINIT; + goto err1; flags |= O_NDELAY; if ((flags = fcntl(audio_fd, F_SETFL, flags)) < 0) - return XMP_ERR_DINIT; + goto err1; - if (ioctl(audio_fd, AUDIO_SET_DATA_FORMAT, AUDIO_FORMAT_LINEAR16BIT) == - -1) - return XMP_ERR_DINIT; + options->format &= ~XMP_FORMAT_8BIT; + if (ioctl(audio_fd, AUDIO_SET_DATA_FORMAT, AUDIO_FORMAT_LINEAR16BIT) == -1) + goto err1; - if (ioctl(audio_fd, AUDIO_SET_CHANNELS, - o->outfmt & XMP_FORMAT_MONO ? 1 : 2) == -1) { - o->outfmt ^= XMP_FORMAT_MONO; + if (ioctl(audio_fd, AUDIO_SET_CHANNELS, nch) == -1) { + options->format ^= XMP_FORMAT_MONO; + nch = options->format & XMP_FORMAT_MONO ? 1 : 2; - if (ioctl(audio_fd, AUDIO_SET_CHANNELS, - o->outfmt & XMP_FORMAT_MONO ? 1 : 2) == -1) - return XMP_ERR_DINIT; + if (ioctl(audio_fd, AUDIO_SET_CHANNELS, nch) == -1) { + goto err1; + } } ioctl(audio_fd, AUDIO_SET_OUTPUT, port); - for (i = 0; ioctl(audio_fd, AUDIO_SET_SAMPLE_RATE, o->freq) == -1; i++) - if ((o->freq = srate[i]) == 0) - return XMP_ERR_DINIT; + for (i = 0; ; i++) { + if (ioctl(audio_fd, AUDIO_SET_SAMPLE_RATE, options->rate) == 0) + break; + + if ((options->rate = srate[i]) == 0) + goto err1; + } if (ioctl(audio_fd, AUDIO_DESCRIBE, &adescribe) == -1) - return XMP_ERR_DINIT; + goto err1; if (ioctl(audio_fd, AUDIO_GET_GAINS, &agains) == -1) - return XMP_ERR_DINIT; + goto err1; agains.transmit_gain = adescribe.min_transmit_gain + (adescribe.max_transmit_gain - adescribe.min_transmit_gain) * gain / 256; if (ioctl(audio_fd, AUDIO_SET_GAINS, &agains) == -1) - return XMP_ERR_DINIT; + goto err1; ioctl(audio_fd, AUDIO_SET_TXBUFSIZE, bsize); return 0; -} - -static int init(struct context_data *ctx) -{ - if ((audio_fd = open("/dev/audio", O_WRONLY)) == -1) - return XMP_ERR_DINIT; - if (setaudio(ctl) != 0) - return XMP_ERR_DINIT; - - return 0; + err1: + close(audio_fd); + err: + return -1; } -/* 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; @@ -158,7 +124,39 @@ 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() +{ +} + + +static char *help[] = { + "gain=val", "Audio output gain (0 to 255)", + "port={s|h|l}", "Audio port (s[peaker], h[eadphones], l[ineout])", + "buffer=val", "Audio buffer size", + NULL +}; + +struct sound_driver sound_hpux = { + "hpux", + "HP-UX PCM audio", + help, + init, + deinit, + play, + flush, + onpause, + onresume +};