summaryrefslogtreecommitdiffstats
path: root/src/modules/alsa/alsa-sink.c
diff options
context:
space:
mode:
authorJuho Hämäläinen <juho.hamalainen@tieto.com>2010-11-25 15:15:17 +0200
committerColin Guthrie <cguthrie@mandriva.org>2010-12-01 10:42:17 +0000
commit027786c6de08abcfb0e8702e59810e1f00977d68 (patch)
tree51a23c10283b03a1c1d06e575535647fe51f7ac8 /src/modules/alsa/alsa-sink.c
parent53f2294d16326688c1b7e21480a40afef6987868 (diff)
alsa-sink: take base volume into account when applying hw volume
Currently if sink base volume differs from 0dB and sync-volume is used, wrong volume values are written to hw. This patch fixes that. Signed-off-by: Juho Hämäläinen <ext-juho.hamalainen@nokia.com>
Diffstat (limited to 'src/modules/alsa/alsa-sink.c')
-rw-r--r--src/modules/alsa/alsa-sink.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 2249f661..53c14b80 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -1263,12 +1263,18 @@ static void sink_write_volume_cb(pa_sink *s) {
pa_assert(u->mixer_handle);
pa_assert(s->flags & PA_SINK_SYNC_VOLUME);
+ /* Shift up by the base volume */
+ pa_sw_cvolume_divide_scalar(&hw_vol, &hw_vol, s->base_volume);
+
if (pa_alsa_path_set_volume(u->mixer_path, u->mixer_handle, &s->channel_map, &hw_vol, TRUE) < 0)
pa_log_error("Writing HW volume failed");
else {
pa_cvolume tmp_vol;
pa_bool_t accurate_enough;
+ /* Shift down by the base volume, so that 0dB becomes maximum volume */
+ pa_sw_cvolume_multiply_scalar(&hw_vol, &hw_vol, s->base_volume);
+
pa_sw_cvolume_divide(&tmp_vol, &hw_vol, &s->thread_info.current_hw_volume);
accurate_enough =
(pa_cvolume_min(&tmp_vol) >= (PA_VOLUME_NORM - VOLUME_ACCURACY)) &&
@@ -1278,10 +1284,10 @@ static void sink_write_volume_cb(pa_sink *s) {
char vol_str_pcnt[PA_CVOLUME_SNPRINT_MAX];
char vol_str_db[PA_SW_CVOLUME_SNPRINT_DB_MAX];
- pa_log_debug("Written HW volume did not match with the request %s != %s",
+ pa_log_debug("Written HW volume did not match with the request: %s (request) != %s",
pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &s->thread_info.current_hw_volume),
pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &hw_vol));
- pa_log_debug(" in dB: %s != %s",
+ pa_log_debug(" in dB: %s (request) != %s",
pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &s->thread_info.current_hw_volume),
pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &hw_vol));
}