$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 +#elif defined(__OpenBSD__) +# define USE_SNDIO +# include #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 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 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; }