[xmp] Add QNX drivers

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
master
Claudio Matsuoka 14 years ago
parent ab818582b9
commit 4a1eb3b492
  1. 15
      configure.ac
  2. 2
      src/Makefile
  3. 8
      src/sound.c
  4. 95
      src/sound_alsa05.c
  5. 97
      src/sound_qnx.c

@ -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"

@ -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)

@ -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

@ -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 <R.Adamson@fitz.cam.ac.uk>
* 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 <string.h>
#include <stdlib.h>
#include <stdio.h>
@ -34,40 +26,10 @@
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/asoundlib.h>
#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 <name>", "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(&params, 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, &params)) < 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 <name>", "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
};

@ -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 <malva@selena.kherson.ua>
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <sys/audio.h>
#include <sys/ioctl.h>
#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=<device_name>", "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=<device_name>", "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
};
Loading…
Cancel
Save