ref: b7cd7074c00f15df5b30eee0e0a1b216839646ad
parent: a583f0d9499d005adb393e71a5f27274bfc7ed9d
author: sl <devnull@localhost>
date: Thu Mar 10 09:03:47 EST 2016
add Make.openbsd and kern/devaudio-sndio.c to support sound on OpenBSD (thanks jpm_)
--- /dev/null
+++ b/Make.openbsd
@@ -1,0 +1,21 @@
+# OpenBSD
+PTHREAD=-pthread
+AR=ar
+AS=as
+RANLIB=ranlib
+X11=/usr/X11R6
+CC=gcc
+CFLAGS=-Wall -Wno-missing-braces -ggdb -I$(ROOT) -I$(ROOT)/include -I$(ROOT)/kern -c -I$(X11)/include -D_THREAD_SAFE $(PTHREAD) -O2
+O=o
+OS=posix
+GUI=x11
+LDADD=-L$(X11)/lib64 -L$(X11)/lib -lX11 -lsndio -ggdb
+LDFLAGS=$(PTHREAD)
+TARG=drawterm
+AUDIO=sndio
+
+all: default
+
+libmachdep.a:
+ arch=`uname -m|sed 's/i.86/386/;s/Power Macintosh/power/; s/x86_64/amd64/'`; \
+ (cd posix-$$arch && make)
--- /dev/null
+++ b/kern/devaudio-sndio.c
@@ -1,0 +1,75 @@
+#include <sndio.h>
+
+#include "u.h"
+#include "lib.h"
+#include "dat.h"
+#include "fns.h"
+#include "error.h"
+#include "devaudio.h"
+
+enum
+{
+ Channels = 2,
+ Rate = 44100,
+ Bits = 16,
+};
+
+static struct sio_hdl *hdl;
+static struct sio_par par;
+
+void
+audiodevopen(void)
+{
+ hdl = sio_open(NULL, SIO_PLAY, 0);
+ if(hdl == NULL)
+ return;
+
+ sio_initpar(&par);
+
+ par.bits = Bits;
+ par.pchan = Channels;
+ par.rate = Rate;
+ par.appbufsz = 288000;
+
+ if(!sio_setpar(hdl, &par) || !sio_start(hdl)){
+ sio_close(hdl);
+ return;
+ }
+}
+
+void
+audiodevclose(void)
+{
+ sio_close(hdl);
+}
+
+void
+audiodevsetvol(int what, int left, int right)
+{
+ USED(what);
+ USED(left);
+ USED(right);
+ error("not supported");
+}
+
+void
+audiodevgetvol(int what, int *left, int *right)
+{
+ USED(what);
+ USED(left);
+ USED(right);
+ error("not supported");
+}
+
+int
+audiodevwrite(void *v, int n)
+{
+ return sio_write(hdl, v, n);
+}
+
+int
+audiodevread(void *v, int n)
+{
+ error("no reading");
+ return -1;
+}