Add sndio sound driver

Signed-off-by: Claudio Matsuoka <cmatsuoka@gmail.com>
master
Claudio Matsuoka 14 years ago
parent 54f47fda9f
commit c712271732
  1. 10
      configure.ac
  2. 2
      src/Makefile
  3. 110
      src/drivers/sndio.c
  4. 4
      src/sound.c
  5. 114
      src/sound_sndio.c

@ -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)
AC_CHECK_HEADERS(sys/soundcard.h alsa/asoundlib.h sndio.h)
])
])
@ -35,6 +35,11 @@ elif test "${ac_cv_header_CoreAudio_CoreAudio_h}" = "yes"; then
DRIVERS="${DRIVERS} sound_coreaudio.o"
LIBS="${LIBS} -framework AudioToolbox -framework AudioUnit -framework CoreServices"
else
if test "${ac_cv_header_sndio_h}" = "yes"; then
AC_DEFINE(SOUND_SNDIO)
DRIVERS="${DRIVERS} sound_sndio.o"
LIBS="${LIBS} -lsndio"
fi
if test "${ac_cv_header_sys_soundcard_h}" = "yes"; then
AC_DEFINE(SOUND_OSS)
DRIVERS="${DRIVERS} sound_oss.o"
@ -42,8 +47,7 @@ else
if test "${ac_cv_header_alsa_asoundlib_h}" = "yes"; then
AC_DEFINE(SOUND_ALSA)
DRIVERS="${DRIVERS} sound_alsa.o"
AC_CHECK_LIB(asound,snd_pcm_open,,
AC_MSG_ERROR(Can't find libasound))
LIBS="${LIBS} -lasound"
fi
fi

@ -2,7 +2,7 @@
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_alsa.c sound_coreaudio.c sound_oss.c sound_sndio.c
SRC_PATH = src
SRC_OBJS += $(DRIVERS)

@ -1,110 +0,0 @@
/*
* Copyright (c) 2009 Thomas Pfaff <tpfaff@tp76.info>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include <sndio.h>
#include "driver.h"
#include "mixer.h"
#include "common.h"
static struct sio_hdl *hdl;
static int init (struct context_data *);
static void bufdump (struct context_data *, void *, int);
static void shutdown (struct context_data *);
static void dummy (void);
struct xmp_drv_info drv_sndio = {
"sndio", /* driver ID */
"OpenBSD sndio", /* driver description */
NULL, /* help */
init, /* init */
shutdown, /* shutdown */
dummy, /* starttimer */
dummy, /* stoptimer */
bufdump, /* bufdump */
};
static void
dummy (void)
{
}
static int
init (struct context_data *ctx)
{
struct sio_par par, askpar;
struct xmp_options *opt = &ctx->o;
hdl = sio_open (NULL, SIO_PLAY, 0);
if (hdl == NULL) {
fprintf (stderr, "%s: failed to open audio device\n",
__func__);
return XMP_ERR_DINIT;
}
sio_initpar (&par);
par.pchan = opt->outfmt & XMP_FORMAT_MONO ? 1 : 2;
par.rate = opt->freq;
par.bits = opt->resol;
par.sig = opt->resol > 8 ? 1 : 0;
par.le = SIO_LE_NATIVE;
par.appbufsz = par.rate / 4;
askpar = par;
if (!sio_setpar (hdl, &par) || !sio_getpar (hdl, &par)) {
fprintf (stderr, "%s: failed to set parameters\n", __func__);
goto error;
}
if ((par.bits == 16 && par.le != askpar.le) ||
par.bits != askpar.bits ||
par.sig != askpar.sig ||
par.pchan != askpar.pchan ||
((par.rate * 1000 < askpar.rate * 995) ||
(par.rate * 1000 > askpar.rate * 1005))) {
fprintf (stderr, "%s: parameters not supported\n", __func__);
goto error;
}
if (!sio_start (hdl)) {
fprintf (stderr, "%s: failed to start audio device\n",
__func__);
goto error;
}
return 0;
error:
sio_close (hdl);
return XMP_ERR_DINIT;
}
static void
bufdump (struct context_data *ctx, void *b, int len)
{
if (b != NULL)
sio_write (hdl, buf, len);
}
static void
shutdown (struct context_data *ctx)
{
sio_close (hdl);
hdl = NULL;
}

@ -6,6 +6,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_sndio;
LIST_HEAD(sound_driver_list);
@ -16,6 +17,9 @@ static void register_sound_driver(struct sound_driver *sd)
void init_sound_drivers()
{
#ifdef SOUND_SNDIO
register_sound_driver(&sound_sndio);
#endif
#ifdef SOUND_COREAUDIO
register_sound_driver(&sound_coreaudio);
#endif

@ -0,0 +1,114 @@
/*
* Copyright (c) 2009 Thomas Pfaff <tpfaff@tp76.info>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <stdlib.h>
#include <string.h>
#include <sndio.h>
#include "sound.h"
static struct sio_hdl *hdl;
static int init(int *rate, int *format)
{
struct sio_par par, askpar;
struct xmp_options *opt = &ctx->o;
hdl = sio_open(NULL, SIO_PLAY, 0);
if (hdl == NULL) {
fprintf(stderr, "%s: failed to open audio device\n", __func__);
return -1;
}
sio_initpar(&par);
par.pchan = *format & XMP_FORMAT_MONO ? 1 : 2;
par.rate = *rate;
par.le = SIO_LE_NATIVE;
par.appbufsz = par.rate / 4;
if (*format & XMP_FORMAT_8BIT) {
par.bits = 8;
par.sig = 0;
*format |= XMP_FORMAT_UNSIGNED;
} else {
par.bits = 16;
par.sig = 1;
*format &= ~XMP_FORMAT_UNSIGNED;
}
askpar = par;
if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) {
fprintf(stderr, "%s: failed to set parameters\n", __func__);
goto error;
}
if ((par.bits == 16 && par.le != askpar.le) ||
par.bits != askpar.bits ||
par.sig != askpar.sig ||
par.pchan != askpar.pchan ||
((par.rate * 1000 < askpar.rate * 995) ||
(par.rate * 1000 > askpar.rate * 1005))) {
fprintf(stderr, "%s: parameters not supported\n", __func__);
goto error;
}
if (!sio_start(hdl)) {
fprintf(stderr, "%s: failed to start audio device\n", __func__);
goto error;
}
return 0;
error:
sio_close(hdl);
return -1;
}
static void deinit()
{
sio_close(hdl);
hdl = NULL;
}
static void play(void *b, int len)
{
if (b != NULL) {
sio_write(hdl, buf, len);
}
}
static void flush()
{
}
static void onpause()
{
}
static void onresume()
{
}
struct sound_driver sound_sndio = {
"sndio",
"OpenBSD sndio",
NULL,
init,
deint,
play,
flush,
onpause,
onresume
};
Loading…
Cancel
Save