This diff adds an sndio driver for audio/xmp.

The default audio output was mono which I changed to stereo (otherwise
aucat will only play on one speaker), however I've not updated the man
page nor changed the --stereo option to --mono.  Mail to upstream bounces,
so I'm not sure how much work I should put into this.

Suggestions are welcome.  Please test and comment.


Index: xmp/Makefile
diff -u xmp/Makefile:1.1.1.1 xmp/Makefile:1.2
--- xmp/Makefile:1.1.1.1        Fri Jan 30 15:15:58 2009
+++ xmp/Makefile        Fri Jan 30 15:18:35 2009
@@ -1,9 +1,9 @@
-# $OpenBSD: Makefile,v 1.29 2007/09/15 21:26:04 simon Exp $
+# $OpenBSD: Makefile,v 1.30 2008/06/18 18:08:06 miod Exp $
 
 COMMENT-main=  extended module player
 COMMENT-xmms=  extended module player plugin for XMMS
 DISTNAME=      xmp-2.0.4
-PKGNAME-main=  ${DISTNAME}p3
+PKGNAME-main=  ${DISTNAME}p4
 PKGNAME-xmms=  xmms-${DISTNAME}p1
 CATEGORIES=    audio
 
@@ -29,15 +29,14 @@
 MULTI_PACKAGES+=       -xmms
 LIB_DEPENDS=           xmms.>=3::audio/xmms
 .else
-CONFIGURE_ARGS+= --disable-xmms
+CONFIGURE_ARGS+= --disable-xmms --disable-esd
 .endif
 
 LIB_DEPENDS-xmms=
 RUN_DEPENDS-xmms=      ::audio/xmms
 WANTLIB-xmms=
 
-LIB_DEPENDS-main=      esd.>=2::audio/esound
-WANTLIB-main=          X11 Xext c m
+WANTLIB-main=          X11 Xext c m sndio
 
 USE_X11=       Yes
 USE_GMAKE=     Yes
@@ -49,6 +48,9 @@
 
 FAKE_FLAGS=    DEST_DIR=${WRKINST} \
                SYSCONF_DIR=${PREFIX}/share/examples/xmp
+
+post-extract:
+       @cp -f ${FILESDIR}/openbsd.c ${WRKSRC}/src/drivers
 
 pre-install:
        @${INSTALL_DATA_DIR} ${PREFIX}/share/examples/xmp \
Index: xmp/files/openbsd.c
diff -u /dev/null xmp/files/openbsd.c:1.1
--- /dev/null   Fri Jan 30 15:20:33 2009
+++ xmp/files/openbsd.c Fri Jan 30 15:18:06 2009
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2009 Thomas Pfaff <tpf...@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 "xmpi.h"
+#include "driver.h"
+#include "mixer.h"
+
+static struct sio_hdl *hdl;
+
+static int init (struct xmp_control *);
+static void dance (int);
+static void shutdown (void);
+static void dummy (void);
+
+struct xmp_drv_info drv_openbsd = {
+       "sndio",                /* driver ID */
+       "OpenBSD sndio",        /* driver description */
+       NULL,                   /* help */
+       init,                   /* init */
+       shutdown,               /* shutdown */
+       xmp_smix_numvoices,     /* numvoices */
+       dummy,                  /* voicepos */
+       xmp_smix_echoback,      /* echoback */
+       dummy,                  /* setpatch */
+       xmp_smix_setvol,        /* setvol */
+       dummy,                  /* setnote */
+       xmp_smix_setpan,        /* setpan */
+       dummy,                  /* setbend */
+       xmp_smix_seteffect,     /* seteffect */
+       dummy,                  /* starttimer */
+       dummy,                  /* stctlimer */
+       dummy,                  /* reset */
+       dance,                  /* bufdump */
+       dummy,                  /* bufwipe */
+       dummy,                  /* clearmem */
+       dummy,                  /* sync */
+       xmp_smix_writepatch,    /* writepatch */
+       xmp_smix_getmsg,        /* getmsg */
+       NULL
+};
+
+static void
+dummy (void)
+{
+}
+
+static int
+init (struct xmp_control *ctl)
+{
+       struct sio_par par, askpar;
+
+       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 = ctl->outfmt & XMP_FMT_MONO ? 1 : 2;
+       par.rate = ctl->freq;
+       par.bits = ctl->resol;
+       par.sig = ctl->resol > 8 ? 1 : 0;
+       par.le = SIO_LE_NATIVE;
+       par.appbufsz = par.rate / 4; /* 250ms buffer */
+
+       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 != askpar.rate) {
+               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 xmp_smix_on (ctl);
+
+error:
+       sio_close (hdl);
+       return XMP_ERR_DINIT;
+}
+
+static void
+dance (int len)
+{
+       char *buf;
+
+       if ((buf = xmp_smix_buffer ()) != NULL)
+               sio_write (hdl, buf, len);
+}
+
+static void
+shutdown (void)
+{
+       xmp_smix_off ();
+       sio_close (hdl);
+       hdl = NULL;
+}
Index: xmp/patches/patch-src_drivers_openbsd_c
diff -u xmp/patches/patch-src_drivers_openbsd_c:1.1.1.1 
xmp/patches/patch-src_drivers_openbsd_c:removed
--- xmp/patches/patch-src_drivers_openbsd_c:1.1.1.1     Fri Jan 30 15:15:58 2009
+++ xmp/patches/patch-src_drivers_openbsd_c     Fri Jan 30 15:20:33 2009
@@ -1,56 +0,0 @@
-$OpenBSD: patch-src_drivers_openbsd_c,v 1.1 2003/05/18 07:40:55 naddy Exp $
---- src/drivers/openbsd.c.orig Fri Dec 29 19:08:08 2000
-+++ src/drivers/openbsd.c      Tue Oct  4 22:12:46 2005
-@@ -39,7 +39,6 @@ static void shutdown (void);
- static void dummy () { }
- 
- static char *help[] = {
--    "gain=val", "Audio output gain (0 to 255)",
-     "buffer=val", "Audio buffer size (default is 32768)",
-     NULL
- };
-@@ -75,35 +74,36 @@ struct xmp_drv_info drv_openbsd = {
- static int setaudio (struct xmp_control *ctl)
- {
-     audio_info_t ainfo;
--    int gain = 128;
-     int bsize = 32 * 1024;
-     char *token;
-     char **parm = ctl->parm;
- 
-     parm_init ();
--    chkparm1 ("gain", gain = atoi (token));
-     chkparm1 ("buffer", bsize = atoi (token));
-     parm_end ();
- 
--    if (gain < AUDIO_MIN_GAIN)
--      gain = AUDIO_MIN_GAIN;
--    if (gain > AUDIO_MAX_GAIN)
--      gain = AUDIO_MAX_GAIN;
--
-     AUDIO_INITINFO (&ainfo);
- 
-+    ainfo.mode = AUMODE_PLAY;
-     ainfo.play.sample_rate = ctl->freq;
-     ainfo.play.channels = ctl->outfmt & XMP_FMT_MONO ? 1 : 2;
-     ainfo.play.precision = ctl->resol;
-     ainfo.play.encoding = ctl->resol > 8 ?
-       AUDIO_ENCODING_SLINEAR : AUDIO_ENCODING_ULINEAR;
--    ainfo.play.gain = gain;
-     ainfo.play.buffer_size = bsize;
- 
-     if (ioctl (audio_fd, AUDIO_SETINFO, &ainfo) == -1) {
-       close (audio_fd);
-       return XMP_ERR_DINIT;
-     }
-+
-+    ioctl (audio_fd, AUDIO_GETINFO, &ainfo);
-+    ctl->freq = ainfo.play.sample_rate;
-+    if (ainfo.play.channels == 2)
-+      ctl->outfmt &= ~XMP_FMT_MONO;
-+    else
-+      ctl->outfmt |= XMP_FMT_MONO;
-+    ctl->resol = ainfo.play.precision;
- 
-     drv_openbsd.description = "OpenBSD PCM audio";
-     return XMP_OK;
Index: xmp/patches/patch-src_main_options_c
diff -u /dev/null xmp/patches/patch-src_main_options_c:1.1
--- /dev/null   Fri Jan 30 15:20:33 2009
+++ xmp/patches/patch-src_main_options_c        Fri Jan 30 15:17:12 2009
@@ -0,0 +1,12 @@
+$OpenBSD$
+--- src/main/options.c.orig    Thu Jan 29 18:03:04 2009
++++ src/main/options.c Thu Jan 29 18:02:28 2009
+@@ -392,6 +392,8 @@ void get_options (int argc, char **argv, struct xmp_co
+       }
+     }
+ 
++    opt->outfmt &= ~XMP_FMT_MONO; /* Force stereo. */
++
+     /* Set limits */
+     if (opt->freq < 1000)
+       opt->freq = 1000;       /* Min. rate 1 kHz */

Reply via email to