From 8cae1aee80ae579b5950685afe859dfb6892f2c9 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Mon, 27 Jun 2011 01:00:34 -0700 Subject: [PATCH] Clamp PortAudio output to stereo --- Alc/portaudio.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/Alc/portaudio.c b/Alc/portaudio.c index b52bd811..b8a82103 100644 --- a/Alc/portaudio.c +++ b/Alc/portaudio.c @@ -154,7 +154,6 @@ static int pa_capture_cb(const void *inputBuffer, void *outputBuffer, static ALCboolean pa_open_playback(ALCdevice *device, const ALCchar *deviceName) { - const PaStreamInfo *streamInfo; PaStreamParameters outParams; pa_data *data; PaError err; @@ -197,7 +196,7 @@ static ALCboolean pa_open_playback(ALCdevice *device, const ALCchar *deviceName) outParams.sampleFormat = paFloat32; break; } - outParams.channelCount = ChannelsFromDevFmt(device->FmtChans); + outParams.channelCount = ((device->FmtChans == DevFmtMono) ? 1 : 2); SetDefaultChannelOrder(device); @@ -210,10 +209,24 @@ static ALCboolean pa_open_playback(ALCdevice *device, const ALCchar *deviceName) free(data); return ALC_FALSE; } - streamInfo = Pa_GetStreamInfo(data->stream); device->szDeviceName = strdup(deviceName); - device->Frequency = streamInfo->sampleRate; + + if((ALuint)outParams.channelCount != ChannelsFromDevFmt(device->FmtChans)) + { + if(outParams.channelCount != 1 && outParams.channelCount != 2) + { + AL_PRINT("Unhandled channel count: %u\n", outParams.channelCount); + Pa_CloseStream(data->stream); + device->ExtraData = NULL; + free(data); + return ALC_FALSE; + } + if((device->Flags&DEVICE_CHANNELS_REQUEST)) + AL_PRINT("Failed to set %s, got %u channels instead\n", DevFmtChannelsString(device->FmtChans), outParams.channelCount); + device->Flags &= ~DEVICE_CHANNELS_REQUEST; + device->FmtChans = ((outParams.channelCount==1) ? DevFmtMono : DevFmtStereo); + } return ALC_TRUE; } -- 2.11.4.GIT