diff options
Diffstat (limited to 'src/modules/alsa-util.c')
-rw-r--r-- | src/modules/alsa-util.c | 84 |
1 files changed, 29 insertions, 55 deletions
diff --git a/src/modules/alsa-util.c b/src/modules/alsa-util.c index 8abf834d..e3e8c85c 100644 --- a/src/modules/alsa-util.c +++ b/src/modules/alsa-util.c @@ -56,7 +56,7 @@ struct pa_alsa_fdlist { void *userdata; }; -static void io_cb(pa_mainloop_api*a, pa_io_event* e, PA_GCC_UNUSED int fd, pa_io_event_flags_t events, void *userdata) { +static void io_cb(pa_mainloop_api*a, pa_io_event* e, int fd, pa_io_event_flags_t events, void *userdata) { struct pa_alsa_fdlist *fdl = userdata; int err, i; @@ -102,7 +102,7 @@ static void io_cb(pa_mainloop_api*a, pa_io_event* e, PA_GCC_UNUSED int fd, pa_io snd_mixer_handle_events(fdl->mixer); } -static void defer_cb(pa_mainloop_api*a, PA_GCC_UNUSED pa_defer_event* e, void *userdata) { +static void defer_cb(pa_mainloop_api*a, pa_defer_event* e, void *userdata) { struct pa_alsa_fdlist *fdl = userdata; int num_fds, i, err; struct pollfd *temp; @@ -808,7 +808,7 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel if (channel_map->channels > 1 && ((playback && snd_mixer_selem_has_playback_volume_joined(elem)) || (!playback && snd_mixer_selem_has_capture_volume_joined(elem)))) { - pa_log_info("ALSA device lacks independant volume controls for each channel, falling back to software volume control."); + pa_log_info("ALSA device lacks independant volume controls for each channel."); return -1; } @@ -820,7 +820,7 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel id = alsa_channel_ids[channel_map->map[i]]; if (!is_mono && id == SND_MIXER_SCHN_UNKNOWN) { - pa_log_info("Configured channel map contains channel '%s' that is unknown to the ALSA mixer. Falling back to software volume control.", pa_channel_position_to_string(channel_map->map[i])); + pa_log_info("Configured channel map contains channel '%s' that is unknown to the ALSA mixer.", pa_channel_position_to_string(channel_map->map[i])); return -1; } @@ -832,7 +832,7 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel if ((playback && (!snd_mixer_selem_has_playback_channel(elem, id) || (is_mono && !snd_mixer_selem_is_playback_mono(elem)))) || (!playback && (!snd_mixer_selem_has_capture_channel(elem, id) || (is_mono && !snd_mixer_selem_is_capture_mono(elem))))) { - pa_log_info("ALSA device lacks separate volumes control for channel '%s', falling back to software volume control.", pa_channel_position_to_string(channel_map->map[i])); + pa_log_info("ALSA device lacks separate volumes control for channel '%s'", pa_channel_position_to_string(channel_map->map[i])); return -1; } @@ -850,56 +850,6 @@ int pa_alsa_calc_mixer_map(snd_mixer_elem_t *elem, const pa_channel_map *channel return 0; } -void pa_alsa_0dB_playback(snd_mixer_elem_t *elem) { - long min, max, v; - - pa_assert(elem); - - /* Try to enable 0 dB if possible. If ALSA cannot do dB, then use - * raw volume levels and fix them to 75% */ - - if (snd_mixer_selem_set_playback_dB_all(elem, 0, -1) >= 0) - return; - - if (snd_mixer_selem_set_playback_dB_all(elem, 0, 1) >= 0) - return; - - if (snd_mixer_selem_get_playback_volume_range(elem, &min, &max) < 0) - return; - - v = min + ((max - min) * 3) / 4; /* 75% */ - - if (v <= min) - v = max; - - snd_mixer_selem_set_playback_volume_all(elem, v); -} - -void pa_alsa_0dB_capture(snd_mixer_elem_t *elem) { - long min, max, v; - - pa_assert(elem); - - /* Try to enable 0 dB if possible. If ALSA cannot do dB, then use - * raw volume levels and fix them to 75% */ - - if (snd_mixer_selem_set_capture_dB_all(elem, 0, -1) >= 0) - return; - - if (snd_mixer_selem_set_capture_dB_all(elem, 0, 1) >= 0) - return; - - if (snd_mixer_selem_get_capture_volume_range(elem, &min, &max) < 0) - return; - - v = min + ((max - min) * 3) / 4; /* 75% */ - - if (v <= min) - v = max; - - snd_mixer_selem_set_capture_volume_all(elem, v); -} - void pa_alsa_dump(snd_pcm_t *pcm) { int err; snd_output_t *out; @@ -1117,3 +1067,27 @@ pa_rtpoll_item* pa_alsa_build_pollfd(snd_pcm_t *pcm, pa_rtpoll *rtpoll) { return item; } + +pa_cvolume *pa_alsa_volume_divide(pa_cvolume *r, const pa_cvolume *t) { + unsigned i; + + pa_assert(r); + pa_assert(t); + pa_assert(r->channels == t->channels); + + for (i = 0; i < r->channels; i++) { + double a, b, c; + + a = pa_sw_volume_to_linear(r->values[i]); /* the hw volume */ + b = pa_sw_volume_to_linear(t->values[i]); /* the intended volume */ + + if (a <= 0) + c = 0; + else + c = b / a; + + r->values[i] = pa_sw_volume_from_linear(c); + } + + return r; +} |