various audio fixes:

- recognize all available audio devices
- the audio device is always opened read-write.  this results in
  full-duplex operation for most OSS implementations, but full-dupplex
  needs to be explicitly enabled on OpenBSD.
- don't error out if SNDCTL_DSP_SPEED returns an error.  instead
  resample based on the returned sample rate.
- the resampling factor was not properly initilized and was returning
  random values.
- simply skip samples to down-sample.  the average method it uses
  sounds horrible.

now ekiga's softphone works for me when using the OSS audio backend

ok ajacoutot
This commit is contained in:
jakemsr 2008-08-20 01:57:31 +00:00
parent 9d275cf52c
commit 7e624c34a7
2 changed files with 74 additions and 12 deletions

View File

@ -1,4 +1,4 @@
# $OpenBSD: Makefile,v 1.12 2008/07/01 08:22:12 ajacoutot Exp $
# $OpenBSD: Makefile,v 1.13 2008/08/20 01:57:31 jakemsr Exp $
SHARED_ONLY= Yes
@ -6,7 +6,7 @@ COMMENT= portable Windows library
V= 1_12_0
DISTNAME= ptlib-v${V}
PKGNAME= pwlib-${V:S/_/./g}p4
PKGNAME= pwlib-${V:S/_/./g}p5
CATEGORIES= devel
EXTRACT_SUFX= -src.tar.gz

View File

@ -1,14 +1,76 @@
$OpenBSD: patch-plugins_sound_oss_sound_oss_cxx,v 1.4 2008/06/08 02:49:00 robert Exp $
--- plugins/sound_oss/sound_oss.cxx.orig Fri Oct 19 08:22:33 2007
+++ plugins/sound_oss/sound_oss.cxx Sun Jun 8 04:39:26 2008
@@ -429,6 +429,10 @@ static void CollectSoundDevices(PDirectory devdir, POr
mixer.SetAt(cardnum+1, devname);
}
$OpenBSD: patch-plugins_sound_oss_sound_oss_cxx,v 1.5 2008/08/20 01:57:31 jakemsr Exp $
--- plugins/sound_oss/sound_oss.cxx.orig Thu Oct 18 23:22:33 2007
+++ plugins/sound_oss/sound_oss.cxx Sat Aug 9 17:44:37 2008
@@ -384,7 +384,7 @@ static void CollectSoundDevices(PDirectory devdir, POr
// When adding these to the 'dsp' string array, only the first one
// found is used.
-#if !defined P_NETBSD || !defined P_OPENBSD
+#if !defined P_NETBSD && !defined P_OPENBSD
// Look for dsp
if (filename == "dsp") {
dsp.SetAt(0, devname);
@@ -519,6 +519,7 @@ BOOL PSoundChannelOSS::Open(const PString & _device,
Close();
+ resampleRate = 0;
// lock the dictionary
PWaitAndSignal mutex(dictMutex);
@@ -554,6 +555,14 @@ BOOL PSoundChannelOSS::Open(const PString & _device,
DWORD cmd = 0;
::ioctl(os_handle, FIONBIO, &cmd);
+#ifdef P_OPENBSD
+ // full-duplex must be set explicitly. don't worry if it fails because
+ // we might not really want full-duplex, even though we always open the
+ // device read-write.
+ cmd = 1;
+ ::ioctl(os_handle, SNDCTL_DSP_SETDUPLEX, &cmd);
+#endif
+
// add the device to the dictionary
SoundHandleEntry * entry = PNEW SoundHandleEntry;
handleDict().SetAt(_device, entry);
@@ -645,7 +654,9 @@ BOOL PSoundChannelOSS::Setup()
mSampleRate = entry.sampleRate;
arg = val = entry.sampleRate;
- if (ConvertOSError(::ioctl(os_handle, SNDCTL_DSP_SPEED, &arg))) {
+ // don't error out if this gives us an error, simply resample
+ // based on the returned rate.
+ ConvertOSError(::ioctl(os_handle, SNDCTL_DSP_SPEED, &arg));
stat = TRUE;
// detect cases where the hardware can't do the actual rate we need, but can do a simple multiple
@@ -658,7 +669,6 @@ BOOL PSoundChannelOSS::Setup()
actualSampleRate = arg;
}
}
- }
}
+#if defined P_OPENBSD
+ dsp.SetAt(0, "/dev/audio");
+ mixer.SetAt(0, "/dev/mixer");
}
@@ -819,6 +829,7 @@ BOOL PSoundChannelOSS::Read(void * buf, PINDEX len)
// use an average, not just a single sample
const BYTE * src = resampleBuffer;
while ( ((src - resampleBuffer) < bytes) && (dst < dstEnd)) {
+#if 0
int sample = 0;
unsigned j;
for (j = 0; j < resampleRate; ++j) {
@@ -828,6 +839,13 @@ BOOL PSoundChannelOSS::Read(void * buf, PINDEX len)
*(PUInt16l *)dst = sample / resampleRate;
dst +=2 ;
lastReadCount += 2;
+#else
+ // don't average, just use 1/resampleRate bytes
+ *(PUInt16l *)dst = *(PUInt16l *)src;
+ src += 2 * resampleRate;
+ dst +=2 ;
+ lastReadCount += 2;
+#endif
}
}
} while (devdir.Next());
}