$OpenBSD: patch-bonk_cc,v 1.3 2009/12/21 20:17:29 naddy Exp $
--- bonk.cc.orig	Sun Jun 23 09:58:57 2002
+++ bonk.cc	Sat Dec 19 03:40:21 2009
@@ -56,14 +56,21 @@ using namespace std;
 #  define  AFMT_S16_NE AFMT_S16_BE
 #  endif
 #  endif
-#elif defined(__NetBSD__) || defined(__OpenBSD__)
+#elif defined(__NetBSD__)
 #  define dsp_device "/dev/sound"
 #  include <soundcard.h>
+#elif defined(__OpenBSD__)
+#  define USE_SNDIO
+#  include <sndio.h>
 #endif
 	      
 #include "utility.h"
 #include "wav.h"
 
+#ifdef USE_SNDIO
+static struct sio_hdl *hdl;
+#endif
+
 //Accuracy of fixed point calculations
 const int    lattice_shift  = 10,
              sample_shift   = 4,
@@ -540,6 +547,7 @@ struct decoder {
   }
 };
 
+#ifndef USE_SNDIO
 FILE *open_dsp(int rate,bool stereo) {
   int device = open(dsp_device,O_WRONLY);
   if (device < 0)
@@ -558,6 +566,7 @@ FILE *open_dsp(int rate,bool stereo) {
 
   return fdopen(device,"wb"); 
 }
+#endif
 
 bool has_parameter(int &argc,char **&argv,char *name,char *&value) {
   for(int i=1;i<argc-1;i++) {
@@ -597,10 +606,41 @@ void play_file(char *name) {
 
   deco.begin(f_in);
 
+#ifdef USE_SNDIO
+  struct sio_par par, askpar;
+
+  hdl = sio_open(NULL, SIO_PLAY, 0);
+  if (hdl == NULL)
+    throw error("Failed to open audio device");
+
+  sio_initpar (&par);
+  par.pchan = deco.channels;
+  par.rate = deco.rate;
+  par.bits = 16;
+  par.sig = 1;
+  par.le = SIO_LE_NATIVE;
+  par.appbufsz = par.rate / 4;
+
+  askpar = par;
+  if (!sio_setpar(hdl, &par) || !sio_getpar(hdl, &par))
+    throw error("Failed to set parameters");
+
+  if (par.le != askpar.le ||
+      par.bits != askpar.bits ||
+      par.sig != askpar.sig ||
+      par.pchan != askpar.pchan ||
+      ((par.rate * 1000 < askpar.rate * 995) ||
+       (par.rate * 1000 > askpar.rate * 1005)))
+    throw error("Parameters not supported");
+
+  if (!sio_start(hdl))
+    throw error("Failed to start audio device");
+#else
   if (deco.channels > 2)
     throw error("Don't know how to play more than 2 channels");
 
   FILE *f_out = open_dsp(deco.rate,deco.channels>1); 
+#endif
 
   while(deco.length_remaining) {
     vector<int> samples;
@@ -615,12 +655,20 @@ void play_file(char *name) {
       else                          
         little_samples[i] =  samples[i];
     }
+#ifdef USE_SNDIO
+    sio_write(hdl, &(little_samples[0]), 2 * little_samples.size());
+#else
     fwrite(&(little_samples[0]),2,little_samples.size(),f_out);
     fflush(f_out);
+#endif
   }
 
   fclose(f_in);
+#ifdef USE_SNDIO
+  sio_close(hdl);
+#else
   fclose(f_out);
+#endif
 }
 
 void do_play(int argc,char **argv) {
@@ -929,6 +977,9 @@ int main(int argc,char **argv) {
     }
     
   } catch(error e) {
+#ifdef USE_SNDIO
+    sio_close(hdl);
+#endif
     fprintf(stderr,"\nError: %s\n",e.message);
     return 1;
   }
