$OpenBSD: patch-src_plugins_sndio_ao_sndio_c,v 1.1 2010/06/03 15:49:38 naddy Exp $
--- src/plugins/sndio/ao_sndio.c.orig	Sun May 23 17:12:27 2010
+++ src/plugins/sndio/ao_sndio.c	Sun May 23 17:17:39 2010
@@ -13,6 +13,7 @@
  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
+#include <string.h>
 #include <sndio.h>
 #include <ao/ao.h>
 #include <ao/plugin.h>
@@ -37,7 +38,7 @@ ao_info ao_sndio_info = {
   4
 };
 
-typedef struct ao_alsa_internal
+typedef struct ao_sndio_internal
 {
   struct sio_hdl *hdl;
   char *dev;
@@ -88,21 +89,28 @@ int ao_plugin_set_option(ao_device *device, const char
 int ao_plugin_open(ao_device *device, ao_sample_format *format)
 {
   ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
+  struct sio_hdl *hdl;
   struct sio_par par;
 
-  internal->hdl = sio_open(internal->dev, SIO_PLAY, 0);
-  if (internal->hdl == NULL)
+  hdl = sio_open(internal->dev, SIO_PLAY, 0);
+  if (hdl == NULL)
     return 0;
+  internal->hdl = hdl;
 
   sio_initpar(&par);
   par.sig = 1;
-  par.le = SIO_LE_NATIVE;
+  if (format->bits > 8)
+    par.le = device->client_byte_format == AO_FMT_LITTLE ? 1 : 0;
   par.bits = format->bits;
   par.rate = format->rate;
   par.pchan = device->output_channels;
   if (!sio_setpar(hdl, &par))
     return 0;
-  device->driver_byte_format = AO_FMT_NATIVE;
+  if (!sio_getpar(hdl, &par))
+    return 0;
+  if (par.bits != format->bits)
+    return 0;
+  device->driver_byte_format = par.le ? AO_FMT_LITTLE : AO_FMT_BIG;
   if (!sio_start(hdl))
     return 0;
 
@@ -131,8 +139,8 @@ int ao_plugin_close(ao_device *device)
   ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
   struct sio_hdl *hdl = internal->hdl;
 
-  if (!sio_stop(hdl))
-    return 0;
+  sio_close(hdl);
+  internal->hdl = NULL;
   return 1;
 }
 
@@ -141,7 +149,9 @@ void ao_plugin_device_clear(ao_device *device)
   ao_sndio_internal *internal = (ao_sndio_internal *) device->internal;
   struct sio_hdl *hdl = internal->hdl;
 
-  sio_close(hdl);
+  if (hdl)
+    sio_close(hdl);
+  internal->hdl=NULL;
   if(internal->dev)
     free(internal->dev);
   internal->dev=NULL;
