From 00272883f64d4fa664e7019f9ce9100a4c474068 Mon Sep 17 00:00:00 2001 From: Chris Robinson Date: Sun, 27 Sep 2009 08:35:10 -0700 Subject: Fallback to 16-bit or 8-bit, or mono, if ALSA doesn't accept the request --- Alc/alsa.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/Alc/alsa.c b/Alc/alsa.c index b392ecba..bb732fe7 100644 --- a/Alc/alsa.c +++ b/Alc/alsa.c @@ -554,10 +554,43 @@ static ALCboolean alsa_reset_playback(ALCdevice *device) } /* set format (implicitly sets sample bits) */ if(err == NULL && (i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, format)) < 0) - err = "set format"; + { + switch(aluChannelsFromFormat(device->Format)) + { + case 1: device->Format = AL_FORMAT_MONO16; break; + case 2: device->Format = AL_FORMAT_STEREO16; break; + case 4: device->Format = AL_FORMAT_QUAD16; break; + case 6: device->Format = AL_FORMAT_51CHN16; break; + case 7: device->Format = AL_FORMAT_61CHN16; break; + case 8: device->Format = AL_FORMAT_71CHN16; break; + } + if((i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, SND_PCM_FORMAT_S16)) < 0) + { + switch(aluChannelsFromFormat(device->Format)) + { + case 1: device->Format = AL_FORMAT_MONO8; break; + case 2: device->Format = AL_FORMAT_STEREO8; break; + case 4: device->Format = AL_FORMAT_QUAD8; break; + case 6: device->Format = AL_FORMAT_51CHN8; break; + case 7: device->Format = AL_FORMAT_61CHN8; break; + case 8: device->Format = AL_FORMAT_71CHN8; break; + } + if((i=psnd_pcm_hw_params_set_format(data->pcmHandle, p, SND_PCM_FORMAT_U8)) < 0) + err = "set format"; + } + } /* set channels (implicitly sets frame bits) */ if(err == NULL && (i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, aluChannelsFromFormat(device->Format))) < 0) - err = "set channels"; + { + switch(aluBytesFromFormat(device->Format)) + { + case 1: device->Format = AL_FORMAT_MONO8; break; + case 2: device->Format = AL_FORMAT_MONO16; break; + case 4: device->Format = AL_FORMAT_MONO_FLOAT32; break; + } + if((i=psnd_pcm_hw_params_set_channels(data->pcmHandle, p, 1)) < 0) + err = "set channels"; + } /* set periods (implicitly constrains period/buffer parameters) */ if(err == NULL && (i=psnd_pcm_hw_params_set_periods_near(data->pcmHandle, p, &periods, NULL)) < 0) err = "set periods near"; -- cgit v1.2.3