diff options
author | Manuel Bachmann <manuel.bachmann@iot.bzh> | 2015-12-22 15:17:37 +0100 |
---|---|---|
committer | Manuel Bachmann <manuel.bachmann@iot.bzh> | 2015-12-22 15:17:37 +0100 |
commit | 6f2913ab5e366e8f3df12a7df11a85b7b6574e2c (patch) | |
tree | 60bb00a0b8fe0dadefbdbeb9c01445b5b645d7f3 /plugins/audio/audio-alsa.c | |
parent | 1b238baa74d36f144581deee5f3a1834d1d445bb (diff) |
Audio API: manage multiple-channel volume
You can now set the volume for multiple channels
independantly by using the "value=<1>,<2>..." syntax.
Signed-off-by: Manuel Bachmann <manuel.bachmann@iot.bzh>
Diffstat (limited to 'plugins/audio/audio-alsa.c')
-rw-r--r-- | plugins/audio/audio-alsa.c | 38 |
1 files changed, 30 insertions, 8 deletions
diff --git a/plugins/audio/audio-alsa.c b/plugins/audio/audio-alsa.c index 8e56e52d..1f54f244 100644 --- a/plugins/audio/audio-alsa.c +++ b/plugins/audio/audio-alsa.c @@ -19,6 +19,17 @@ #include "audio-api.h" #include "audio-alsa.h" +snd_mixer_selem_channel_id_t SCHANNELS[8] = { + SND_MIXER_SCHN_FRONT_LEFT, + SND_MIXER_SCHN_FRONT_RIGHT, + SND_MIXER_SCHN_FRONT_CENTER, + SND_MIXER_SCHN_REAR_LEFT, + SND_MIXER_SCHN_REAR_RIGHT, + SND_MIXER_SCHN_REAR_CENTER, + SND_MIXER_SCHN_SIDE_LEFT, + SND_MIXER_SCHN_SIDE_RIGHT +}; + PUBLIC unsigned char _alsa_init (const char *name, audioCtxHandleT *ctx) { snd_pcm_t *dev; @@ -28,7 +39,7 @@ PUBLIC unsigned char _alsa_init (const char *name, audioCtxHandleT *ctx) { snd_mixer_elem_t *mixer_elm; unsigned int rate = 22050; long vol, vol_min, vol_max; - int num; + int num, i; if (snd_pcm_open (&dev, name, SND_PCM_STREAM_PLAYBACK, 0) < 0) return 0; @@ -105,7 +116,8 @@ PUBLIC unsigned char _alsa_init (const char *name, audioCtxHandleT *ctx) { dev_ctx[num]->thr_finished = 0; /* make the client context aware of current card state */ - ctx->volume = _alsa_get_volume (num); + for (i = 0; i < 8; i++) + ctx->volume[i] = _alsa_get_volume (num, i); ctx->mute = _alsa_get_mute (num); ctx->idx = num; @@ -155,22 +167,32 @@ PUBLIC void _alsa_stop (unsigned int num) { pthread_join(dev_ctx[num]->thr, NULL); } -PUBLIC unsigned int _alsa_get_volume (unsigned int num) { +PUBLIC int _alsa_get_volume (unsigned int num, unsigned int channel) { if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->mixer_elm) return; - snd_mixer_selem_get_playback_volume (dev_ctx[num]->mixer_elm, SND_MIXER_SCHN_FRONT_LEFT, &dev_ctx[num]->vol); + snd_mixer_selem_get_playback_volume (dev_ctx[num]->mixer_elm, SCHANNELS[channel], &dev_ctx[num]->vol); - return (unsigned int)(dev_ctx[num]->vol*100)/dev_ctx[num]->vol_max; + return (int)(dev_ctx[num]->vol*100)/dev_ctx[num]->vol_max; } -PUBLIC unsigned int _alsa_set_volume (unsigned int num, unsigned int vol) { +PUBLIC void _alsa_set_volume (unsigned int num, unsigned int channel, int vol) { - if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->mixer_elm || vol > 100) + if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->mixer_elm || + 0 > vol > 100) return; - snd_mixer_selem_set_playback_volume_all (dev_ctx[num]->mixer_elm, (vol*dev_ctx[num]->vol_max)/100); + snd_mixer_selem_set_playback_volume (dev_ctx[num]->mixer_elm, SCHANNELS[channel], (vol*dev_ctx[num]->vol_max)/100); + +} + +PUBLIC void _alsa_set_volume_all (unsigned int num, int vol) { + + if (!dev_ctx || !dev_ctx[num] || !dev_ctx[num]->mixer_elm || + 0 > vol > 100) + + snd_mixer_selem_set_playback_volume_all (dev_ctx[num]->mixer_elm, (vol*dev_ctx[num]->vol_max)/100); } PUBLIC unsigned char _alsa_get_mute (unsigned int num) { |