$OpenBSD: patch-src_hostapi_oss_pa_unix_oss_c,v 1.4 2008/03/24 05:26:46 jakemsr Exp $
--- src/hostapi/oss/pa_unix_oss.c.orig	Mon Feb 25 17:37:41 2008
+++ src/hostapi/oss/pa_unix_oss.c	Mon Feb 25 18:32:40 2008
@@ -76,6 +76,9 @@
 #elif defined(HAVE_MACHINE_SOUNDCARD_H)
 # include <machine/soundcard.h> /* JH20010905 */
 # define DEVICE_NAME_BASE            "/dev/audio"
+#elif defined(HAVE_SOUNDCARD_H)
+# include <soundcard.h>
+# define DEVICE_NAME_BASE            "/dev/audio"
 #else
 # error No sound card header file
 #endif
@@ -409,8 +412,15 @@ static PaError QueryDirection( const char *deviceName,
     if( *defaultSampleRate < 0 )
     {
         sr = 44100;
-        ENSURE_( ioctl( devHandle, SNDCTL_DSP_SPEED, &sr ), paUnanticipatedHostError );
-
+        if( ioctl( devHandle, SNDCTL_DSP_SPEED, &sr ) < 0 )
+        {
+            sr = 48000;
+            if( ioctl( devHandle, SNDCTL_DSP_SPEED, &sr ) < 0 )
+            {
+                result = paUnanticipatedHostError;
+                goto error;
+	    }
+        }
         *defaultSampleRate = sr;
     }
 
@@ -594,6 +604,7 @@ static PaError IsFormatSupported( struct PaUtilHostApi
     int tempDevHandle = -1;
     int flags;
     PaSampleFormat inputSampleFormat, outputSampleFormat;
+    int sr;
 
     if( inputParameters )
     {
@@ -689,6 +700,43 @@ static PaError IsFormatSupported( struct PaUtilHostApi
     /* PaOssStream_Configure will do the rest of the checking for us */
     /* PA_ENSURE( PaOssStream_Configure( tempDevHandle, deviceName, outputChannelCount, &sampleRate ) ); */
 
+    /* try to set the number of channels */
+    if (outputChannelCount > 0) {
+        if ( ioctl( tempDevHandle, SNDCTL_DSP_CHANNELS, &outputChannelCount ) < 0 ) {
+            result = paInvalidChannelCount;
+            goto error;
+        }
+        if (outputChannelCount != outputParameters->channelCount) {
+            result =  paInvalidChannelCount;
+            goto error;
+        }
+    }
+    if ((inputChannelCount > 0) && (inputChannelCount != outputChannelCount)) {
+        if ( ioctl( tempDevHandle, SNDCTL_DSP_CHANNELS, &inputChannelCount ) < 0 ) {
+            result = paInvalidChannelCount;
+            goto error;
+        }
+        if (inputChannelCount != inputParameters->channelCount) {
+            result =  paInvalidChannelCount;
+            goto error;
+        }
+    }
+
+    /* try to set the sample rate */
+    sr = (int)sampleRate;
+
+    if ( ioctl( tempDevHandle, SNDCTL_DSP_SPEED, &sr ) < 0) {
+        result = paInvalidSampleRate;
+        goto error;
+    }
+
+    /* reject if there's no sample rate within 1% of the one requested */
+    if( (fabs( sampleRate - (double)sr ) / sampleRate) > 0.01 )
+    {
+        result = paInvalidSampleRate;
+        goto error;
+    }
+
     /* everything succeeded! */
 
  error:
@@ -807,9 +855,11 @@ static PaError OpenDevices( const char *idevName, cons
         ENSURE_( *idev = open( idevName, flags ), paDeviceUnavailable );
         PA_ENSURE( ModifyBlocking( *idev, 1 ) ); /* Blocking */
 
+#ifndef __OpenBSD__
         /* Initially disable */
         enableBits = ~PCM_ENABLE_INPUT;
         ENSURE_( ioctl( *idev, SNDCTL_DSP_SETTRIGGER, &enableBits ), paUnanticipatedHostError );
+#endif
     }
     if( odevName )
     {
@@ -818,9 +868,11 @@ static PaError OpenDevices( const char *idevName, cons
             ENSURE_( *odev = open( odevName, flags ), paDeviceUnavailable );
             PA_ENSURE( ModifyBlocking( *odev, 1 ) ); /* Blocking */
 
+#ifndef __OpenBSD__
             /* Initially disable */
             enableBits = ~PCM_ENABLE_OUTPUT;
             ENSURE_( ioctl( *odev, SNDCTL_DSP_SETTRIGGER, &enableBits ), paUnanticipatedHostError );
+#endif
         }
         else
         {
