From 4a1eb3b492bccdfb1f2fe5c5e55cde91a9958864 Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Mon, 9 Apr 2012 13:34:42 -0300 Subject: [PATCH] [xmp] Add QNX drivers Signed-off-by: Claudio Matsuoka --- configure.ac | 15 ++++ src/Makefile | 2 +- src/sound.c | 8 ++ src/{drivers/alsa05.c => sound_alsa05.c} | 95 +++++++++-------------- src/{drivers/qnx.c => sound_qnx.c} | 97 ++++++++++-------------- 5 files changed, 101 insertions(+), 116 deletions(-) rename src/{drivers/alsa05.c => sound_alsa05.c} (79%) rename src/{drivers/qnx.c => sound_qnx.c} (54%) diff --git a/configure.ac b/configure.ac index 2623e46..3c38f0d 100644 --- a/configure.ac +++ b/configure.ac @@ -135,6 +135,21 @@ irix*) LIBS="${LIBS} -laudio" fi ;; +qnx*) + AC_CHECK_HEADERS(sys/audio.h) + if test "${ac_cv_header_sys_audio_h}" = "yes"; then + AC_DEFINE(DRIVER_QNX) + DRIVERS="${DRIVERS} sound_qnx.o" + fi + ;; +nto-qnx*) + AC_CHECK_HEADERS(sys/asoundlib.h) + if test "${ac_cv_header_sys_asoundlib_h}" = "yes"; then + AC_DEFINE(DRIVER_ALSA05) + DRIVERS="${DRIVERS} alsa05.o" + LIBS="${LIBS} -lasound" + fi + ;; cygwin*|mingw*) AC_DEFINE(SOUND_WIN32) DRIVERS="${DRIVERS} sound_win32.o" diff --git a/src/Makefile b/src/Makefile index 1362b97..00d7fd6 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_pulseaudio.c + sound_aix.c sound_pulseaudio.c sound_qnx.c sound_alsa05.c SRC_PATH = src SRC_OBJS += $(DRIVERS) diff --git a/src/sound.c b/src/sound.c index 70404f7..1a82e1e 100644 --- a/src/sound.c +++ b/src/sound.c @@ -5,6 +5,8 @@ extern struct sound_driver sound_null; extern struct sound_driver sound_wav; extern struct sound_driver sound_file; +extern struct sound_driver sound_qnx; +extern struct sound_driver sound_alsa05; extern struct sound_driver sound_oss; extern struct sound_driver sound_alsa; extern struct sound_driver sound_win32; @@ -68,6 +70,12 @@ void init_sound_drivers() #ifdef SOUND_ALSA register_sound_driver(&sound_alsa); #endif +#ifdef SOUND_ALSA05 + register_sound_driver(&sound_alsa05); +#endif +#ifdef SOUND_QNX + register_sound_driver(&sound_qnx); +#endif #ifdef SOUND_PULSEAUDIO register_sound_driver(&sound_pulseaudio); #endif diff --git a/src/drivers/alsa05.c b/src/sound_alsa05.c similarity index 79% rename from src/drivers/alsa05.c rename to src/sound_alsa05.c index a0c4dad..e683c2f 100644 --- a/src/drivers/alsa05.c +++ b/src/sound_alsa05.c @@ -1,10 +1,6 @@ /* ALSA 0.5 driver for xmp * Copyright (C) 2000 Tijs van Bakel and Rob Adamson * - * 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. - * * Fixed for ALSA 0.5 by Rob Adamson * Sat, 29 Apr 2000 17:10:46 +0100 (BST) */ @@ -20,10 +16,6 @@ /* Now uses specified options - Rob Adamson, 20 Mar 2000 */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include #include @@ -34,40 +26,10 @@ #include #include #include +#include "sound.h" -#include "driver.h" -#include "mixer.h" - -static int init (struct context_data *ctx); -static void dshutdown (struct context_data *); -static void bufdump (struct context_data *, void *, int); -static void bufwipe (void); -static void flush (void); - -static void dummy() -{ -} - -static char *help[] = { - "frag=num,size", "Set the number and size (bytes) of fragments", - "card ", "Select sound card to use", - NULL -}; - -struct sound_driver sound_alsa05 = { - "alsa05", /* driver ID */ - "ALSA 0.5 PCM audio", /* driver description */ - help, /* help */ - init, /* init */ - dshutdown, /* shutdown */ - dummy, /* starttimer */ - flush, /* stoptimer */ - bufdump, /* bufdump */ - NULL -}; static snd_pcm_t *pcm_handle; - static int frag_num = 4; static size_t frag_size = 4096; static char *mybuffer = NULL; @@ -88,27 +50,24 @@ static int prepare_driver(void) return 0; } -static int to_fmt(struct xmp_options *o) +static int to_fmt(struct options *options) { int fmt; - if (o->resol == 0) - return SND_PCM_SFMT_MU_LAW; - - if (o->resol == 8) { + if (options->format & XMP_FORMAT_8BIT) { fmt = SND_PCM_SFMT_U8 | SND_PCM_SFMT_S8; } else { fmt = SND_PCM_SFMT_S16_LE | SND_PCM_SFMT_S16_BE | SND_PCM_SFMT_U16_LE | SND_PCM_SFMT_U16_BE; - if (o->big_endian) { + if (is_big_endian()) { fmt &= SND_PCM_SFMT_S16_BE | SND_PCM_SFMT_U16_BE; } else { fmt &= SND_PCM_SFMT_S16_LE | SND_PCM_SFMT_U16_LE; } } - if (o->outfmt & XMP_FMT_UNS) { + if (options->format & XMP_FORMAT_UNSIGNED) { fmt &= SND_PCM_SFMT_U8|SND_PCM_SFMT_U16_LE|SND_PCM_SFMT_U16_BE; } else { fmt &= SND_PCM_SFMT_S8|SND_PCM_SFMT_S16_LE|SND_PCM_SFMT_S16_BE; @@ -117,17 +76,16 @@ static int to_fmt(struct xmp_options *o) return fmt; } -static int init(struct context_data *ctx) +static int init(struct options *options) { - struct xmp_options *o = &ctx->o; + char **parm = options->driver_parm; snd_pcm_channel_params_t params; snd_pcm_channel_setup_t setup; int card = 0; int dev = 0; int rc; - char *token, **parm; - parm_init(); + parm_init(parm); chkparm2("frag", "%d,%d", &frag_num, &frag_size); if (frag_num > 8) frag_num = 8; @@ -147,14 +105,14 @@ static int init(struct context_data *ctx) mybuffer_nextfree = mybuffer; } else { printf("Unable to allocate memory for mixer buffer\n"); - return XMP_ERR_DINIT; + return -1; } if ((rc = snd_pcm_open(&pcm_handle, card, dev, SND_PCM_OPEN_PLAYBACK)) < 0) { printf("Unable to initialize pcm device: %s\n", snd_strerror(rc)); - return XMP_ERR_DINIT; + return -1; } memset(¶ms, 0, sizeof(snd_pcm_channel_params_t)); @@ -175,13 +133,13 @@ static int init(struct context_data *ctx) params.format.interleave = 1; params.format.format = to_fmt(o); - params.format.rate = o->freq; + params.format.rate = options->rate; params.format.voices = (o->outfmt & XMP_FORMAT_MONO) ? 1 : 2; if ((rc = snd_pcm_plugin_params(pcm_handle, ¶ms)) < 0) { printf("Unable to set output parameters: %s\n", snd_strerror(rc)); - return XMP_ERR_DINIT; + return -1; } if (prepare_driver() < 0) @@ -193,16 +151,13 @@ static int init(struct context_data *ctx) if ((rc = snd_pcm_channel_setup(pcm_handle, &setup)) < 0) { printf("Unable to setup channel: %s\n", snd_strerror(rc)); - 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) { /* Note this assumes a fragment size of (frag_size) */ while (i > 0) { @@ -221,7 +176,7 @@ static void bufdump(struct context_data *ctx, void *b, int i) } } -static void dshutdown(struct context_data *ctx) +static void deinit() { snd_pcm_close(pcm_handle); free(mybuffer); @@ -232,3 +187,23 @@ static void flush() snd_pcm_plugin_flush(pcm_handle, SND_PCM_CHANNEL_PLAYBACK); prepare_driver(); } + + +static char *help[] = { + "frag=num,size", "Set the number and size (bytes) of fragments", + "card ", "Select sound card to use", + NULL +}; + +struct sound_driver sound_alsa05 = { + "alsa05", /* driver ID */ + "ALSA 0.5 PCM audio", /* driver description */ + help, /* help */ + init, /* init */ + dshutdown, /* shutdown */ + dummy, /* starttimer */ + flush, /* stoptimer */ + bufdump, /* bufdump */ + NULL +}; + diff --git a/src/drivers/qnx.c b/src/sound_qnx.c similarity index 54% rename from src/drivers/qnx.c rename to src/sound_qnx.c index ddb257c..be5f1e7 100644 --- a/src/drivers/qnx.c +++ b/src/sound_qnx.c @@ -1,77 +1,36 @@ -/* 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. - */ - /* * Based on the QNX4 port of nspmod by Mike Gorchak */ -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - #include #include -#include "common.h" -#include "driver.h" -#include "mixer.h" +#include "sound.h" static int fd_audio; -static int init(struct context_data *); -static void bufdump(struct context_data *, void *, int); -static void myshutdown(struct context_data *); -static void mysync(); - -static void dummy() -{ -} - -static char *help[] = { - "dev=", "Audio device name (default is /dev/dsp)", - "buffer=val", "Audio buffer size (default is 32768)", - NULL -}; - -struct sound_driver sound_qnx = { - "QNX", /* driver ID */ - "QNX PCM audio", /* driver description */ - NULL, /* help */ - init, /* init */ - myshutdown, /* shutdown */ - dummy, /* starttimer */ - dummy, /* flush */ - bufdump, /* bufdump */ -}; - -static int init(struct context_data *ctx) +static int init(struct options *options) { - struct xmp_options *o = &ctx->o; + char **parm = options->driver_parm; int rc, rate, bits, stereo, bsize; char *dev; - char *token, **parm; - parm_init(); + parm_init(parm); chkparm1("dev", dev = token); chkparm1("buffer", bsize = strtoul(token, NULL, 0)); parm_end(); - rate = o->freq; - bits = o->resol; + rate = options->rate; + bits = options->format & XMP_FORMAT_8BIT ? 8 : 16; stereo = 1; bufsize = 32 * 1024; fd_audio = open(dev, O_WRONLY); if (fd_audio < 0) { fprintf(stderr, "can't open audio device\n"); - return XMP_ERR_DINIT; + return -1; } - if (o->outfmt & XMP_FORMAT_MONO) + if (options->outfmt & XMP_FORMAT_MONO) stereo = 0; if (ioctl(fd_audio, SOUND_PCM_WRITE_BITS, &bits) < 0) { @@ -101,12 +60,12 @@ static int init(struct context_data *ctx) return 0; - error: + error: close(fd_audio); - return XMP_ERR_DINIT; + return -1; } -static void bufdump(struct context_data *ctx, void *b, int i) +static void play(void *b, int i) { int j; @@ -114,17 +73,45 @@ static void bufdump(struct context_data *ctx, void *b, int i) if ((j = write(fd_audio, b, i)) > 0) { i -= j; b += j; - } else + } else { break; + } } while (i); } -static void myshutdown(struct context_data *ctx) +static void deinit() { close(fd_audio); } -static void mysync() +static void flush() { ioctl(fd, SNDCTL_DSP_SYNC, NULL); } + +static void onpause() +{ +} + +static void onresume() +{ +} + + +static char *help[] = { + "dev=", "Audio device name (default is /dev/dsp)", + "buffer=val", "Audio buffer size (default is 32768)", + NULL +}; + +struct sound_driver sound_qnx = { + "QNX", + "QNX PCM audio", + help, + init, + deinit, + play, + flush, + onpause, + onresume +};