diff options
author | Lennart Poettering <lennart@poettering.net> | 2006-05-13 20:29:32 +0000 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2006-05-13 20:29:32 +0000 |
commit | b6812029ba32002aea1576339571eafde62f124a (patch) | |
tree | ca379b62a3c31bc8ad49b68291b2bf4b8963f52d | |
parent | afdec0532fc1fde7d53bce689d8da0b98dc04d3a (diff) |
use default alsa channel map for alsa devices
git-svn-id: file:///home/lennart/svn/public/pulseaudio/trunk@851 fefdeb5f-60dc-0310-8127-8f9354f1896f
-rw-r--r-- | src/modules/alsa-util.c | 44 | ||||
-rw-r--r-- | src/modules/alsa-util.h | 4 | ||||
-rw-r--r-- | src/modules/module-alsa-sink.c | 14 | ||||
-rw-r--r-- | src/modules/module-alsa-source.c | 14 |
4 files changed, 74 insertions, 2 deletions
diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c index 8bb33c2f..4c9cde9e 100644 --- a/src/modules/alsa-util.c +++ b/src/modules/alsa-util.c @@ -340,3 +340,47 @@ snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name) { return elem; } + +pa_channel_map* pa_alsa_channel_map_init_auto(pa_channel_map *m, unsigned channels) { + assert(m); + assert(channels > 0); + assert(channels <= PA_CHANNELS_MAX); + + pa_channel_map_init(m); + + m->channels = channels; + + /* The standard ALSA channel order */ + + switch (channels) { + case 1: + m->map[0] = PA_CHANNEL_POSITION_MONO; + return m; + + case 8: + m->map[6] = PA_CHANNEL_POSITION_SIDE_LEFT; + m->map[7] = PA_CHANNEL_POSITION_SIDE_RIGHT; + /* Fall through */ + + case 6: + m->map[5] = PA_CHANNEL_POSITION_LFE; + /* Fall through */ + + case 5: + m->map[4] = PA_CHANNEL_POSITION_FRONT_CENTER; + /* Fall through */ + + case 4: + m->map[2] = PA_CHANNEL_POSITION_REAR_LEFT; + m->map[3] = PA_CHANNEL_POSITION_REAR_RIGHT; + /* Fall through */ + + case 2: + m->map[0] = PA_CHANNEL_POSITION_FRONT_LEFT; + m->map[1] = PA_CHANNEL_POSITION_FRONT_RIGHT; + return m; + + default: + return NULL; + } +} diff --git a/src/modules/alsa-util.h b/src/modules/alsa-util.h index c908d7e0..bad6e9bf 100644 --- a/src/modules/alsa-util.h +++ b/src/modules/alsa-util.h @@ -27,6 +27,8 @@ #include <polyp/sample.h> #include <polyp/mainloop-api.h> +#include <polyp/channelmap.h> + struct pa_alsa_fdlist; struct pa_alsa_fdlist *pa_alsa_fdlist_new(void); @@ -40,4 +42,6 @@ int pa_alsa_set_hw_params(snd_pcm_t *pcm_handle, const pa_sample_spec *ss, uint3 int pa_alsa_prepare_mixer(snd_mixer_t *mixer, const char *dev); snd_mixer_elem_t *pa_alsa_find_elem(snd_mixer_t *mixer, const char *name); +pa_channel_map* pa_alsa_channel_map_init_auto(pa_channel_map *m, unsigned channels); + #endif diff --git a/src/modules/module-alsa-sink.c b/src/modules/module-alsa-sink.c index 84b506e1..2d90afaf 100644 --- a/src/modules/module-alsa-sink.c +++ b/src/modules/module-alsa-sink.c @@ -324,10 +324,22 @@ int pa__init(pa_core *c, pa_module*m) { } ss = c->default_sample_spec; - if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) { + if (pa_modargs_get_sample_spec(ma, &ss) < 0) { pa_log(__FILE__": failed to parse sample specification"); goto fail; } + + pa_alsa_channel_map_init_auto(&map, ss.channels); + if ((pa_modargs_get_channel_map(ma, &map) < 0)) { + pa_log(__FILE__": invalid channel map."); + goto fail; + } + + if (ss.channels != map.channels) { + pa_log(__FILE__": channel map and sample specification don't match."); + goto fail; + } + frame_size = pa_frame_size(&ss); periods = 8; diff --git a/src/modules/module-alsa-source.c b/src/modules/module-alsa-source.c index 84ae992b..ad52271c 100644 --- a/src/modules/module-alsa-source.c +++ b/src/modules/module-alsa-source.c @@ -312,10 +312,22 @@ int pa__init(pa_core *c, pa_module*m) { } ss = c->default_sample_spec; - if (pa_modargs_get_sample_spec_and_channel_map(ma, &ss, &map) < 0) { + if (pa_modargs_get_sample_spec(ma, &ss) < 0) { pa_log(__FILE__": failed to parse sample specification"); goto fail; } + + pa_alsa_channel_map_init_auto(&map, ss.channels); + if ((pa_modargs_get_channel_map(ma, &map) < 0)) { + pa_log(__FILE__": invalid channel map."); + goto fail; + } + + if (ss.channels != map.channels) { + pa_log(__FILE__": channel map and sample specification don't match."); + goto fail; + } + frame_size = pa_frame_size(&ss); periods = 12; |