openbsd-ports/audio/nspmod/patches/patch-dacio-linux_c
jakemsr ac4eed901f - use sndio instead of ossaudio
- remove patches for 16-bit only soundcard support - use aucat instead
- @bin marker

ok ratchov
2009-12-24 21:43:32 +00:00

127 lines
3.1 KiB
Plaintext

$OpenBSD: patch-dacio-linux_c,v 1.2 2009/12/24 21:43:32 jakemsr Exp $
--- dacio-linux.c.orig Sun Sep 17 05:51:43 1995
+++ dacio-linux.c Sat Dec 19 22:00:33 2009
@@ -1,10 +1,8 @@
#line 2 "dacio-linux.c"
+#include <stdlib.h>
#include <stdio.h> /*(perror)*/
-#include <fcntl.h> /*O_WRONLY*/
-#include <sys/ioctl.h> /*(ioctl)*/
#include <unistd.h> /*(write)*/
-#include <sys/soundcard.h> /*SNDCTL_XXX*/
-#include <errno.h> /*EINTR*/
+#include <sndio.h>
#include "defs.h" /*u8,u16*/
#include "dacio.h" /*(dacioXXX)*/
#include "mem.h" /*(memPerm)*/
@@ -27,18 +25,14 @@ makeLim(void)
}
#endif
-static int fd;
+static struct sio_hdl *hdl;
-#ifndef DAC_DEV
-#define DAC_DEV "/dev/dsp"
-#endif
-
void
dacioInit(void)
{
- fd = open(DAC_DEV, O_WRONLY);
- if (fd < 0) {
- perror("dacioInit");
+ hdl = sio_open(NULL, SIO_PLAY, 0);
+ if (hdl == NULL) {
+ fprintf(stderr, "dacioInit failed");
exit(1);
}
/*makeLim();*/
@@ -59,52 +53,42 @@ static DacioConfInfo dci;
void
dacioConf(DacioConfInfo *dcp)
{
- int tmp;
+ struct sio_par par;
-#if 0
- if (ioctl(fd, SNDCTL_DSP_RESET) < 0) {
- perror("dacioConf");
- exit(1);
- }
-#endif
- tmp = AFMT_U8;
- if (ioctl(fd, SNDCTL_DSP_SETFMT, &tmp) < 0) {
- perror("dacioConf");
- exit(1);
- }
- /*fprintf(stderr, "fmt = 0x%x\n", tmp);*/
+ sio_initpar(&par);
+ par.bits = 8;
+ par.sig = 0;
+ par.pchan = dcp->stereo + 1;
+ par.rate = dcp->speed;
- if (ioctl(fd, SNDCTL_DSP_STEREO, &dcp->stereo) < 0) {
- perror("dacioConf");
+ if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par)) {
+ fprintf(stderr, "dacioConf failed: set/get\n");
exit(1);
}
- /*fprintf(stderr, "stereo = %d\n", dcp->stereo);*/
- if (ioctl(fd, SNDCTL_DSP_SPEED, &dcp->speed) < 0) {
- perror("dacioConf");
+ if (par.bits != 8 || par.sig != 0 || par.pchan != dcp->stereo + 1 ||
+ par.rate != dcp->speed) {
+ fprintf(stderr, "dacioConf failed: inappropriate settings\n");
exit(1);
}
- /*fprintf(stderr, "speed = %d\n", dcp->speed);*/
- if (ioctl(fd, SNDCTL_DSP_GETBLKSIZE, &buf.size) < 0) {
- perror("dacioConf");
- exit(1);
- }
- /*fprintf(stderr, "buffer size = 0x%x\n", buf.size);*/
+ buf.size = par.round * par.bps * par.pchan;
+
dci = *dcp;
/*if (buf.top != NULL) free(buf.top);*/
buf.top = memPerm(buf.size * sizeof(u8));
buf.p.p8 = buf.top;
buf.bot = buf.top + buf.size;
+
+ if (!sio_start(hdl)) {
+ fprintf(stderr, "dacioConf failed: couldn't start\n");
+ exit(1);
+ }
}
void
dacioSync(void)
{
- if (ioctl(fd, SNDCTL_DSP_SYNC, NULL) < 0) {
- perror("dacioSync");
- exit(1);
- }
}
/* OS independent part (?) */
@@ -116,12 +100,10 @@ dacioFlush(void)
if (buf.p.p8 <= buf.top) return;
for ( ; buf.p.p8 < buf.bot; buf.p.p8++) *buf.p.p8 = 128;
- RETRY:
- s = write(fd, buf.top, buf.size);
+ s = sio_write(hdl, buf.top, buf.size);
if (s < buf.size) {
- if (s < 0) {
- if (errno == EINTR) goto RETRY;
- perror("dacioFlush");
+ if (s == 0) {
+ fprintf(stderr, "dacioFlush: write failed\n");
} else fprintf(stderr, "wrote only %d bytes\n", s);
exit(1);
}