1
0
mirror of https://github.com/ericonr/sndio.git synced 2024-02-18 04:45:21 -06:00

add alsa rawmidi support

This commit is contained in:
Alexandre Ratchov 2012-10-26 14:30:48 +02:00
parent 9f6bcbbc0e
commit 80a52c9600
6 changed files with 64 additions and 11 deletions

26
configure vendored
View File

@ -13,10 +13,12 @@ Usage: configure [options]
--libdir=DIR install libraries in DIR [\$prefix/lib] --libdir=DIR install libraries in DIR [\$prefix/lib]
--mandir=DIR install man pages in DIR [\$prefix/man] --mandir=DIR install man pages in DIR [\$prefix/man]
--precision=NUMBER aucat/sndiod processing precision [$precision] --precision=NUMBER aucat/sndiod processing precision [$precision]
--enable-alsa enable alsa backend [$alsa] --enable-alsa enable alsa audio & midi backends [$alsa]
--disable-alsa disable alsa backend --disable-alsa disable alsa audio & midi backends
--enable-sun enable sun backend [$sun] --enable-sun enable sun audio backend [$sun]
--disable-sun disable sun backend --disable-sun disable sun audio backend
--enable-rmidi enable character device midi backend [$rmidi]
--disable-rmidi disable character device midi backend
END END
} }
@ -27,6 +29,7 @@ prefix=/usr/local # where to install sndio
so="libsndio.so.\${MAJ}.\${MIN}" # shared libs to build so="libsndio.so.\${MAJ}.\${MIN}" # shared libs to build
alsa=no # do we want alsa support ? alsa=no # do we want alsa support ?
sun=no # do we want sun support ? sun=no # do we want sun support ?
rmidi=no # do we want support for raw char dev ?
precision=16 # aucat/sndiod arithmetic precision precision=16 # aucat/sndiod arithmetic precision
unset vars # variables passed as arguments unset vars # variables passed as arguments
unset bindir # path where to install binaries unset bindir # path where to install binaries
@ -51,6 +54,7 @@ case `uname` in
;; ;;
OpenBSD) OpenBSD)
sun=yes sun=yes
rmidi=yes
defs='-DUSE_ARC4RANDOM' defs='-DUSE_ARC4RANDOM'
;; ;;
esac esac
@ -94,6 +98,12 @@ for i; do
--disable-sun) --disable-sun)
sun=no sun=no
shift;; shift;;
--enable-rmidi)
rmidi=yes
shift;;
--disable-rmidi)
rmidi=no
shift;;
--precision=*) --precision=*)
precision="${i#--precision=}" precision="${i#--precision=}"
if [ "$precision" != 16 -a "$precision" != 24 ]; then if [ "$precision" != 16 -a "$precision" != 24 ]; then
@ -135,6 +145,13 @@ if [ $sun = yes ]; then
defs="$defs -DUSE_SUN" defs="$defs -DUSE_SUN"
fi fi
#
# if using raw character devices for midi, add corresponding parameters
#
if [ $rmidi = yes ]; then
defs="$defs -DUSE_RMIDI"
fi
for makefile in Makefile aucat/Makefile sndiod/Makefile libsndio/Makefile examples/Makefile for makefile in Makefile aucat/Makefile sndiod/Makefile libsndio/Makefile examples/Makefile
do do
sed \ sed \
@ -160,6 +177,7 @@ echo "mandir................... $mandir"
echo "precision................ $precision" echo "precision................ $precision"
echo "alsa..................... $alsa" echo "alsa..................... $alsa"
echo "sun...................... $sun" echo "sun...................... $sun"
echo "rmidi.................... $rmidi"
echo echo
echo "Do \"make && make install\" to compile and install sndio" echo "Do \"make && make install\" to compile and install sndio"
echo echo

View File

@ -98,7 +98,8 @@ clean:
# loader to determine dependencies in a single pass # loader to determine dependencies in a single pass
# #
OBJS = debug.o aucat.o \ OBJS = debug.o aucat.o \
mio.o mio_rmidi.o mio_aucat.o sio.o sio_alsa.o sio_aucat.o sio_sun.o \ mio.o mio_rmidi.o mio_alsa.o mio_aucat.o \
sio.o sio_alsa.o sio_aucat.o sio_sun.o \
issetugid.o strlcat.o strlcpy.o strtonum.o issetugid.o strlcat.o strlcpy.o strtonum.o
.c.o: .c.o:
@ -130,12 +131,15 @@ aucat.o: aucat.c aucat.h amsg.h debug.h \
debug.o: debug.c debug.h ../bsd-compat/bsd-compat.h debug.o: debug.c debug.h ../bsd-compat/bsd-compat.h
mio.o: mio.c debug.h mio_priv.h sndio.h \ mio.o: mio.c debug.h mio_priv.h sndio.h \
../bsd-compat/bsd-compat.h ../bsd-compat/bsd-compat.h
mio_alsa.o: mio_alsa.c debug.h mio_priv.h sndio.h
mio_aucat.o: mio_aucat.c aucat.h amsg.h debug.h mio_priv.h sndio.h \ mio_aucat.o: mio_aucat.c aucat.h amsg.h debug.h mio_priv.h sndio.h \
../bsd-compat/bsd-compat.h ../bsd-compat/bsd-compat.h
mio_rmidi.o: mio_rmidi.c debug.h mio_priv.h sndio.h mio_rmidi.o: mio_rmidi.c debug.h mio_priv.h sndio.h
sio.o: sio.c debug.h sio_priv.h sndio.h \ sio.o: sio.c debug.h sio_priv.h sndio.h \
../bsd-compat/bsd-compat.h ../bsd-compat/bsd-compat.h
sio_alsa.o: sio_alsa.c debug.h sio_priv.h sndio.h sio_alsa.o: sio_alsa.c debug.h sio_priv.h sndio.h \
../bsd-compat/bsd-compat.h
sio_aucat.o: sio_aucat.c aucat.h amsg.h debug.h sio_priv.h sndio.h \ sio_aucat.o: sio_aucat.c aucat.h amsg.h debug.h sio_priv.h sndio.h \
../bsd-compat/bsd-compat.h ../bsd-compat/bsd-compat.h
sio_sun.o: sio_sun.c debug.h sio_priv.h sndio.h sio_sun.o: sio_sun.c debug.h sio_priv.h sndio.h \
../bsd-compat/bsd-compat.h

View File

@ -55,15 +55,28 @@ mio_open(const char *str, unsigned int mode, int nbio)
hdl = mio_aucat_open("/0", mode, nbio, 1); hdl = mio_aucat_open("/0", mode, nbio, 1);
if (hdl != NULL) if (hdl != NULL)
return hdl; return hdl;
#if defined(USE_RMIDI)
return mio_rmidi_open("/0", mode, nbio); return mio_rmidi_open("/0", mode, nbio);
#elif defined(USE_ALSA)
return mio_alsa_open("/0", mode, nbio);
#else
return NULL;
#endif
} }
if ((p = sndio_parsetype(str, "snd")) != NULL || if ((p = sndio_parsetype(str, "snd")) != NULL ||
(p = sndio_parsetype(str, "aucat")) != NULL) (p = sndio_parsetype(str, "aucat")) != NULL)
return mio_aucat_open(p, mode, nbio, 0); return mio_aucat_open(p, mode, nbio, 0);
if ((p = sndio_parsetype(str, "midithru")) != NULL) if ((p = sndio_parsetype(str, "midithru")) != NULL)
return mio_aucat_open(p, mode, nbio, 1); return mio_aucat_open(p, mode, nbio, 1);
if ((p = sndio_parsetype(str, "rmidi")) != NULL) #if defined(USE_RMIDI) || defined(USE_ALSA)
if ((p = sndio_parsetype(str, "rmidi")) != NULL) {
#if defined(USE_SUN)
return mio_rmidi_open(p, mode, nbio); return mio_rmidi_open(p, mode, nbio);
#elif defined(USE_ALSA)
return mio_alsa_open(p, mode, nbio);
#endif
}
#endif
DPRINTF("mio_open: %s: unknown device type\n", str); DPRINTF("mio_open: %s: unknown device type\n", str);
return NULL; return NULL;
} }
@ -193,7 +206,7 @@ mio_write(struct mio_hdl *hdl, const void *buf, size_t len)
int int
mio_nfds(struct mio_hdl *hdl) mio_nfds(struct mio_hdl *hdl)
{ {
return 1; return hdl->ops->nfds(hdl);
} }
int int

View File

@ -42,6 +42,7 @@ struct mio_aucat_hdl {
static void mio_aucat_close(struct mio_hdl *); static void mio_aucat_close(struct mio_hdl *);
static size_t mio_aucat_read(struct mio_hdl *, void *, size_t); static size_t mio_aucat_read(struct mio_hdl *, void *, size_t);
static size_t mio_aucat_write(struct mio_hdl *, const void *, size_t); static size_t mio_aucat_write(struct mio_hdl *, const void *, size_t);
static int mio_aucat_nfds(struct mio_hdl *);
static int mio_aucat_pollfd(struct mio_hdl *, struct pollfd *, int); static int mio_aucat_pollfd(struct mio_hdl *, struct pollfd *, int);
static int mio_aucat_revents(struct mio_hdl *, struct pollfd *); static int mio_aucat_revents(struct mio_hdl *, struct pollfd *);
@ -49,8 +50,9 @@ static struct mio_ops mio_aucat_ops = {
mio_aucat_close, mio_aucat_close,
mio_aucat_write, mio_aucat_write,
mio_aucat_read, mio_aucat_read,
mio_aucat_nfds,
mio_aucat_pollfd, mio_aucat_pollfd,
mio_aucat_revents, mio_aucat_revents
}; };
/* /*
@ -140,6 +142,12 @@ mio_aucat_write(struct mio_hdl *sh, const void *buf, size_t len)
return n; return n;
} }
static int
mio_aucat_nfds(struct mio_hdl *sh)
{
return 1;
}
static int static int
mio_aucat_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events) mio_aucat_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
{ {

View File

@ -39,11 +39,13 @@ struct mio_ops {
void (*close)(struct mio_hdl *); void (*close)(struct mio_hdl *);
size_t (*write)(struct mio_hdl *, const void *, size_t); size_t (*write)(struct mio_hdl *, const void *, size_t);
size_t (*read)(struct mio_hdl *, void *, size_t); size_t (*read)(struct mio_hdl *, void *, size_t);
int (*nfds)(struct mio_hdl *);
int (*pollfd)(struct mio_hdl *, struct pollfd *, int); int (*pollfd)(struct mio_hdl *, struct pollfd *, int);
int (*revents)(struct mio_hdl *, struct pollfd *); int (*revents)(struct mio_hdl *, struct pollfd *);
}; };
struct mio_hdl *mio_rmidi_open(const char *, unsigned, int); struct mio_hdl *mio_rmidi_open(const char *, unsigned, int);
struct mio_hdl *mio_alsa_open(const char *, unsigned, int);
struct mio_hdl *mio_aucat_open(const char *, unsigned, int, unsigned); struct mio_hdl *mio_aucat_open(const char *, unsigned, int, unsigned);
void mio_create(struct mio_hdl *, struct mio_ops *, unsigned, int); void mio_create(struct mio_hdl *, struct mio_ops *, unsigned, int);
void mio_destroy(struct mio_hdl *); void mio_destroy(struct mio_hdl *);

View File

@ -38,6 +38,7 @@ struct mio_rmidi_hdl {
static void mio_rmidi_close(struct mio_hdl *); static void mio_rmidi_close(struct mio_hdl *);
static size_t mio_rmidi_read(struct mio_hdl *, void *, size_t); static size_t mio_rmidi_read(struct mio_hdl *, void *, size_t);
static size_t mio_rmidi_write(struct mio_hdl *, const void *, size_t); static size_t mio_rmidi_write(struct mio_hdl *, const void *, size_t);
static int mio_rmidi_nfds(struct mio_hdl *);
static int mio_rmidi_pollfd(struct mio_hdl *, struct pollfd *, int); static int mio_rmidi_pollfd(struct mio_hdl *, struct pollfd *, int);
static int mio_rmidi_revents(struct mio_hdl *, struct pollfd *); static int mio_rmidi_revents(struct mio_hdl *, struct pollfd *);
@ -45,8 +46,9 @@ static struct mio_ops mio_rmidi_ops = {
mio_rmidi_close, mio_rmidi_close,
mio_rmidi_write, mio_rmidi_write,
mio_rmidi_read, mio_rmidi_read,
mio_rmidi_nfds,
mio_rmidi_pollfd, mio_rmidi_pollfd,
mio_rmidi_revents, mio_rmidi_revents
}; };
struct mio_hdl * struct mio_hdl *
@ -148,6 +150,12 @@ mio_rmidi_write(struct mio_hdl *sh, const void *buf, size_t len)
return n; return n;
} }
static int
mio_rmidi_nfds(struct mio_hdl *sh)
{
return 1;
}
static int static int
mio_rmidi_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events) mio_rmidi_pollfd(struct mio_hdl *sh, struct pollfd *pfd, int events)
{ {