$OpenBSD: patch-src_opusdec_c,v 1.1.1.1 2012/07/10 12:12:37 naddy Exp $
--- src/opusdec.c.orig	Wed Jun 13 00:01:52 2012
+++ src/opusdec.c	Mon Jul  9 23:18:44 2012
@@ -63,7 +63,10 @@
 #define I64FORMAT "lld"
 #endif
 
-#if defined HAVE_SYS_SOUNDCARD_H || defined HAVE_MACHINE_SOUNDCARD_H || HAVE_SOUNDCARD_H
+#if defined USE_SNDIO
+#include <sndio.h>
+
+#elif defined HAVE_SYS_SOUNDCARD_H || defined HAVE_MACHINE_SOUNDCARD_H || HAVE_SOUNDCARD_H
 #ifdef HAVE_SYS_SOUNDCARD_H
 # include <sys/soundcard.h>
 #elif HAVE_MACHINE_SOUNDCARD_H
@@ -105,6 +108,10 @@
                            ((buf[base+1]<<8)&0xff00)| \
                            (buf[base]&0xff))
 
+#ifdef USE_SNDIO
+struct sio_hdl *hdl;
+#endif
+
 typedef struct shapestate shapestate;
 struct shapestate {
   float * b_buf;
@@ -301,6 +308,32 @@ FILE *out_file_open(char *outFile, int rate, int *chan
         perror("Cannot open output");
         exit(1);
       }
+#elif defined USE_SNDIO
+      struct sio_par par;
+
+      hdl = sio_open(NULL, SIO_PLAY, 0);
+      if (!hdl)
+      {
+         fprintf(stderr, "Cannot open sndio device\n");
+         exit(1);
+      }
+
+      sio_initpar(&par);
+      par.sig = 1;
+      par.bits = 16;
+      par.rate = rate;
+      par.pchan = *channels;
+
+      if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par) ||
+        par.sig != 1 || par.bits != 16 || par.rate != rate) {
+          fprintf(stderr, "could not set sndio parameters\n");
+          exit(1);
+      }
+      *channels = par.pchan;
+      if (!sio_start(hdl)) {
+          fprintf(stderr, "could not start sndio\n");
+          exit(1);
+      }
 #elif defined HAVE_SYS_AUDIOIO_H
       audio_info_t info;
       int audio_fd;
@@ -507,6 +540,12 @@ opus_int64 audio_write(float *pcm, int channels, int f
 #if defined WIN32 || defined _WIN32
        if(!file){
          ret=WIN_Play_Samples (out, sizeof(short) * channels * (out_len<maxout?out_len:maxout));
+         if(ret>0)ret/=sizeof(short)*channels;
+         else fprintf(stderr, "Error playing audio.\n");
+       }else
+#elif defined USE_SNDIO
+       if(!file){
+         ret=sio_write (hdl, out, sizeof(short) * channels * (out_len<maxout?out_len:maxout));
          if(ret>0)ret/=sizeof(short)*channels;
          else fprintf(stderr, "Error playing audio.\n");
        }else
