]> code.delx.au - pulseaudio/commitdiff
alsa-sink: take base volume into account when applying hw volume
authorJuho Hämäläinen <juho.hamalainen@tieto.com>
Thu, 25 Nov 2010 13:15:17 +0000 (15:15 +0200)
committerColin Guthrie <cguthrie@mandriva.org>
Wed, 1 Dec 2010 10:42:17 +0000 (10:42 +0000)
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>
src/modules/alsa/alsa-sink.c

index 2249f661ba50633c7c167f3b9bc42ecce042ecae..53c14b80bd12cd996bb5e6a157b31f9620347b19 100644 (file)
@@ -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));
         }