[pulseaudio-commits] [SCM] PulseAudio Sound Server branch, master, updated. v0.9.15-test7-48-gc523b16

Lennart Poettering gitmailer-noreply at 0pointer.de
Mon Apr 6 19:48:40 PDT 2009


This is an automated email from the git hooks/post-receive script. It was
generated because of a push to the "PulseAudio Sound Server" repository.

The master branch has been updated
      from  e356a03ab2683d81a9725c73e6a58c424646a44f (commit)

- Log -----------------------------------------------------------------
c523b16 after propagating a sink volume change to the sink inputs recalculate their soft volumes
93e14d3 we need to make our multiplications with linear values
02686cc reduce number of conversions to/from linear volumes
d612fbb compare with doubles, not integer
-----------------------------------------------------------------------

Summary of changes:
 src/pulse/volume.c   |    4 +-
 src/pulsecore/sink.c |   88 ++++++++++++++++++++++++++++++++++++-------------
 src/pulsecore/sink.h |    1 +
 3 files changed, 67 insertions(+), 26 deletions(-)

-----------------------------------------------------------------------

commit d612fbb80237c046953c029c55e05b8bb34915cb
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Apr 7 04:02:25 2009 +0200

    compare with doubles, not integer

diff --git a/src/pulse/volume.c b/src/pulse/volume.c
index c865058..9033c32 100644
--- a/src/pulse/volume.c
+++ b/src/pulse/volume.c
@@ -138,7 +138,7 @@ double pa_sw_volume_to_dB(pa_volume_t v) {
 
 pa_volume_t pa_sw_volume_from_linear(double v) {
 
-    if (v <= 0)
+    if (v <= 0.0)
         return PA_VOLUME_MUTED;
 
     if (v > .999 && v < 1.001)
@@ -150,7 +150,7 @@ pa_volume_t pa_sw_volume_from_linear(double v) {
 double pa_sw_volume_to_linear(pa_volume_t v) {
 
     if (v == PA_VOLUME_MUTED)
-        return 0;
+        return 0.0;
 
     return pow(10.0, pa_sw_volume_to_dB(v)/20.0);
 }

commit 02686cce6d56a4438eb7cf2d902ce6e737a7e8b0
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Apr 7 04:04:19 2009 +0200

    reduce number of conversions to/from linear volumes

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 2c5ceac..0e203b6 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -1027,13 +1027,24 @@ void pa_sink_update_flat_volume(pa_sink *s, pa_cvolume *new_volume) {
      * to this sink */
     for (i = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); i; i = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx))) {
         pa_cvolume remapped_new_volume;
+        unsigned c;
 
         /* This basically calculates i->soft_volume := i->virtual_volume / new_volume * i->volume_factor */
 
         remapped_new_volume = *new_volume;
         pa_cvolume_remap(&remapped_new_volume, &s->channel_map, &i->channel_map);
-        pa_sw_cvolume_divide(&i->soft_volume, &i->virtual_volume, &remapped_new_volume);
-        pa_sw_cvolume_multiply(&i->soft_volume, &i->soft_volume, &i->volume_factor);
+
+        for (c = 0; c < i->sample_spec.channels; c++)
+
+            if (remapped_new_volume.values[c] <= PA_VOLUME_MUTED)
+                i->soft_volume.values[c] = PA_VOLUME_MUTED;
+            else
+                i->soft_volume.values[c] = pa_sw_volume_from_linear(
+                        pa_sw_volume_to_linear(i->virtual_volume.values[c]) *
+                        pa_sw_volume_to_linear(i->volume_factor.values[c]) /
+                        pa_sw_volume_to_linear(remapped_new_volume.values[c]));
+
+        i->soft_volume.channels = i->sample_spec.channels;
 
         /* Hooks have the ability to play games with i->soft_volume */
         pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_INPUT_SET_VOLUME], i);

commit 93e14d3e6238abc0bc1f492edb15b9708c7067d6
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Apr 7 04:05:03 2009 +0200

    we need to make our multiplications with linear values

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 0e203b6..43f579a 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -1071,7 +1071,7 @@ void pa_sink_propagate_flat_volume(pa_sink *s, const pa_cvolume *old_volume) {
      * sink input volumes accordingly */
 
     for (i = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); i; i = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx))) {
-        pa_cvolume remapped_old_volume, remapped_new_volume, fixed_volume;
+        pa_cvolume remapped_old_volume, remapped_new_volume, new_virtual_volume;
         unsigned c;
 
         /* This basically calculates i->virtual_volume := i->virtual_volume * s->virtual_volume / old_volume */
@@ -1084,18 +1084,18 @@ void pa_sink_propagate_flat_volume(pa_sink *s, const pa_cvolume *old_volume) {
 
         for (c = 0; c < i->sample_spec.channels; c++)
 
-            if (remapped_old_volume.values[c] == PA_VOLUME_MUTED)
-                fixed_volume.values[c] = remapped_new_volume.values[c];
+            if (remapped_old_volume.values[c] <= PA_VOLUME_MUTED)
+                new_virtual_volume.values[c] = remapped_new_volume.values[c];
             else
-                fixed_volume.values[c] = (pa_volume_t)
-                    ((uint64_t) i->virtual_volume.values[c] *
-                     (uint64_t) remapped_new_volume.values[c] /
-                     (uint64_t) remapped_old_volume.values[c]);
+                new_virtual_volume.values[c] = pa_sw_volume_from_linear(
+                        pa_sw_volume_to_linear(i->virtual_volume.values[c]) *
+                        pa_sw_volume_to_linear(remapped_new_volume.values[c]) /
+                        pa_sw_volume_to_linear(remapped_old_volume.values[c]));
 
-        fixed_volume.channels = i->virtual_volume.channels;
+        new_virtual_volume.channels = i->sample_spec.channels;
 
-        if (!pa_cvolume_equal(&fixed_volume, &i->virtual_volume)) {
-            i->virtual_volume = fixed_volume;
+        if (!pa_cvolume_equal(&new_virtual_volume, &i->virtual_volume)) {
+            i->virtual_volume = new_virtual_volume;
 
             /* The virtual volume changed, let's tell people so */
             pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);

commit c523b16d33a772b59407622c1066e11536f4cfa0
Author: Lennart Poettering <lennart at poettering.net>
Date:   Tue Apr 7 04:47:58 2009 +0200

    after propagating a sink volume change to the sink inputs recalculate their soft volumes

diff --git a/src/pulsecore/sink.c b/src/pulsecore/sink.c
index 43f579a..886402a 100644
--- a/src/pulsecore/sink.c
+++ b/src/pulsecore/sink.c
@@ -984,6 +984,36 @@ pa_usec_t pa_sink_get_latency_within_thread(pa_sink *s) {
     return usec;
 }
 
+static void compute_new_soft_volume(pa_sink_input *i, const pa_cvolume *new_volume) {
+    unsigned c;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert(new_volume->channels == i->sample_spec.channels);
+
+    /* This basically calculates i->soft_volume := i->virtual_volume / new_volume * i->volume_factor */
+
+    /* The new sink volume passed in here must already be remapped to
+     * the sink input's channel map! */
+
+    for (c = 0; c < i->sample_spec.channels; c++)
+
+        if (new_volume->values[c] <= PA_VOLUME_MUTED)
+            i->soft_volume.values[c] = PA_VOLUME_MUTED;
+        else
+            i->soft_volume.values[c] = pa_sw_volume_from_linear(
+                    pa_sw_volume_to_linear(i->virtual_volume.values[c]) *
+                    pa_sw_volume_to_linear(i->volume_factor.values[c]) /
+                    pa_sw_volume_to_linear(new_volume->values[c]));
+
+    i->soft_volume.channels = i->sample_spec.channels;
+
+    /* Hooks have the ability to play games with i->soft_volume */
+    pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_SET_VOLUME], i);
+
+    /* We don't copy the soft_volume to the thread_info data
+     * here. That must be done by the caller */
+}
+
 /* Called from main thread */
 void pa_sink_update_flat_volume(pa_sink *s, pa_cvolume *new_volume) {
     pa_sink_input *i;
@@ -998,7 +1028,7 @@ void pa_sink_update_flat_volume(pa_sink *s, pa_cvolume *new_volume) {
      * might need to fix up the sink volume accordingly. Please note
      * that we don't actually update the sinks volume here, we only
      * return how it needs to be updated. The caller should then call
-     * pa_sink_set_flat_volume().*/
+     * pa_sink_set_volume().*/
 
     if (pa_idxset_isempty(s->inputs)) {
         /* In the special case that we have no sink input we leave the
@@ -1027,32 +1057,16 @@ void pa_sink_update_flat_volume(pa_sink *s, pa_cvolume *new_volume) {
      * to this sink */
     for (i = PA_SINK_INPUT(pa_idxset_first(s->inputs, &idx)); i; i = PA_SINK_INPUT(pa_idxset_next(s->inputs, &idx))) {
         pa_cvolume remapped_new_volume;
-        unsigned c;
-
-        /* This basically calculates i->soft_volume := i->virtual_volume / new_volume * i->volume_factor */
 
         remapped_new_volume = *new_volume;
         pa_cvolume_remap(&remapped_new_volume, &s->channel_map, &i->channel_map);
+        compute_new_soft_volume(i, &remapped_new_volume);
 
-        for (c = 0; c < i->sample_spec.channels; c++)
-
-            if (remapped_new_volume.values[c] <= PA_VOLUME_MUTED)
-                i->soft_volume.values[c] = PA_VOLUME_MUTED;
-            else
-                i->soft_volume.values[c] = pa_sw_volume_from_linear(
-                        pa_sw_volume_to_linear(i->virtual_volume.values[c]) *
-                        pa_sw_volume_to_linear(i->volume_factor.values[c]) /
-                        pa_sw_volume_to_linear(remapped_new_volume.values[c]));
-
-        i->soft_volume.channels = i->sample_spec.channels;
-
-        /* Hooks have the ability to play games with i->soft_volume */
-        pa_hook_fire(&s->core->hooks[PA_CORE_HOOK_SINK_INPUT_SET_VOLUME], i);
-
-        /* We don't issue PA_SINK_INPUT_MESSAGE_SET_VOLUME because
-         * we want the update to have atomically with the sink
-         * volume update, hence we do it within the
-         * pa_sink_set_flat_volume() call below */
+        /* We don't copy soft_volume to the thread_info data here
+         * (i.e. issue PA_SINK_INPUT_MESSAGE_SET_VOLUME) because we
+         * want the update to be atomically with the sink volume
+         * update, hence we do it within the pa_sink_set_volume() call
+         * below */
     }
 }
 
@@ -1097,10 +1111,21 @@ void pa_sink_propagate_flat_volume(pa_sink *s, const pa_cvolume *old_volume) {
         if (!pa_cvolume_equal(&new_virtual_volume, &i->virtual_volume)) {
             i->virtual_volume = new_virtual_volume;
 
+            /* Hmm, the soft volume might no longer actually match
+             * what has been chosen as new virtual volume here,
+             * especially when the old volume was
+             * PA_VOLUME_MUTED. Hence let's recalculate the soft
+             * volumes here. */
+            compute_new_soft_volume(i, &remapped_new_volume);
+
             /* The virtual volume changed, let's tell people so */
             pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
         }
     }
+
+    /* If the soft_volume of any of the sink inputs got changed, let's
+     * make sure the thread copies are synced up. */
+    pa_assert_se(pa_asyncmsgq_send(s->asyncmsgq, PA_MSGOBJECT(s), PA_SINK_MESSAGE_SYNC_VOLUMES, NULL, 0, NULL) == 0);
 }
 
 /* Called from main thread */
@@ -1580,9 +1605,13 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
                 pa_sink_request_rewind(s, (size_t) -1);
             }
 
-            if (s->flags & PA_SINK_FLAT_VOLUME)
-                sync_input_volumes_within_thread(s);
+            if (!(s->flags & PA_SINK_FLAT_VOLUME))
+                return 0;
+
+            /* Fall through ... */
 
+        case PA_SINK_MESSAGE_SYNC_VOLUMES:
+            sync_input_volumes_within_thread(s);
             return 0;
 
         case PA_SINK_MESSAGE_GET_VOLUME:
diff --git a/src/pulsecore/sink.h b/src/pulsecore/sink.h
index 634bf3e..eb1c88f 100644
--- a/src/pulsecore/sink.h
+++ b/src/pulsecore/sink.h
@@ -159,6 +159,7 @@ typedef enum pa_sink_message {
     PA_SINK_MESSAGE_REMOVE_INPUT,
     PA_SINK_MESSAGE_GET_VOLUME,
     PA_SINK_MESSAGE_SET_VOLUME,
+    PA_SINK_MESSAGE_SYNC_VOLUMES,
     PA_SINK_MESSAGE_GET_MUTE,
     PA_SINK_MESSAGE_SET_MUTE,
     PA_SINK_MESSAGE_GET_LATENCY,

-- 
hooks/post-receive
PulseAudio Sound Server



More information about the pulseaudio-commits mailing list