diff options
author | waker <wakeroid@gmail.com> | 2011-03-24 22:03:29 +0100 |
---|---|---|
committer | waker <wakeroid@gmail.com> | 2011-03-24 22:03:29 +0100 |
commit | c43fabc77c076280136b4bcb5ee11117834bc24a (patch) | |
tree | 853915c54409133ba2b8d991acca3ed01877d7b9 /plugins/alsa | |
parent | fd04c7a395f4ac26942222e29e2dd9a8901bff41 (diff) |
alsa: try all other sampleformats if requested one failed
Diffstat (limited to 'plugins/alsa')
-rw-r--r-- | plugins/alsa/alsa.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/plugins/alsa/alsa.c b/plugins/alsa/alsa.c index ee0dee86..fa08fcdb 100644 --- a/plugins/alsa/alsa.c +++ b/plugins/alsa/alsa.c @@ -184,11 +184,26 @@ retry: break; }; - //sample_fmt = SND_PCM_FORMAT_S16_LE; if ((err = snd_pcm_hw_params_set_format (audio, hw_params, sample_fmt)) < 0) { - fprintf (stderr, "cannot set sample format (%s)\n", - snd_strerror (err)); - goto error; + fprintf (stderr, "cannot set sample format (%s), trying all supported formats\n", snd_strerror (err)); + +#if WORDS_BIGENDIAN + int fmt[] = { SND_PCM_FORMAT_S16_BE, SND_PCM_FORMAT_S24_3BE, SND_PCM_FORMAT_S32_BE, SND_PCM_FORMAT_FLOAT_BE, SND_PCM_FORMAT_S8, -1 }; +#else + int fmt[] = { SND_PCM_FORMAT_S16_LE, SND_PCM_FORMAT_S24_3LE, SND_PCM_FORMAT_S32_LE, SND_PCM_FORMAT_FLOAT_LE, SND_PCM_FORMAT_S8, -1 }; +#endif + int i = 0; + for (i = 0; fmt[i] != -1; i++) { + if (fmt[i] != sample_fmt) { + if (snd_pcm_hw_params_set_format (audio, hw_params, fmt[i]) >= 0) { + break; + } + } + } + + if (fmt[i] == -1) { + goto error; + } } snd_pcm_hw_params_get_format (hw_params, &sample_fmt); |