From koen.deturck at gmail.com Mon May 28 04:30:28 2018 From: koen.deturck at gmail.com (Koen De Turck) Date: Mon, 28 May 2018 13:30:28 +0200 Subject: [CM] [Snd] Patch for OpenBSD Message-ID: <20180528113028.l3hp5kdvxrdb74wm@nohkan.my.domain> Hi all, I tried to install snd (version 18.4) on my openbsd machine (OpenBSD 6.3, amd64) but ran into a problem: The code in the snd source tree is shared between NetBSD and OpenBSD, which was ok I guess in the past, but a couple of years ago OpenBSD has revamped its audio support and introduced its own audio lib, sndio. This library is designed quite well and pleasant to use, so I decided to try and make a little patch (see attachment). The patch isn't super polished and could be improved in a couple of places if need be. For example, a mus_open_*() call always returns either a 0 for output or a 1 for input (just like in the portaudio interface), and thus only allows one input and one output stream handle at the same time. By contrast, sndio has mixing built-in and happily accepts multiple input and/or output streams at the same time. You can also make sndio return a list with supported audio formats (just like in the netbsd code), but I didn't bother with that yet, proposing a safe default instead. I also succeeded in building snd with portaudio support, but that didn't work out of the box either: I needed to change the order of the code in audio.c a bit: snd insists on building with openbsd sound even if you ./configure --with-portaudio explicitly. Thanks for the wonderful piece of software that is snd! Best regards, Koen -------------- next part -------------- diff -rupN snd-18/audio.c snd-18-patch/audio.c --- snd-18/audio.c Fri May 18 13:04:12 2018 +++ snd-18-patch/audio.c Mon May 28 12:56:33 2018 @@ -19,7 +19,8 @@ * OSX * JACK * HPUX - * NetBSD/OpenBSD + * OpenBSD + * NetBSD * PulseAudio (in progress?) * PortAudio */ @@ -4799,11 +4800,123 @@ int mus_audio_read(int line, char *buf, int bytes) #endif +/* ------------------------------- OpenBSD ----------------------------------------- */ +#if (__OpenBSD__) && (!(defined(AUDIO_OK))) +#define AUDIO_OK 1 +#include +static struct sio_hdl *in_hdl = NULL; +static struct sio_hdl *out_hdl = NULL; -/* ------------------------------- NETBSD/OpenBSD ----------------------------------------- */ +#define SNDIO_OUT 0 +#define SNDIO_IN 1 -#if (__NetBSD__ || __OpenBSD__) && (!(defined(AUDIO_OK))) +int mus_audio_initialize(void) +{ + return(MUS_NO_ERROR); +} + +char *mus_audio_moniker(void) +{ + return((char *)"OpenBSD audio (sndio)"); +} + +static int mus_sndio_open(int mode, int srate, int chans, mus_sample_t samp_type, int size) +{ + struct sio_hdl *hdl; + struct sio_par par, par2; + hdl = sio_open(SIO_DEVANY, mode, 0 /*non-blocking io=0 -> we choose blocking*/); + sio_initpar(&par); + switch (samp_type) + { + case MUS_BYTE: par.bits=8;par.bps=1;par.sig=1;break; + case MUS_UBYTE: par.bits=8;par.bps=1;par.sig=0;break; + case MUS_LSHORT: par.bits=16;par.bps=2;par.sig=1;par.le=1;break; + case MUS_BSHORT: par.bits=16;par.bps=2;par.sig=1;par.le=0;break; + case MUS_ULSHORT: par.bits=16;par.bps=2;par.sig=0;par.le=1;break; + case MUS_UBSHORT: par.bits=16;par.bps=2;par.sig=0;par.le=0;break; + /* actually, all linear integer formats are accepted by sndio */ + default: + return(mus_error(MUS_AUDIO_CANT_OPEN, NULL)); + } + if(mode==SIO_PLAY) + par.pchan=chans; + else + par.rchan=chans; + par.rate=srate; + par.appbufsz=size; + /* set params */ + if (!sio_setpar(hdl, &par)) + return(mus_error(MUS_AUDIO_CANT_OPEN, NULL)); + /* then see what sndio thinks of it */ + if (!sio_getpar(hdl, &par2)) + return(mus_error(MUS_AUDIO_CANT_OPEN, NULL)); + + if (par2.bits!=par.bits || par2.bps!=par.bps || + par2.sig!=par.sig || par2.le!=par.le || + par2.rate!=par.rate ||par2.bufsz Snd 18.4: s7: s7_c_object_type_set* various changes clm: added (clm-initialize-links) at end of all.lisp Koen De Turck provided openBSD audio support using sndio checked: sbcl 1.4.7, FC 28 (gcc 8.0), Ubuntu 18.04, openbsd 6.3 Thanks!: Kjetil Matheussen, Michael Edwards, Koen De Turck.