[pulseaudio-commits] 3 commits - src/map-file src/modules src/pulse src/pulsecore src/tests src/utils

Tanu Kaskinen tanuk at kemper.freedesktop.org
Tue Jul 9 07:41:56 PDT 2013


 src/map-file                               |    2 
 src/modules/alsa/alsa-sink.c               |   44 ++++-------
 src/modules/alsa/alsa-source.c             |   44 ++++-------
 src/modules/module-device-restore.c        |   16 +---
 src/modules/module-position-event-sounds.c |    9 +-
 src/modules/module-stream-restore.c        |    4 -
 src/modules/oss/oss-util.c                 |    4 -
 src/modules/raop/module-raop-sink.c        |    9 +-
 src/pulse/volume.c                         |   64 +++++++++++++++++
 src/pulse/volume.h                         |   23 ++++++
 src/pulsecore/cli-command.c                |  107 +++++++++++++++++++++++------
 src/pulsecore/cli-text.c                   |   64 +++++++----------
 src/pulsecore/sink-input.c                 |    1 
 src/tests/volume-test.c                    |   30 +++++---
 src/utils/pactl.c                          |   54 ++++----------
 15 files changed, 300 insertions(+), 175 deletions(-)

New commits:
commit 8e0e2617fb4c70fd4ed031cd108024f84e950fae
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Wed Apr 3 18:28:32 2013 +0300

    sink-input: Keep reference ratio up-to-date
    
    The reference ratio should always be kept up-to-date. If the reference
    ratio is not updated when the input volume changes, the stale
    reference ratio ends up being used as the new input volume when the
    input is moved.

diff --git a/src/pulsecore/sink-input.c b/src/pulsecore/sink-input.c
index ffea078..c6d540e 100644
--- a/src/pulsecore/sink-input.c
+++ b/src/pulsecore/sink-input.c
@@ -1289,6 +1289,7 @@ void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, bool s
         /* OK, we are in normal volume mode. The volume only affects
          * ourselves */
         set_real_ratio(i, volume);
+        i->reference_ratio = i->volume;
 
         /* Copy the new soft_volume to the thread_info struct */
         pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME, NULL, 0, NULL) == 0);

commit ee5e245afac050b7fae11820002cca74beab8f2b
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Wed Apr 3 16:36:43 2013 +0300

    Use pa_(c)volume_snprint_verbose() everywhere
    
    All pa_cvolume_snprint(), pa_volume_snprint(),
    pa_sw_cvolume_snprint_dB() and pa_sw_volume_snprint_dB() calls have
    been replaced with pa_cvolume_snprint_verbose() and
    pa_volume_snprint_verbose() calls, making the log output more
    informative and the code sometimes simpler.

diff --git a/src/modules/alsa/alsa-sink.c b/src/modules/alsa/alsa-sink.c
index 535f7ec..f910d19 100644
--- a/src/modules/alsa/alsa-sink.c
+++ b/src/modules/alsa/alsa-sink.c
@@ -1273,7 +1273,7 @@ static int io_mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
 static void sink_get_volume_cb(pa_sink *s) {
     struct userdata *u = s->userdata;
     pa_cvolume r;
-    char vol_str_pcnt[PA_CVOLUME_SNPRINT_MAX];
+    char volume_buf[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
 
     pa_assert(u);
     pa_assert(u->mixer_path);
@@ -1285,13 +1285,8 @@ static void sink_get_volume_cb(pa_sink *s) {
     /* Shift down by the base volume, so that 0dB becomes maximum volume */
     pa_sw_cvolume_multiply_scalar(&r, &r, s->base_volume);
 
-    pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &r));
-
-    if (u->mixer_path->has_dB) {
-        char vol_str_db[PA_SW_CVOLUME_SNPRINT_DB_MAX];
-
-        pa_log_debug("               in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &r));
-    }
+    pa_log_debug("Read hardware volume: %s",
+                 pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &r, &s->channel_map, u->mixer_path->has_dB));
 
     if (pa_cvolume_equal(&u->hardware_volume, &r))
         return;
@@ -1306,7 +1301,7 @@ static void sink_get_volume_cb(pa_sink *s) {
 static void sink_set_volume_cb(pa_sink *s) {
     struct userdata *u = s->userdata;
     pa_cvolume r;
-    char vol_str_pcnt[PA_CVOLUME_SNPRINT_MAX];
+    char volume_buf[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
     bool deferred_volume = !!(s->flags & PA_SINK_DEFERRED_VOLUME);
 
     pa_assert(u);
@@ -1327,7 +1322,6 @@ static void sink_set_volume_cb(pa_sink *s) {
     if (u->mixer_path->has_dB) {
         pa_cvolume new_soft_volume;
         bool accurate_enough;
-        char vol_str_db[PA_SW_CVOLUME_SNPRINT_DB_MAX];
 
         /* Match exactly what the user requested by software */
         pa_sw_cvolume_divide(&new_soft_volume, &s->real_volume, &u->hardware_volume);
@@ -1339,20 +1333,20 @@ static void sink_set_volume_cb(pa_sink *s) {
             (pa_cvolume_min(&new_soft_volume) >= (PA_VOLUME_NORM - VOLUME_ACCURACY)) &&
             (pa_cvolume_max(&new_soft_volume) <= (PA_VOLUME_NORM + VOLUME_ACCURACY));
 
-        pa_log_debug("Requested volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &s->real_volume));
-        pa_log_debug("           in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &s->real_volume));
-        pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &u->hardware_volume));
-        pa_log_debug("              in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &u->hardware_volume));
+        pa_log_debug("Requested volume: %s",
+                     pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &s->real_volume, &s->channel_map, true));
+        pa_log_debug("Got hardware volume: %s",
+                     pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &u->hardware_volume, &s->channel_map, true));
         pa_log_debug("Calculated software volume: %s (accurate-enough=%s)",
-                     pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &new_soft_volume),
+                     pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &new_soft_volume, &s->channel_map, true),
                      pa_yes_no(accurate_enough));
-        pa_log_debug("                     in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &new_soft_volume));
 
         if (!accurate_enough)
             s->soft_volume = new_soft_volume;
 
     } else {
-        pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &r));
+        pa_log_debug("Wrote hardware volume: %s",
+                     pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &r, &s->channel_map, false));
 
         /* We can't match exactly what the user requested, hence let's
          * at least tell the user about it */
@@ -1388,17 +1382,15 @@ static void sink_write_volume_cb(pa_sink *s) {
             (pa_cvolume_max(&tmp_vol) <= (PA_VOLUME_NORM + VOLUME_ACCURACY));
 
         if (!accurate_enough) {
-            union {
-                char db[2][PA_SW_CVOLUME_SNPRINT_DB_MAX];
-                char pcnt[2][PA_CVOLUME_SNPRINT_MAX];
-            } vol;
+            char volume_buf[2][PA_CVOLUME_SNPRINT_VERBOSE_MAX];
 
             pa_log_debug("Written HW volume did not match with the request: %s (request) != %s",
-                         pa_cvolume_snprint(vol.pcnt[0], sizeof(vol.pcnt[0]), &s->thread_info.current_hw_volume),
-                         pa_cvolume_snprint(vol.pcnt[1], sizeof(vol.pcnt[1]), &hw_vol));
-            pa_log_debug("                                           in dB: %s (request) != %s",
-                         pa_sw_cvolume_snprint_dB(vol.db[0], sizeof(vol.db[0]), &s->thread_info.current_hw_volume),
-                         pa_sw_cvolume_snprint_dB(vol.db[1], sizeof(vol.db[1]), &hw_vol));
+                         pa_cvolume_snprint_verbose(volume_buf[0],
+                                                    sizeof(volume_buf[0]),
+                                                    &s->thread_info.current_hw_volume,
+                                                    &s->channel_map,
+                                                    true),
+                         pa_cvolume_snprint_verbose(volume_buf[1], sizeof(volume_buf[1]), &hw_vol, &s->channel_map, true));
         }
     }
 }
diff --git a/src/modules/alsa/alsa-source.c b/src/modules/alsa/alsa-source.c
index 3d56013..faf8965 100644
--- a/src/modules/alsa/alsa-source.c
+++ b/src/modules/alsa/alsa-source.c
@@ -1155,7 +1155,7 @@ static int io_mixer_callback(snd_mixer_elem_t *elem, unsigned int mask) {
 static void source_get_volume_cb(pa_source *s) {
     struct userdata *u = s->userdata;
     pa_cvolume r;
-    char vol_str_pcnt[PA_CVOLUME_SNPRINT_MAX];
+    char volume_buf[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
 
     pa_assert(u);
     pa_assert(u->mixer_path);
@@ -1167,13 +1167,8 @@ static void source_get_volume_cb(pa_source *s) {
     /* Shift down by the base volume, so that 0dB becomes maximum volume */
     pa_sw_cvolume_multiply_scalar(&r, &r, s->base_volume);
 
-    pa_log_debug("Read hardware volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &r));
-
-    if (u->mixer_path->has_dB) {
-        char vol_str_db[PA_SW_CVOLUME_SNPRINT_DB_MAX];
-
-        pa_log_debug("               in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &r));
-    }
+    pa_log_debug("Read hardware volume: %s",
+                 pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &r, &s->channel_map, u->mixer_path->has_dB));
 
     if (pa_cvolume_equal(&u->hardware_volume, &r))
         return;
@@ -1188,7 +1183,7 @@ static void source_get_volume_cb(pa_source *s) {
 static void source_set_volume_cb(pa_source *s) {
     struct userdata *u = s->userdata;
     pa_cvolume r;
-    char vol_str_pcnt[PA_CVOLUME_SNPRINT_MAX];
+    char volume_buf[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
     bool deferred_volume = !!(s->flags & PA_SOURCE_DEFERRED_VOLUME);
 
     pa_assert(u);
@@ -1209,7 +1204,6 @@ static void source_set_volume_cb(pa_source *s) {
     if (u->mixer_path->has_dB) {
         pa_cvolume new_soft_volume;
         bool accurate_enough;
-        char vol_str_db[PA_SW_CVOLUME_SNPRINT_DB_MAX];
 
         /* Match exactly what the user requested by software */
         pa_sw_cvolume_divide(&new_soft_volume, &s->real_volume, &u->hardware_volume);
@@ -1221,20 +1215,20 @@ static void source_set_volume_cb(pa_source *s) {
             (pa_cvolume_min(&new_soft_volume) >= (PA_VOLUME_NORM - VOLUME_ACCURACY)) &&
             (pa_cvolume_max(&new_soft_volume) <= (PA_VOLUME_NORM + VOLUME_ACCURACY));
 
-        pa_log_debug("Requested volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &s->real_volume));
-        pa_log_debug("           in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &s->real_volume));
-        pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &u->hardware_volume));
-        pa_log_debug("              in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &u->hardware_volume));
+        pa_log_debug("Requested volume: %s",
+                     pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &s->real_volume, &s->channel_map, true));
+        pa_log_debug("Got hardware volume: %s",
+                     pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &u->hardware_volume, &s->channel_map, true));
         pa_log_debug("Calculated software volume: %s (accurate-enough=%s)",
-                     pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &new_soft_volume),
+                     pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &new_soft_volume, &s->channel_map, true),
                      pa_yes_no(accurate_enough));
-        pa_log_debug("                     in dB: %s", pa_sw_cvolume_snprint_dB(vol_str_db, sizeof(vol_str_db), &new_soft_volume));
 
         if (!accurate_enough)
             s->soft_volume = new_soft_volume;
 
     } else {
-        pa_log_debug("Wrote hardware volume: %s", pa_cvolume_snprint(vol_str_pcnt, sizeof(vol_str_pcnt), &r));
+        pa_log_debug("Wrote hardware volume: %s",
+                     pa_cvolume_snprint_verbose(volume_buf, sizeof(volume_buf), &r, &s->channel_map, false));
 
         /* We can't match exactly what the user requested, hence let's
          * at least tell the user about it */
@@ -1270,17 +1264,15 @@ static void source_write_volume_cb(pa_source *s) {
             (pa_cvolume_max(&tmp_vol) <= (PA_VOLUME_NORM + VOLUME_ACCURACY));
 
         if (!accurate_enough) {
-            union {
-                char db[2][PA_SW_CVOLUME_SNPRINT_DB_MAX];
-                char pcnt[2][PA_CVOLUME_SNPRINT_MAX];
-            } vol;
+            char volume_buf[2][PA_CVOLUME_SNPRINT_VERBOSE_MAX];
 
             pa_log_debug("Written HW volume did not match with the request: %s (request) != %s",
-                         pa_cvolume_snprint(vol.pcnt[0], sizeof(vol.pcnt[0]), &s->thread_info.current_hw_volume),
-                         pa_cvolume_snprint(vol.pcnt[1], sizeof(vol.pcnt[1]), &hw_vol));
-            pa_log_debug("                                           in dB: %s (request) != %s",
-                         pa_sw_cvolume_snprint_dB(vol.db[0], sizeof(vol.db[0]), &s->thread_info.current_hw_volume),
-                         pa_sw_cvolume_snprint_dB(vol.db[1], sizeof(vol.db[1]), &hw_vol));
+                         pa_cvolume_snprint_verbose(volume_buf[0],
+                                                    sizeof(volume_buf[0]),
+                                                    &s->thread_info.current_hw_volume,
+                                                    &s->channel_map,
+                                                    true),
+                         pa_cvolume_snprint_verbose(volume_buf[1], sizeof(volume_buf[1]), &hw_vol, &s->channel_map, true));
         }
     }
 }
diff --git a/src/modules/module-device-restore.c b/src/modules/module-device-restore.c
index fd3e23c..780b3e1 100644
--- a/src/modules/module-device-restore.c
+++ b/src/modules/module-device-restore.c
@@ -775,13 +775,13 @@ static pa_hook_result_t sink_fixate_hook_callback(pa_core *c, pa_sink_new_data *
 
             if (!new_data->volume_is_set) {
                 pa_cvolume v;
-                char buf[PA_CVOLUME_SNPRINT_MAX];
+                char buf[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
 
-                pa_log_info("Restoring volume for sink %s.", new_data->name);
                 v = e->volume;
                 pa_cvolume_remap(&v, &e->channel_map, &new_data->channel_map);
                 pa_sink_new_data_set_volume(new_data, &v);
-                pa_log_info("Restored volume: %s", pa_cvolume_snprint(buf, PA_CVOLUME_SNPRINT_MAX, &new_data->volume));
+                pa_log_info("Restoring volume for sink %s: %s", new_data->name,
+                            pa_cvolume_snprint_verbose(buf, sizeof(buf), &new_data->volume, &new_data->channel_map, false));
 
                 new_data->save_volume = true;
             } else
@@ -821,13 +821,11 @@ static pa_hook_result_t sink_port_hook_callback(pa_core *c, pa_sink *sink, struc
 
         if (u->restore_volume && e->volume_valid) {
             pa_cvolume v;
-            char buf[PA_CVOLUME_SNPRINT_MAX];
 
             pa_log_info("Restoring volume for sink %s.", sink->name);
             v = e->volume;
             pa_cvolume_remap(&v, &e->channel_map, &sink->channel_map);
             pa_sink_set_volume(sink, &v, true, false);
-            pa_log_info("Restored volume: %s", pa_cvolume_snprint(buf, PA_CVOLUME_SNPRINT_MAX, &sink->reference_volume));
 
             sink->save_volume = true;
         }
@@ -918,13 +916,13 @@ static pa_hook_result_t source_fixate_hook_callback(pa_core *c, pa_source_new_da
 
             if (!new_data->volume_is_set) {
                 pa_cvolume v;
-                char buf[PA_CVOLUME_SNPRINT_MAX];
+                char buf[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
 
-                pa_log_info("Restoring volume for source %s.", new_data->name);
                 v = e->volume;
                 pa_cvolume_remap(&v, &e->channel_map, &new_data->channel_map);
                 pa_source_new_data_set_volume(new_data, &v);
-                pa_log_info("Restored volume: %s", pa_cvolume_snprint(buf, PA_CVOLUME_SNPRINT_MAX, &new_data->volume));
+                pa_log_info("Restoring volume for source %s: %s", new_data->name,
+                            pa_cvolume_snprint_verbose(buf, sizeof(buf), &new_data->volume, &new_data->channel_map, false));
 
                 new_data->save_volume = true;
             } else
@@ -964,13 +962,11 @@ static pa_hook_result_t source_port_hook_callback(pa_core *c, pa_source *source,
 
         if (u->restore_volume && e->volume_valid) {
             pa_cvolume v;
-            char buf[PA_CVOLUME_SNPRINT_MAX];
 
             pa_log_info("Restoring volume for source %s.", source->name);
             v = e->volume;
             pa_cvolume_remap(&v, &e->channel_map, &source->channel_map);
             pa_source_set_volume(source, &v, true, false);
-            pa_log_info("Restored volume: %s", pa_cvolume_snprint(buf, PA_CVOLUME_SNPRINT_MAX, &source->reference_volume));
 
             source->save_volume = true;
         }
diff --git a/src/modules/module-position-event-sounds.c b/src/modules/module-position-event-sounds.c
index bb62cbb..531fee7 100644
--- a/src/modules/module-position-event-sounds.c
+++ b/src/modules/module-position-event-sounds.c
@@ -74,7 +74,7 @@ static int parse_pos(const char *pos, double *f) {
 static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *core, pa_sink_input_new_data *data, struct userdata *u) {
     const char *hpos, *vpos, *role, *id;
     double f;
-    char t[PA_CVOLUME_SNPRINT_MAX];
+    char t[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
     pa_cvolume v;
 
     pa_assert(data);
@@ -132,7 +132,12 @@ static pa_hook_result_t sink_input_fixate_hook_callback(pa_core *core, pa_sink_i
         }
     }
 
-    pa_log_debug("Final volume factor %s.", pa_cvolume_snprint(t, sizeof(t), &v));
+    pa_log_debug("Final volume factor %s.",
+                 pa_cvolume_snprint_verbose(t,
+                                            sizeof(t),
+                                            &v,
+                                            &data->sink->channel_map,
+                                            data->sink->flags & PA_SINK_DECIBEL_VOLUME));
     pa_sink_input_new_data_add_volume_factor_sink(data, u->name, &v);
 
     return PA_HOOK_OK;
diff --git a/src/modules/module-stream-restore.c b/src/modules/module-stream-restore.c
index 77107e8..735dcde 100644
--- a/src/modules/module-stream-restore.c
+++ b/src/modules/module-stream-restore.c
@@ -1995,7 +1995,9 @@ PA_GCC_UNUSED static void stream_restore_dump_database(struct userdata *u) {
             pa_log("name=%s", name);
             pa_log("device=%s %s", e->device, pa_yes_no(e->device_valid));
             pa_log("channel_map=%s", pa_channel_map_snprint(t, sizeof(t), &e->channel_map));
-            pa_log("volume=%s %s", pa_cvolume_snprint(t, sizeof(t), &e->volume), pa_yes_no(e->volume_valid));
+            pa_log("volume=%s %s",
+                   pa_cvolume_snprint_verbose(t, sizeof(t), &e->volume, &e->channel_map, true),
+                   pa_yes_no(e->volume_valid));
             pa_log("mute=%s %s", pa_yes_no(e->muted), pa_yes_no(e->volume_valid));
             entry_free(e);
         }
diff --git a/src/modules/oss/oss-util.c b/src/modules/oss/oss-util.c
index 1d82713..4527b63 100644
--- a/src/modules/oss/oss-util.c
+++ b/src/modules/oss/oss-util.c
@@ -249,7 +249,7 @@ int pa_oss_set_fragments(int fd, int nfrags, int frag_size) {
 }
 
 int pa_oss_get_volume(int fd, unsigned long mixer, const pa_sample_spec *ss, pa_cvolume *volume) {
-    char cv[PA_CVOLUME_SNPRINT_MAX];
+    char cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
     unsigned vol;
 
     pa_assert(fd >= 0);
@@ -266,7 +266,7 @@ int pa_oss_get_volume(int fd, unsigned long mixer, const pa_sample_spec *ss, pa_
     if (volume->channels >= 2)
         volume->values[1] = PA_CLAMP_VOLUME((((vol >> 8) & 0xFF) * PA_VOLUME_NORM) / 100);
 
-    pa_log_debug("Read mixer settings: %s", pa_cvolume_snprint(cv, sizeof(cv), volume));
+    pa_log_debug("Read mixer settings: %s", pa_cvolume_snprint_verbose(cv, sizeof(cv), volume, NULL, false));
     return 0;
 }
 
diff --git a/src/modules/raop/module-raop-sink.c b/src/modules/raop/module-raop-sink.c
index 13d0c3b..2d08645 100644
--- a/src/modules/raop/module-raop-sink.c
+++ b/src/modules/raop/module-raop-sink.c
@@ -266,7 +266,7 @@ static void sink_set_volume_cb(pa_sink *s) {
     struct userdata *u = s->userdata;
     pa_cvolume hw;
     pa_volume_t v;
-    char t[PA_CVOLUME_SNPRINT_MAX];
+    char t[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
 
     pa_assert(u);
 
@@ -285,9 +285,10 @@ static void sink_set_volume_cb(pa_sink *s) {
     /* Perform any software manipulation of the volume needed */
     pa_sw_cvolume_divide(&s->soft_volume, &s->real_volume, &hw);
 
-    pa_log_debug("Requested volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->real_volume));
-    pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint(t, sizeof(t), &hw));
-    pa_log_debug("Calculated software volume: %s", pa_cvolume_snprint(t, sizeof(t), &s->soft_volume));
+    pa_log_debug("Requested volume: %s", pa_cvolume_snprint_verbose(t, sizeof(t), &s->real_volume, &s->channel_map, false));
+    pa_log_debug("Got hardware volume: %s", pa_cvolume_snprint_verbose(t, sizeof(t), &hw, &s->channel_map, false));
+    pa_log_debug("Calculated software volume: %s",
+                 pa_cvolume_snprint_verbose(t, sizeof(t), &s->soft_volume, &s->channel_map, true));
 
     /* Any necessary software volume manipulation is done so set
        our hw volume (or v as a single value) on the device */
diff --git a/src/pulsecore/cli-command.c b/src/pulsecore/cli-command.c
index ad9bb7d..f937d46 100644
--- a/src/pulsecore/cli-command.c
+++ b/src/pulsecore/cli-command.c
@@ -1873,7 +1873,8 @@ static int pa_cli_command_dump_volumes(pa_core *c, pa_tokenizer *t, pa_strbuf *b
     pa_sink_input *i;
     pa_source_output *o;
     uint32_t s_idx, i_idx;
-    char v_str[PA_CVOLUME_SNPRINT_MAX];
+    char v_str[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
+    pa_channel_map *map;
 
     pa_core_assert_ref(c);
     pa_assert(t);
@@ -1881,41 +1882,105 @@ static int pa_cli_command_dump_volumes(pa_core *c, pa_tokenizer *t, pa_strbuf *b
     pa_assert(fail);
 
     PA_IDXSET_FOREACH(s, c->sinks, s_idx) {
+        map = &s->channel_map;
         pa_strbuf_printf(buf, "Sink %d: ", s_idx);
-        pa_strbuf_printf(buf, "reference = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &s->reference_volume));
-        pa_strbuf_printf(buf, "real = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &s->real_volume));
-        pa_strbuf_printf(buf, "soft = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &s->soft_volume));
-        pa_strbuf_printf(buf, "current_hw = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &s->thread_info.current_hw_volume));
+        pa_strbuf_printf(buf,
+                         "reference = %s, ",
+                         pa_cvolume_snprint_verbose(v_str,
+                                                    sizeof(v_str),
+                                                    &s->reference_volume,
+                                                    map,
+                                                    s->flags & PA_SINK_DECIBEL_VOLUME));
+        pa_strbuf_printf(buf,
+                         "real = %s, ",
+                         pa_cvolume_snprint_verbose(v_str,
+                                                    sizeof(v_str),
+                                                    &s->real_volume,
+                                                    &s->channel_map,
+                                                    s->flags & PA_SINK_DECIBEL_VOLUME));
+        pa_strbuf_printf(buf, "soft = %s, ", pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &s->soft_volume, map, true));
+        pa_strbuf_printf(buf,
+                         "current_hw = %s, ",
+                         pa_cvolume_snprint_verbose(v_str,
+                                                    sizeof(v_str),
+                                                    &s->thread_info.current_hw_volume,
+                                                    map,
+                                                    s->flags & PA_SINK_DECIBEL_VOLUME));
         pa_strbuf_printf(buf, "save = %s\n", pa_yes_no(s->save_volume));
 
         PA_IDXSET_FOREACH(i, s->inputs, i_idx) {
+            map = &i->channel_map;
             pa_strbuf_printf(buf, "\tInput %d: ", i_idx);
-            pa_strbuf_printf(buf, "volume = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &i->volume));
-            pa_strbuf_printf(buf, "reference_ratio = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &i->reference_ratio));
-            pa_strbuf_printf(buf, "real_ratio = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &i->real_ratio));
-            pa_strbuf_printf(buf, "soft = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &i->soft_volume));
-            pa_strbuf_printf(buf, "volume_factor = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &i->volume_factor));
-            pa_strbuf_printf(buf, "volume_factor_sink = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &i->volume_factor_sink));
+            pa_strbuf_printf(buf, "volume = %s, ", pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &i->volume, map, true));
+            pa_strbuf_printf(buf,
+                             "reference_ratio = %s, ",
+                             pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &i->reference_ratio, map, true));
+            pa_strbuf_printf(buf,
+                             "real_ratio = %s, ",
+                             pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &i->real_ratio, map, true));
+            pa_strbuf_printf(buf, "soft = %s, ", pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &i->soft_volume, map, true));
+            pa_strbuf_printf(buf,
+                             "volume_factor = %s, ",
+                             pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &i->volume_factor, map, true));
+            pa_strbuf_printf(buf,
+                             "volume_factor_sink = %s, ",
+                             pa_cvolume_snprint_verbose(v_str,
+                                                        sizeof(v_str),
+                                                        &i->volume_factor_sink,
+                                                        &i->sink->channel_map,
+                                                        true));
             pa_strbuf_printf(buf, "save = %s\n", pa_yes_no(i->save_volume));
         }
     }
 
     PA_IDXSET_FOREACH(so, c->sources, s_idx) {
+        map = &so->channel_map;
         pa_strbuf_printf(buf, "Source %d: ", s_idx);
-        pa_strbuf_printf(buf, "reference = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &so->reference_volume));
-        pa_strbuf_printf(buf, "real = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &so->real_volume));
-        pa_strbuf_printf(buf, "soft = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &so->soft_volume));
-        pa_strbuf_printf(buf, "current_hw = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &so->thread_info.current_hw_volume));
+        pa_strbuf_printf(buf,
+                         "reference = %s, ",
+                         pa_cvolume_snprint_verbose(v_str,
+                                                    sizeof(v_str),
+                                                    &so->reference_volume,
+                                                    map,
+                                                    so->flags & PA_SOURCE_DECIBEL_VOLUME));
+        pa_strbuf_printf(buf,
+                         "real = %s, ",
+                         pa_cvolume_snprint_verbose(v_str,
+                                                    sizeof(v_str),
+                                                    &so->real_volume,
+                                                    map,
+                                                    so->flags & PA_SOURCE_DECIBEL_VOLUME));
+        pa_strbuf_printf(buf, "soft = %s, ", pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &so->soft_volume, map, true));
+        pa_strbuf_printf(buf,
+                         "current_hw = %s, ",
+                         pa_cvolume_snprint_verbose(v_str,
+                                                    sizeof(v_str),
+                                                    &so->thread_info.current_hw_volume,
+                                                    map,
+                                                    so->flags & PA_SOURCE_DECIBEL_VOLUME));
         pa_strbuf_printf(buf, "save = %s\n", pa_yes_no(so->save_volume));
 
         PA_IDXSET_FOREACH(o, so->outputs, i_idx) {
+            map = &o->channel_map;
             pa_strbuf_printf(buf, "\tOutput %d: ", i_idx);
-            pa_strbuf_printf(buf, "volume = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &o->volume));
-            pa_strbuf_printf(buf, "reference_ratio = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &o->reference_ratio));
-            pa_strbuf_printf(buf, "real_ratio = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &o->real_ratio));
-            pa_strbuf_printf(buf, "soft = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &o->soft_volume));
-            pa_strbuf_printf(buf, "volume_factor = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &o->volume_factor));
-            pa_strbuf_printf(buf, "volume_factor_source = %s, ", pa_cvolume_snprint(v_str, sizeof(v_str), &o->volume_factor_source));
+            pa_strbuf_printf(buf, "volume = %s, ", pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &o->volume, map, true));
+            pa_strbuf_printf(buf,
+                             "reference_ratio = %s, ",
+                             pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &o->reference_ratio, map, true));
+            pa_strbuf_printf(buf,
+                             "real_ratio = %s, ",
+                             pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &o->real_ratio, map, true));
+            pa_strbuf_printf(buf, "soft = %s, ", pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &o->soft_volume, map, true));
+            pa_strbuf_printf(buf,
+                             "volume_factor = %s, ",
+                             pa_cvolume_snprint_verbose(v_str, sizeof(v_str), &o->volume_factor, map, true));
+            pa_strbuf_printf(buf,
+                             "volume_factor_source = %s, ",
+                             pa_cvolume_snprint_verbose(v_str,
+                                                        sizeof(v_str),
+                                                        &o->volume_factor_source,
+                                                        &o->source->channel_map,
+                                                        true));
             pa_strbuf_printf(buf, "save = %s\n", pa_yes_no(o->save_volume));
         }
     }
diff --git a/src/pulsecore/cli-text.c b/src/pulsecore/cli-text.c
index 3ca4cbf..c7db0a6 100644
--- a/src/pulsecore/cli-text.c
+++ b/src/pulsecore/cli-text.c
@@ -246,10 +246,8 @@ char *pa_sink_list_to_string(pa_core *c) {
 
     PA_IDXSET_FOREACH(sink, c->sinks, idx) {
         char ss[PA_SAMPLE_SPEC_SNPRINT_MAX],
-            cv[PA_CVOLUME_SNPRINT_MAX],
-            cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
-            v[PA_VOLUME_SNPRINT_MAX],
-            vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
+            cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX],
+            v[PA_VOLUME_SNPRINT_VERBOSE_MAX],
             cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
         const char *cmn;
 
@@ -264,9 +262,9 @@ char *pa_sink_list_to_string(pa_core *c) {
             "\tstate: %s\n"
             "\tsuspend cause: %s%s%s%s\n"
             "\tpriority: %u\n"
-            "\tvolume: %s%s%s\n"
+            "\tvolume: %s\n"
             "\t        balance %0.2f\n"
-            "\tbase volume: %s%s%s\n"
+            "\tbase volume: %s\n"
             "\tvolume steps: %u\n"
             "\tmuted: %s\n"
             "\tcurrent latency: %0.2f ms\n"
@@ -295,13 +293,13 @@ char *pa_sink_list_to_string(pa_core *c) {
             sink->suspend_cause & PA_SUSPEND_IDLE ? "IDLE " : "",
             sink->suspend_cause & PA_SUSPEND_SESSION ? "SESSION" : "",
             sink->priority,
-            pa_cvolume_snprint(cv, sizeof(cv), pa_sink_get_volume(sink, false)),
-            sink->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t        " : "",
-            sink->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), pa_sink_get_volume(sink, false)) : "",
+            pa_cvolume_snprint_verbose(cv,
+                                       sizeof(cv),
+                                       pa_sink_get_volume(sink, false),
+                                       &sink->channel_map,
+                                       sink->flags & PA_SINK_DECIBEL_VOLUME),
             pa_cvolume_get_balance(pa_sink_get_volume(sink, false), &sink->channel_map),
-            pa_volume_snprint(v, sizeof(v), sink->base_volume),
-            sink->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t             " : "",
-            sink->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), sink->base_volume) : "",
+            pa_volume_snprint_verbose(v, sizeof(v), sink->base_volume, sink->flags & PA_SINK_DECIBEL_VOLUME),
             sink->n_volume_steps,
             pa_yes_no(pa_sink_get_mute(sink, false)),
             (double) pa_sink_get_latency(sink) / (double) PA_USEC_PER_MSEC,
@@ -366,10 +364,8 @@ char *pa_source_list_to_string(pa_core *c) {
 
     PA_IDXSET_FOREACH(source, c->sources, idx) {
         char ss[PA_SAMPLE_SPEC_SNPRINT_MAX],
-            cv[PA_CVOLUME_SNPRINT_MAX],
-            cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
-            v[PA_VOLUME_SNPRINT_MAX],
-            vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
+            cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX],
+            v[PA_VOLUME_SNPRINT_VERBOSE_MAX],
             cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t;
         const char *cmn;
 
@@ -384,9 +380,9 @@ char *pa_source_list_to_string(pa_core *c) {
             "\tstate: %s\n"
             "\tsuspend cause: %s%s%s%s\n"
             "\tpriority: %u\n"
-            "\tvolume: %s%s%s\n"
+            "\tvolume: %s\n"
             "\t        balance %0.2f\n"
-            "\tbase volume: %s%s%s\n"
+            "\tbase volume: %s\n"
             "\tvolume steps: %u\n"
             "\tmuted: %s\n"
             "\tcurrent latency: %0.2f ms\n"
@@ -412,13 +408,13 @@ char *pa_source_list_to_string(pa_core *c) {
             source->suspend_cause & PA_SUSPEND_IDLE ? "IDLE " : "",
             source->suspend_cause & PA_SUSPEND_SESSION ? "SESSION" : "",
             source->priority,
-            pa_cvolume_snprint(cv, sizeof(cv), pa_source_get_volume(source, false)),
-            source->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t        " : "",
-            source->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), pa_source_get_volume(source, false)) : "",
+            pa_cvolume_snprint_verbose(cv,
+                                       sizeof(cv),
+                                       pa_source_get_volume(source, false),
+                                       &source->channel_map,
+                                       source->flags & PA_SOURCE_DECIBEL_VOLUME),
             pa_cvolume_get_balance(pa_source_get_volume(source, false), &source->channel_map),
-            pa_volume_snprint(v, sizeof(v), source->base_volume),
-            source->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t             " : "",
-            source->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), source->base_volume) : "",
+            pa_volume_snprint_verbose(v, sizeof(v), source->base_volume, source->flags & PA_SOURCE_DECIBEL_VOLUME),
             source->n_volume_steps,
             pa_yes_no(pa_source_get_mute(source, false)),
             (double) pa_source_get_latency(source) / PA_USEC_PER_MSEC,
@@ -486,7 +482,7 @@ char *pa_source_output_list_to_string(pa_core *c) {
     pa_strbuf_printf(s, "%u source output(s) available.\n", pa_idxset_size(c->source_outputs));
 
     PA_IDXSET_FOREACH(o, c->source_outputs, idx) {
-        char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
+        char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
         pa_usec_t cl;
         const char *cmn;
         pa_cvolume v;
@@ -503,9 +499,8 @@ char *pa_source_output_list_to_string(pa_core *c) {
 
         if (pa_source_output_is_volume_readable(o)) {
             pa_source_output_get_volume(o, &v, true);
-            volume_str = pa_sprintf_malloc("%s\n\t        %s\n\t        balance %0.2f",
-                                           pa_cvolume_snprint(cv, sizeof(cv), &v),
-                                           pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &v),
+            volume_str = pa_sprintf_malloc("%s\n\t        balance %0.2f",
+                                           pa_cvolume_snprint_verbose(cv, sizeof(cv), &v, &o->channel_map, true),
                                            pa_cvolume_get_balance(&v, &o->channel_map));
         } else
             volume_str = pa_xstrdup("n/a");
@@ -585,7 +580,7 @@ char *pa_sink_input_list_to_string(pa_core *c) {
     pa_strbuf_printf(s, "%u sink input(s) available.\n", pa_idxset_size(c->sink_inputs));
 
     PA_IDXSET_FOREACH(i, c->sink_inputs, idx) {
-        char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
+        char ss[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], *t, clt[28];
         pa_usec_t cl;
         const char *cmn;
         pa_cvolume v;
@@ -602,9 +597,8 @@ char *pa_sink_input_list_to_string(pa_core *c) {
 
         if (pa_sink_input_is_volume_readable(i)) {
             pa_sink_input_get_volume(i, &v, true);
-            volume_str = pa_sprintf_malloc("%s\n\t        %s\n\t        balance %0.2f",
-                                           pa_cvolume_snprint(cv, sizeof(cv), &v),
-                                           pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &v),
+            volume_str = pa_sprintf_malloc("%s\n\t        balance %0.2f",
+                                           pa_cvolume_snprint_verbose(cv, sizeof(cv), &v, &i->channel_map, true),
                                            pa_cvolume_get_balance(&v, &i->channel_map));
         } else
             volume_str = pa_xstrdup("n/a");
@@ -678,7 +672,7 @@ char *pa_scache_list_to_string(pa_core *c) {
 
         PA_IDXSET_FOREACH(e, c->scache, idx) {
             double l = 0;
-            char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a", *t;
+            char ss[PA_SAMPLE_SPEC_SNPRINT_MAX] = "n/a", cv[PA_CVOLUME_SNPRINT_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX] = "n/a", *t;
             const char *cmn;
 
             cmn = pa_channel_map_to_pretty_name(&e->channel_map);
@@ -698,7 +692,6 @@ char *pa_scache_list_to_string(pa_core *c) {
                 "\tlength: %lu\n"
                 "\tduration: %0.1f s\n"
                 "\tvolume: %s\n"
-                "\t        %s\n"
                 "\t        balance %0.2f\n"
                 "\tlazy: %s\n"
                 "\tfilename: <%s>\n",
@@ -710,8 +703,7 @@ char *pa_scache_list_to_string(pa_core *c) {
                 cmn ? cmn : "",
                 (long unsigned)(e->memchunk.memblock ? e->memchunk.length : 0),
                 l,
-                e->volume_is_set ? pa_cvolume_snprint(cv, sizeof(cv), &e->volume) : "n/a",
-                e->volume_is_set ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &e->volume) : "n/a",
+                e->volume_is_set ? pa_cvolume_snprint_verbose(cv, sizeof(cv), &e->volume, &e->channel_map, true) : "n/a",
                 (e->memchunk.memblock && e->volume_is_set) ? pa_cvolume_get_balance(&e->volume, &e->channel_map) : 0.0f,
                 pa_yes_no(e->lazy),
                 e->filename ? e->filename : "n/a");
diff --git a/src/tests/volume-test.c b/src/tests/volume-test.c
index d8d2149..a2daf3e 100644
--- a/src/tests/volume-test.c
+++ b/src/tests/volume-test.c
@@ -54,39 +54,47 @@ START_TEST (volume_test) {
                v, (v*100)/PA_VOLUME_NORM, dB, f, pa_sw_volume_from_dB(dB), pa_sw_volume_from_linear(f));
     }
 
+    map.channels = cv.channels = 2;
+    map.map[0] = PA_CHANNEL_POSITION_LEFT;
+    map.map[1] = PA_CHANNEL_POSITION_RIGHT;
+
     for (v = PA_VOLUME_MUTED; v <= PA_VOLUME_NORM*2; v += 256) {
-        char s[PA_CVOLUME_SNPRINT_MAX], t[PA_SW_CVOLUME_SNPRINT_DB_MAX];
+        char s[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
 
         pa_cvolume_set(&cv, 2, v);
 
-        pa_log_debug("Volume: %3i [%s] [%s]", v, pa_cvolume_snprint(s, sizeof(s), &cv), pa_sw_cvolume_snprint_dB(t, sizeof(t), &cv));
+        pa_log_debug("Volume: %3i [%s]", v, pa_cvolume_snprint_verbose(s, sizeof(s), &cv, &map, true));
     }
 
-    map.channels = cv.channels = 2;
-    map.map[0] = PA_CHANNEL_POSITION_LEFT;
-    map.map[1] = PA_CHANNEL_POSITION_RIGHT;
-
     for (cv.values[0] = PA_VOLUME_MUTED; cv.values[0] <= PA_VOLUME_NORM*2; cv.values[0] += 4096)
         for (cv.values[1] = PA_VOLUME_MUTED; cv.values[1] <= PA_VOLUME_NORM*2; cv.values[1] += 4096) {
-            char s[PA_CVOLUME_SNPRINT_MAX];
+            char s[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
 
-            pa_log_debug("Volume: [%s]; balance: %2.1f", pa_cvolume_snprint(s, sizeof(s), &cv), pa_cvolume_get_balance(&cv, &map));
+            pa_log_debug("Volume: [%s]; balance: %2.1f",
+                         pa_cvolume_snprint_verbose(s, sizeof(s), &cv, &map, true),
+                         pa_cvolume_get_balance(&cv, &map));
         }
 
     for (cv.values[0] = PA_VOLUME_MUTED+4096; cv.values[0] <= PA_VOLUME_NORM*2; cv.values[0] += 4096)
         for (cv.values[1] = PA_VOLUME_MUTED; cv.values[1] <= PA_VOLUME_NORM*2; cv.values[1] += 4096)
             for (b = -1.0f; b <= 1.0f; b += 0.2f) {
-                char s[PA_CVOLUME_SNPRINT_MAX];
+                char s[PA_CVOLUME_SNPRINT_VERBOSE_MAX];
                 pa_cvolume r;
                 float k;
 
-                pa_log_debug("Before: volume: [%s]; balance: %2.1f", pa_cvolume_snprint(s, sizeof(s), &cv), pa_cvolume_get_balance(&cv, &map));
+                pa_log_debug("Before: volume: [%s]; balance: %2.1f",
+                             pa_cvolume_snprint_verbose(s, sizeof(s), &cv, &map, true),
+                             pa_cvolume_get_balance(&cv, &map));
 
                 r = cv;
                 pa_cvolume_set_balance(&r, &map,b);
 
                 k = pa_cvolume_get_balance(&r, &map);
-                pa_log_debug("After: volume: [%s]; balance: %2.1f (intended: %2.1f) %s", pa_cvolume_snprint(s, sizeof(s), &r), k, b, k < b-.05 || k > b+.5 ? "MISMATCH" : "");
+                pa_log_debug("After: volume: [%s]; balance: %2.1f (intended: %2.1f) %s",
+                             pa_cvolume_snprint_verbose(s, sizeof(s), &r, &map, true),
+                             k,
+                             b,
+                             k < b - .05 || k > b + .5 ? "MISMATCH" : "");
             }
 
     for (v = PA_VOLUME_MUTED; v <= PA_VOLUME_NORM*2; v += 51) {
diff --git a/src/utils/pactl.c b/src/utils/pactl.c
index 8849b40..b6d943e 100644
--- a/src/utils/pactl.c
+++ b/src/utils/pactl.c
@@ -242,10 +242,8 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
 
     char
         s[PA_SAMPLE_SPEC_SNPRINT_MAX],
-        cv[PA_CVOLUME_SNPRINT_MAX],
-        cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
-        v[PA_VOLUME_SNPRINT_MAX],
-        vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
+        cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX],
+        v[PA_VOLUME_SNPRINT_VERBOSE_MAX],
         cm[PA_CHANNEL_MAP_SNPRINT_MAX],
         f[PA_FORMAT_INFO_SNPRINT_MAX];
     char *pl;
@@ -286,9 +284,9 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
              "\tChannel Map: %s\n"
              "\tOwner Module: %u\n"
              "\tMute: %s\n"
-             "\tVolume: %s%s%s\n"
+             "\tVolume: %s\n"
              "\t        balance %0.2f\n"
-             "\tBase Volume: %s%s%s\n"
+             "\tBase Volume: %s\n"
              "\tMonitor Source: %s\n"
              "\tLatency: %0.0f usec, configured %0.0f usec\n"
              "\tFlags: %s%s%s%s%s%s%s\n"
@@ -302,13 +300,9 @@ static void get_sink_info_callback(pa_context *c, const pa_sink_info *i, int is_
            pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
            i->owner_module,
            pa_yes_no(i->mute),
-           pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
-           i->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t        " : "",
-           i->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume) : "",
+           pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, i->flags & PA_SINK_DECIBEL_VOLUME),
            pa_cvolume_get_balance(&i->volume, &i->channel_map),
-           pa_volume_snprint(v, sizeof(v), i->base_volume),
-           i->flags & PA_SINK_DECIBEL_VOLUME ? "\n\t             " : "",
-           i->flags & PA_SINK_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), i->base_volume) : "",
+           pa_volume_snprint_verbose(v, sizeof(v), i->base_volume, i->flags & PA_SINK_DECIBEL_VOLUME),
            pa_strnull(i->monitor_source_name),
            (double) i->latency, (double) i->configured_latency,
            i->flags & PA_SINK_HARDWARE ? "HARDWARE " : "",
@@ -355,10 +349,8 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
 
     char
         s[PA_SAMPLE_SPEC_SNPRINT_MAX],
-        cv[PA_CVOLUME_SNPRINT_MAX],
-        cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX],
-        v[PA_VOLUME_SNPRINT_MAX],
-        vdb[PA_SW_VOLUME_SNPRINT_DB_MAX],
+        cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX],
+        v[PA_VOLUME_SNPRINT_VERBOSE_MAX],
         cm[PA_CHANNEL_MAP_SNPRINT_MAX],
         f[PA_FORMAT_INFO_SNPRINT_MAX];
     char *pl;
@@ -399,9 +391,9 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
              "\tChannel Map: %s\n"
              "\tOwner Module: %u\n"
              "\tMute: %s\n"
-             "\tVolume: %s%s%s\n"
+             "\tVolume: %s\n"
              "\t        balance %0.2f\n"
-             "\tBase Volume: %s%s%s\n"
+             "\tBase Volume: %s\n"
              "\tMonitor of Sink: %s\n"
              "\tLatency: %0.0f usec, configured %0.0f usec\n"
              "\tFlags: %s%s%s%s%s%s\n"
@@ -415,13 +407,9 @@ static void get_source_info_callback(pa_context *c, const pa_source_info *i, int
            pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map),
            i->owner_module,
            pa_yes_no(i->mute),
-           pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
-           i->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t        " : "",
-           i->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume) : "",
+           pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, i->flags & PA_SOURCE_DECIBEL_VOLUME),
            pa_cvolume_get_balance(&i->volume, &i->channel_map),
-           pa_volume_snprint(v, sizeof(v), i->base_volume),
-           i->flags & PA_SOURCE_DECIBEL_VOLUME ? "\n\t             " : "",
-           i->flags & PA_SOURCE_DECIBEL_VOLUME ? pa_sw_volume_snprint_dB(vdb, sizeof(vdb), i->base_volume) : "",
+           pa_volume_snprint_verbose(v, sizeof(v), i->base_volume, i->flags & PA_SOURCE_DECIBEL_VOLUME),
            i->monitor_of_sink_name ? i->monitor_of_sink_name : _("n/a"),
            (double) i->latency, (double) i->configured_latency,
            i->flags & PA_SOURCE_HARDWARE ? "HARDWARE " : "",
@@ -623,7 +611,7 @@ static void get_card_info_callback(pa_context *c, const pa_card_info *i, int is_
 }
 
 static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info *i, int is_last, void *userdata) {
-    char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], f[PA_FORMAT_INFO_SNPRINT_MAX];
+    char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], f[PA_FORMAT_INFO_SNPRINT_MAX];
     char *pl;
 
     if (is_last < 0) {
@@ -667,7 +655,6 @@ static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info
              "\tCorked: %s\n"
              "\tMute: %s\n"
              "\tVolume: %s\n"
-             "\t        %s\n"
              "\t        balance %0.2f\n"
              "\tBuffer Latency: %0.0f usec\n"
              "\tSink Latency: %0.0f usec\n"
@@ -683,8 +670,7 @@ static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info
            pa_format_info_snprint(f, sizeof(f), i->format),
            pa_yes_no(i->corked),
            pa_yes_no(i->mute),
-           pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
-           pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume),
+           pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, true),
            pa_cvolume_get_balance(&i->volume, &i->channel_map),
            (double) i->buffer_usec,
            (double) i->sink_usec,
@@ -695,7 +681,7 @@ static void get_sink_input_info_callback(pa_context *c, const pa_sink_input_info
 }
 
 static void get_source_output_info_callback(pa_context *c, const pa_source_output_info *i, int is_last, void *userdata) {
-    char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], f[PA_FORMAT_INFO_SNPRINT_MAX];
+    char t[32], k[32], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX], f[PA_FORMAT_INFO_SNPRINT_MAX];
     char *pl;
 
     if (is_last < 0) {
@@ -739,7 +725,6 @@ static void get_source_output_info_callback(pa_context *c, const pa_source_outpu
              "\tCorked: %s\n"
              "\tMute: %s\n"
              "\tVolume: %s\n"
-             "\t        %s\n"
              "\t        balance %0.2f\n"
              "\tBuffer Latency: %0.0f usec\n"
              "\tSource Latency: %0.0f usec\n"
@@ -755,8 +740,7 @@ static void get_source_output_info_callback(pa_context *c, const pa_source_outpu
            pa_format_info_snprint(f, sizeof(f), i->format),
            pa_yes_no(i->corked),
            pa_yes_no(i->mute),
-           pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
-           pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume),
+           pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, true),
            pa_cvolume_get_balance(&i->volume, &i->channel_map),
            (double) i->buffer_usec,
            (double) i->source_usec,
@@ -767,7 +751,7 @@ static void get_source_output_info_callback(pa_context *c, const pa_source_outpu
 }
 
 static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int is_last, void *userdata) {
-    char t[PA_BYTES_SNPRINT_MAX], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_MAX], cvdb[PA_SW_CVOLUME_SNPRINT_DB_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
+    char t[PA_BYTES_SNPRINT_MAX], s[PA_SAMPLE_SPEC_SNPRINT_MAX], cv[PA_CVOLUME_SNPRINT_VERBOSE_MAX], cm[PA_CHANNEL_MAP_SNPRINT_MAX];
     char *pl;
 
     if (is_last < 0) {
@@ -803,7 +787,6 @@ static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int
              "\tSample Specification: %s\n"
              "\tChannel Map: %s\n"
              "\tVolume: %s\n"
-             "\t        %s\n"
              "\t        balance %0.2f\n"
              "\tDuration: %0.1fs\n"
              "\tSize: %s\n"
@@ -814,8 +797,7 @@ static void get_sample_info_callback(pa_context *c, const pa_sample_info *i, int
            i->name,
            pa_sample_spec_valid(&i->sample_spec) ? pa_sample_spec_snprint(s, sizeof(s), &i->sample_spec) : _("n/a"),
            pa_sample_spec_valid(&i->sample_spec) ? pa_channel_map_snprint(cm, sizeof(cm), &i->channel_map) : _("n/a"),
-           pa_cvolume_snprint(cv, sizeof(cv), &i->volume),
-           pa_sw_cvolume_snprint_dB(cvdb, sizeof(cvdb), &i->volume),
+           pa_cvolume_snprint_verbose(cv, sizeof(cv), &i->volume, &i->channel_map, true),
            pa_cvolume_get_balance(&i->volume, &i->channel_map),
            (double) i->duration/1000000.0,
            t,

commit 596b2988a5dcdcc693f1a281ba653d907adf64dc
Author: Tanu Kaskinen <tanuk at iki.fi>
Date:   Wed Apr 3 16:36:42 2013 +0300

    pulse: Add verbose volume printing functions
    
    For more informative logging.

diff --git a/src/map-file b/src/map-file
index 90c8ea2..466c828 100644
--- a/src/map-file
+++ b/src/map-file
@@ -142,6 +142,7 @@ pa_cvolume_set_balance;
 pa_cvolume_set_fade;
 pa_cvolume_set_position;
 pa_cvolume_snprint;
+pa_cvolume_snprint_verbose;
 pa_cvolume_valid;
 pa_encoding_to_string;
 pa_ext_device_manager_delete;
@@ -361,6 +362,7 @@ pa_utf8_filter;
 pa_utf8_to_locale;
 pa_utf8_valid;
 pa_volume_snprint;
+pa_volume_snprint_verbose;
 pa_xfree;
 pa_xmalloc;
 pa_xmalloc0;
diff --git a/src/pulse/volume.c b/src/pulse/volume.c
index d7a86c6..fd67254 100644
--- a/src/pulse/volume.c
+++ b/src/pulse/volume.c
@@ -361,6 +361,48 @@ char *pa_sw_cvolume_snprint_dB(char *s, size_t l, const pa_cvolume *c) {
     return s;
 }
 
+char *pa_cvolume_snprint_verbose(char *s, size_t l, const pa_cvolume *c, const pa_channel_map *map, int print_dB) {
+    char *current = s;
+    bool first = true;
+
+    pa_assert(s);
+    pa_assert(l > 0);
+    pa_assert(c);
+
+    pa_init_i18n();
+
+    if (!pa_cvolume_valid(c)) {
+        pa_snprintf(s, l, _("(invalid)"));
+        return s;
+    }
+
+    pa_assert(!map || (map->channels == c->channels));
+    pa_assert(!map || pa_channel_map_valid(map));
+
+    current[0] = 0;
+
+    for (unsigned channel = 0; channel < c->channels && l > 1; channel++) {
+        char channel_position[32];
+        size_t bytes_printed;
+        char buf[PA_VOLUME_SNPRINT_VERBOSE_MAX];
+
+        if (map)
+            pa_snprintf(channel_position, sizeof(channel_position), "%s", pa_channel_position_to_string(map->map[channel]));
+        else
+            pa_snprintf(channel_position, sizeof(channel_position), "%u", channel);
+
+        bytes_printed = pa_snprintf(current, l, "%s%s: %s",
+                                    first ? "" : ",   ",
+                                    channel_position,
+                                    pa_volume_snprint_verbose(buf, sizeof(buf), c->values[channel], print_dB));
+        l -= bytes_printed;
+        current += bytes_printed;
+        first = false;
+    }
+
+    return s;
+}
+
 char *pa_sw_volume_snprint_dB(char *s, size_t l, pa_volume_t v) {
     double f;
 
@@ -380,6 +422,28 @@ char *pa_sw_volume_snprint_dB(char *s, size_t l, pa_volume_t v) {
     return s;
 }
 
+char *pa_volume_snprint_verbose(char *s, size_t l, pa_volume_t v, int print_dB) {
+    char dB[PA_SW_VOLUME_SNPRINT_DB_MAX];
+
+    pa_assert(s);
+    pa_assert(l > 0);
+
+    pa_init_i18n();
+
+    if (!PA_VOLUME_IS_VALID(v)) {
+        pa_snprintf(s, l, _("(invalid)"));
+        return s;
+    }
+
+    pa_snprintf(s, l, "%" PRIu32 " / %3u%%%s%s",
+                v,
+                (v * 100 + PA_VOLUME_NORM / 2) / PA_VOLUME_NORM,
+                print_dB ? " / " : "",
+                print_dB ? pa_sw_volume_snprint_dB(dB, sizeof(dB), v) : "");
+
+    return s;
+}
+
 int pa_cvolume_channels_equal_to(const pa_cvolume *a, pa_volume_t v) {
     unsigned c;
     pa_assert(a);
diff --git a/src/pulse/volume.h b/src/pulse/volume.h
index 1e1beb4..ab6c59b 100644
--- a/src/pulse/volume.h
+++ b/src/pulse/volume.h
@@ -174,6 +174,18 @@ char *pa_cvolume_snprint(char *s, size_t l, const pa_cvolume *c);
 /** Pretty print a volume structure but show dB values. \since 0.9.13 */
 char *pa_sw_cvolume_snprint_dB(char *s, size_t l, const pa_cvolume *c);
 
+/** Maximum length of the strings returned by pa_cvolume_snprint_verbose().
+ * Please note that this value can change with any release without warning and
+ * without being considered API or ABI breakage. You should not use this
+ * definition anywhere where it might become part of an ABI. \since 5.0 */
+#define PA_CVOLUME_SNPRINT_VERBOSE_MAX 1984
+
+/** Pretty print a volume structure in a verbose way. The volume for each
+ * channel is printed in several formats: the raw pa_volume_t value,
+ * percentage, and if print_dB is non-zero, also the dB value. If map is not
+ * NULL, the channel names will be printed. \since 5.0 */
+char *pa_cvolume_snprint_verbose(char *s, size_t l, const pa_cvolume *c, const pa_channel_map *map, int print_dB);
+
 /** Maximum length of the strings returned by
  * pa_volume_snprint(). Please note that this value can change with
  * any release without warning and without being considered API or ABI
@@ -194,6 +206,17 @@ char *pa_volume_snprint(char *s, size_t l, pa_volume_t v);
 /** Pretty print a volume but show dB values. \since 0.9.15 */
 char *pa_sw_volume_snprint_dB(char *s, size_t l, pa_volume_t v);
 
+/** Maximum length of the strings returned by pa_volume_snprint_verbose().
+ * Please note that this value can change with any release without warning and
+ * withou being considered API or ABI breakage. You should not use this
+ * definition anywhere where it might become part of an ABI. \since 5.0 */
+#define PA_VOLUME_SNPRINT_VERBOSE_MAX 35
+
+/** Pretty print a volume in a verbose way. The volume is printed in several
+ * formats: the raw pa_volume_t value, percentage, and if print_dB is non-zero,
+ * also the dB value. \since 5.0 */
+char *pa_volume_snprint_verbose(char *s, size_t l, pa_volume_t v, int print_dB);
+
 /** Return the average volume of all channels */
 pa_volume_t pa_cvolume_avg(const pa_cvolume *a) PA_GCC_PURE;
 



More information about the pulseaudio-commits mailing list