aboutsummaryrefslogtreecommitdiffstats
path: root/src/output/alsa_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2009-11-10 17:11:34 +0100
committerMax Kellermann <max@duempel.org>2009-12-02 22:29:50 +0100
commitc412d6251e9cd3abe735b7622af4003502e54f72 (patch)
tree7344c13f62e4cc788c830c05d21bb7b5b47f5866 /src/output/alsa_plugin.c
parent68c2cfbb4067b2292e1ff1d4e7716ff370903f84 (diff)
downloadmpd-c412d6251e9cd3abe735b7622af4003502e54f72.tar.gz
mpd-c412d6251e9cd3abe735b7622af4003502e54f72.tar.xz
mpd-c412d6251e9cd3abe735b7622af4003502e54f72.zip
audio_format: changed "bits" to "enum sample_format"
This patch prepares support for floating point samples (and probably other formats). It changes the meaning of the "bits" attribute from a bit count to a symbolic value.
Diffstat (limited to 'src/output/alsa_plugin.c')
-rw-r--r--src/output/alsa_plugin.c73
1 files changed, 44 insertions, 29 deletions
diff --git a/src/output/alsa_plugin.c b/src/output/alsa_plugin.c
index 2c642015d..b7325de07 100644
--- a/src/output/alsa_plugin.c
+++ b/src/output/alsa_plugin.c
@@ -185,13 +185,22 @@ alsa_test_default_device(void)
static snd_pcm_format_t
get_bitformat(const struct audio_format *af)
{
- switch (af->bits) {
- case 8: return SND_PCM_FORMAT_S8;
- case 16: return SND_PCM_FORMAT_S16;
- case 24: return SND_PCM_FORMAT_S24;
- case 32: return SND_PCM_FORMAT_S32;
+ switch (af->format) {
+ case SAMPLE_FORMAT_S8:
+ return SND_PCM_FORMAT_S8;
+
+ case SAMPLE_FORMAT_S16:
+ return SND_PCM_FORMAT_S16;
+
+ case SAMPLE_FORMAT_S24_P32:
+ return SND_PCM_FORMAT_S24;
+
+ case SAMPLE_FORMAT_S32:
+ return SND_PCM_FORMAT_S32;
+
+ default:
+ return SND_PCM_FORMAT_UNKNOWN;
}
- return SND_PCM_FORMAT_UNKNOWN;
}
static snd_pcm_format_t
@@ -264,61 +273,67 @@ configure_hw:
err = snd_pcm_hw_params_set_format(ad->pcm, hwparams,
byteswap_bitformat(bitformat));
if (err == 0) {
- g_debug("ALSA device \"%s\": converting %u bit to reverse-endian\n",
- alsa_device(ad), audio_format->bits);
+ g_debug("ALSA device \"%s\": converting format %s to reverse-endian",
+ alsa_device(ad),
+ sample_format_to_string(audio_format->format));
audio_format->reverse_endian = 1;
}
}
- if (err == -EINVAL && (audio_format->bits == 24 ||
- audio_format->bits == 16)) {
+ if (err == -EINVAL && (audio_format->format == SAMPLE_FORMAT_S24_P32 ||
+ audio_format->format == SAMPLE_FORMAT_S16)) {
/* fall back to 32 bit, let pcm_convert.c do the conversion */
err = snd_pcm_hw_params_set_format(ad->pcm, hwparams,
SND_PCM_FORMAT_S32);
if (err == 0) {
- g_debug("ALSA device \"%s\": converting %u bit to 32 bit\n",
- alsa_device(ad), audio_format->bits);
- audio_format->bits = 32;
+ g_debug("ALSA device \"%s\": converting format %s to 32 bit\n",
+ alsa_device(ad),
+ sample_format_to_string(audio_format->format));
+ audio_format->format = SAMPLE_FORMAT_S32;
}
}
- if (err == -EINVAL && (audio_format->bits == 24 ||
- audio_format->bits == 16)) {
+ if (err == -EINVAL && (audio_format->format == SAMPLE_FORMAT_S24_P32 ||
+ audio_format->format == SAMPLE_FORMAT_S16)) {
/* fall back to 32 bit, let pcm_convert.c do the conversion */
err = snd_pcm_hw_params_set_format(ad->pcm, hwparams,
byteswap_bitformat(SND_PCM_FORMAT_S32));
if (err == 0) {
- g_debug("ALSA device \"%s\": converting %u bit to 32 bit backward-endian\n",
- alsa_device(ad), audio_format->bits);
- audio_format->bits = 32;
+ g_debug("ALSA device \"%s\": converting format %s to 32 bit backward-endian\n",
+ alsa_device(ad),
+ sample_format_to_string(audio_format->format));
+ audio_format->format = SAMPLE_FORMAT_S32;
audio_format->reverse_endian = 1;
}
}
- if (err == -EINVAL && audio_format->bits != 16) {
+ if (err == -EINVAL && audio_format->format != SAMPLE_FORMAT_S16) {
/* fall back to 16 bit, let pcm_convert.c do the conversion */
err = snd_pcm_hw_params_set_format(ad->pcm, hwparams,
SND_PCM_FORMAT_S16);
if (err == 0) {
- g_debug("ALSA device \"%s\": converting %u bit to 16 bit\n",
- alsa_device(ad), audio_format->bits);
- audio_format->bits = 16;
+ g_debug("ALSA device \"%s\": converting format %s to 16 bit\n",
+ alsa_device(ad),
+ sample_format_to_string(audio_format->format));
+ audio_format->format = SAMPLE_FORMAT_S16;
}
}
- if (err == -EINVAL && audio_format->bits != 16) {
+ if (err == -EINVAL && audio_format->format != SAMPLE_FORMAT_S16) {
/* fall back to 16 bit, let pcm_convert.c do the conversion */
err = snd_pcm_hw_params_set_format(ad->pcm, hwparams,
byteswap_bitformat(SND_PCM_FORMAT_S16));
if (err == 0) {
- g_debug("ALSA device \"%s\": converting %u bit to 16 bit backward-endian\n",
- alsa_device(ad), audio_format->bits);
- audio_format->bits = 16;
+ g_debug("ALSA device \"%s\": converting format %s to 16 bit backward-endian\n",
+ alsa_device(ad),
+ sample_format_to_string(audio_format->format));
+ audio_format->format = SAMPLE_FORMAT_S16;
audio_format->reverse_endian = 1;
}
}
if (err < 0) {
g_set_error(error, alsa_output_quark(), err,
- "ALSA device \"%s\" does not support %u bit audio: %s",
- alsa_device(ad), audio_format->bits,
+ "ALSA device \"%s\" does not support format %s: %s",
+ alsa_device(ad),
+ sample_format_to_string(audio_format->format),
snd_strerror(-err));
return false;
}
@@ -449,7 +464,7 @@ alsa_open(void *data, struct audio_format *audio_format, GError **error)
/* sample format is not supported by this plugin -
fall back to 16 bit samples */
- audio_format->bits = 16;
+ audio_format->format = SAMPLE_FORMAT_S16;
bitformat = SND_PCM_FORMAT_S16;
}