]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/sink-input.c
Revert "Add volume ramping feature - sink-input modification"
[pulseaudio] / src / pulsecore / sink-input.c
index 283d0265de0ecf775b843e8a146c6fa18263d228..e0831f65d7a5834ee2ddc79ce45913bb9bf3414c 100644 (file)
@@ -38,7 +38,6 @@
 #include <pulsecore/play-memblockq.h>
 #include <pulsecore/namereg.h>
 #include <pulsecore/core-util.h>
-#include <pulse/timeval.h>
 
 #include "sink-input.h"
 
@@ -49,11 +48,6 @@ PA_DEFINE_PUBLIC_CLASS(pa_sink_input, pa_msgobject);
 
 static void sink_input_free(pa_object *o);
 static void set_real_ratio(pa_sink_input *i, const pa_cvolume *v);
-static void sink_input_set_ramping_info(pa_sink_input* i, pa_volume_t  pre_virtual_volume, pa_volume_t target_virtual_volume, pa_usec_t t);
-static void sink_input_set_ramping_info_for_mute(pa_sink_input* i, pa_bool_t mute, pa_usec_t t);
-static void sink_input_volume_ramping(pa_sink_input* i, pa_memchunk* chunk);
-static void sink_input_rewind_ramp_info(pa_sink_input *i, size_t nbytes);
-static void sink_input_release_envelope(pa_sink_input *i);
 
 static int check_passthrough_connection(pa_sink_input_flags_t flags, pa_sink *dest) {
 
@@ -115,7 +109,13 @@ void pa_sink_input_new_data_set_channel_map(pa_sink_input_new_data *data, const
 pa_bool_t pa_sink_input_new_data_is_volume_writable(pa_sink_input_new_data *data) {
     pa_assert(data);
 
-    return !(data->flags & PA_SINK_INPUT_PASSTHROUGH);
+    if (data->flags & PA_SINK_INPUT_PASSTHROUGH)
+        return FALSE;
+
+    if (data->origin_sink && (data->origin_sink->flags & PA_SINK_SHARE_VOLUME_WITH_MASTER))
+        return FALSE;
+
+    return TRUE;
 }
 
 void pa_sink_input_new_data_set_volume(pa_sink_input_new_data *data, const pa_cvolume *volume) {
@@ -337,7 +337,7 @@ int pa_sink_input_new(
     i->sample_spec = data->sample_spec;
     i->channel_map = data->channel_map;
 
-    if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !data->volume_is_absolute) {
+    if (!data->volume_is_absolute && pa_sink_flat_volume_enabled(i->sink)) {
         pa_cvolume remapped;
 
         /* When the 'absolute' bool is not set then we'll treat the volume
@@ -374,16 +374,6 @@ int pa_sink_input_new(
     reset_callbacks(i);
     i->userdata = NULL;
 
-    /* Set Ramping info */
-    i->thread_info.ramp_info.is_ramping = FALSE;
-    i->thread_info.ramp_info.envelope_dead = TRUE;
-    i->thread_info.ramp_info.envelope = NULL;
-    i->thread_info.ramp_info.item = NULL;
-    i->thread_info.ramp_info.envelope_dying = 0;
-
-    pa_atomic_store(&i->before_ramping_v, 0);
-    pa_atomic_store(&i->before_ramping_m, 0);
-
     i->thread_info.state = i->state;
     i->thread_info.attached = FALSE;
     pa_atomic_store(&i->thread_info.drained, 1);
@@ -532,7 +522,7 @@ void pa_sink_input_unlink(pa_sink_input *i) {
 
     if (linked && i->sink) {
         /* We might need to update the sink's volume if we are in flat volume mode. */
-        if (i->sink->flags & PA_SINK_FLAT_VOLUME)
+        if (pa_sink_flat_volume_enabled(i->sink))
             pa_sink_set_volume(i->sink, NULL, FALSE, FALSE);
 
         if (i->sink->asyncmsgq)
@@ -574,12 +564,6 @@ static void sink_input_free(pa_object *o) {
      * "half-moved" or are connected to sinks that have no asyncmsgq
      * and are hence half-destructed themselves! */
 
-    if (i->thread_info.ramp_info.envelope) {
-        pa_log_debug ("Freeing envelope\n");
-        pa_envelope_free(i->thread_info.ramp_info.envelope);
-        i->thread_info.ramp_info.envelope = NULL;
-    }
-
     if (i->thread_info.render_memblockq)
         pa_memblockq_free(i->thread_info.render_memblockq);
 
@@ -619,10 +603,16 @@ void pa_sink_input_put(pa_sink_input *i) {
     i->state = state;
 
     /* We might need to update the sink's volume if we are in flat volume mode. */
-    if (i->sink->flags & PA_SINK_FLAT_VOLUME)
+    if (pa_sink_flat_volume_enabled(i->sink))
         pa_sink_set_volume(i->sink, NULL, FALSE, i->save_volume);
-    else
+    else {
+        if (i->origin_sink && (i->origin_sink->flags & PA_SINK_SHARE_VOLUME_WITH_MASTER)) {
+            pa_assert(pa_cvolume_is_norm(&i->volume));
+            pa_assert(pa_cvolume_is_norm(&i->reference_ratio));
+        }
+
         set_real_ratio(i, &i->volume);
+    }
 
     i->thread_info.soft_volume = i->soft_volume;
     i->thread_info.muted = i->muted;
@@ -667,7 +657,6 @@ pa_usec_t pa_sink_input_get_latency(pa_sink_input *i, pa_usec_t *sink_latency) {
 void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, pa_memchunk *chunk, pa_cvolume *volume) {
     pa_bool_t do_volume_adj_here, need_volume_factor_sink;
     pa_bool_t volume_is_norm;
-    pa_bool_t ramping;
     size_t block_size_max_sink, block_size_max_sink_input;
     size_t ilength;
 
@@ -712,7 +701,7 @@ void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, p
      * to adjust the volume *before* we resample. Otherwise we can do
      * it after and leave it for the sink code */
 
-    do_volume_adj_here = !pa_channel_map_equal(&i->channel_map, &i->sink->channel_map) || i->thread_info.ramp_info.is_ramping;
+    do_volume_adj_here = !pa_channel_map_equal(&i->channel_map, &i->sink->channel_map);
     volume_is_norm = pa_cvolume_is_norm(&i->thread_info.soft_volume) && !i->thread_info.muted;
     need_volume_factor_sink = !pa_cvolume_is_norm(&i->volume_factor_sink);
 
@@ -755,7 +744,7 @@ void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, p
                 wchunk.length = block_size_max_sink_input;
 
             /* It might be necessary to adjust the volume here */
-            if (do_volume_adj_here && !volume_is_norm && !i->thread_info.ramp_info.is_ramping) {
+            if (do_volume_adj_here && !volume_is_norm) {
                 pa_memchunk_make_writable(&wchunk, 0);
 
                 if (i->thread_info.muted) {
@@ -821,23 +810,6 @@ void pa_sink_input_peek(pa_sink_input *i, size_t slength /* in sink frames */, p
     if (chunk->length > block_size_max_sink)
         chunk->length = block_size_max_sink;
 
-    ramping = i->thread_info.ramp_info.is_ramping;
-    if (ramping)
-        sink_input_volume_ramping(i, chunk);
-
-    if (!i->thread_info.ramp_info.envelope_dead) {
-        i->thread_info.ramp_info.envelope_dying += chunk->length;
-        pa_log_debug("Envelope dying is %d, chunk length is %zu, dead thresholder is %lu\n", i->thread_info.ramp_info.envelope_dying,
-                chunk->length,
-                i->sink->thread_info.max_rewind + pa_envelope_length(i->thread_info.ramp_info.envelope));
-
-        if (i->thread_info.ramp_info.envelope_dying >= (int32_t) (i->sink->thread_info.max_rewind + pa_envelope_length(i->thread_info.ramp_info.envelope))) {
-            pa_log_debug("RELEASE Envelop");
-            i->thread_info.ramp_info.envelope_dead = TRUE;
-            sink_input_release_envelope(i);
-        }
-    }
-
     /* Let's see if we had to apply the volume adjustment ourselves,
      * or if this can be done by the sink for us */
 
@@ -882,7 +854,6 @@ void pa_sink_input_process_rewind(pa_sink_input *i, size_t nbytes /* in sink sam
     if (nbytes > 0 && !i->thread_info.dont_rewind_render) {
         pa_log_debug("Have to rewind %lu bytes on render memblockq.", (unsigned long) nbytes);
         pa_memblockq_rewind(i->thread_info.render_memblockq, nbytes);
-        sink_input_rewind_ramp_info(i, nbytes);
     }
 
     if (i->thread_info.rewrite_nbytes == (size_t) -1) {
@@ -1045,6 +1016,64 @@ pa_usec_t pa_sink_input_get_requested_latency(pa_sink_input *i) {
     return i->thread_info.requested_sink_latency;
 }
 
+/* Called from main context */
+void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute) {
+    pa_cvolume v;
+
+    pa_sink_input_assert_ref(i);
+    pa_assert_ctl_context();
+    pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
+    pa_assert(volume);
+    pa_assert(pa_cvolume_valid(volume));
+    pa_assert(volume->channels == 1 || pa_cvolume_compatible(volume, &i->sample_spec));
+    pa_assert(pa_sink_input_is_volume_writable(i));
+
+    if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !absolute) {
+        v = i->sink->reference_volume;
+        pa_cvolume_remap(&v, &i->sink->channel_map, &i->channel_map);
+
+        if (pa_cvolume_compatible(volume, &i->sample_spec))
+            volume = pa_sw_cvolume_multiply(&v, &v, volume);
+        else
+            volume = pa_sw_cvolume_multiply_scalar(&v, &v, pa_cvolume_max(volume));
+    } else {
+        if (!pa_cvolume_compatible(volume, &i->sample_spec)) {
+            v = i->volume;
+            volume = pa_cvolume_scale(&v, pa_cvolume_max(volume));
+        }
+    }
+
+    if (pa_cvolume_equal(volume, &i->volume)) {
+        i->save_volume = i->save_volume || save;
+        return;
+    }
+
+    i->volume = *volume;
+    i->save_volume = save;
+
+    if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
+        /* We are in flat volume mode, so let's update all sink input
+         * volumes and update the flat volume of the sink */
+
+        pa_sink_set_volume(i->sink, NULL, TRUE, save);
+
+    } else {
+        /* OK, we are in normal volume mode. The volume only affects
+         * ourselves */
+        set_real_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);
+    }
+
+    /* The volume changed, let's tell people so */
+    if (i->volume_changed)
+        i->volume_changed(i);
+
+    /* 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);
+}
+
 /* Called from main context */
 static void set_real_ratio(pa_sink_input *i, const pa_cvolume *v) {
     pa_sink_input_assert_ref(i);
@@ -1079,13 +1108,13 @@ pa_bool_t pa_sink_input_is_volume_writable(pa_sink_input *i) {
     pa_sink_input_assert_ref(i);
     pa_assert_ctl_context();
 
-    return !(i->flags & PA_SINK_INPUT_PASSTHROUGH);
-}
+    if (i->flags & PA_SINK_INPUT_PASSTHROUGH)
+        return FALSE;
 
-/* Called from main context */
-void pa_sink_input_set_volume(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute) {
-    /* test ramping -> return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 2000 * PA_USEC_PER_MSEC); */
-    return pa_sink_input_set_volume_with_ramping(i, volume, save, absolute, 0);
+    if (i->origin_sink && (i->origin_sink->flags & PA_SINK_SHARE_VOLUME_WITH_MASTER))
+        return FALSE;
+
+    return TRUE;
 }
 
 /* Called from main context */
@@ -1095,7 +1124,7 @@ pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i, pa_cvolume *volume, pa_bo
     pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
     pa_assert(pa_sink_input_is_volume_readable(i));
 
-    if (absolute || !(i->sink->flags & PA_SINK_FLAT_VOLUME))
+    if (absolute || !pa_sink_flat_volume_enabled(i->sink))
         *volume = i->volume;
     else
         *volume = i->reference_ratio;
@@ -1105,8 +1134,25 @@ pa_cvolume *pa_sink_input_get_volume(pa_sink_input *i, pa_cvolume *volume, pa_bo
 
 /* Called from main context */
 void pa_sink_input_set_mute(pa_sink_input *i, pa_bool_t mute, pa_bool_t save) {
-    /* test ramping -> return pa_sink_input_set_mute_with_ramping(i, mute, save, 2000 * PA_USEC_PER_MSEC); */
-    return pa_sink_input_set_mute_with_ramping(i, mute, save, 0);
+    pa_sink_input_assert_ref(i);
+    pa_assert_ctl_context();
+    pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
+
+    if (!i->muted == !mute) {
+        i->save_muted = i->save_muted || mute;
+        return;
+    }
+
+    i->muted = mute;
+    i->save_muted = save;
+
+    pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE, NULL, 0, NULL) == 0);
+
+    /* The mute status changed, let's tell people so */
+    if (i->mute_changed)
+        i->mute_changed(i);
+
+    pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
 }
 
 /* Called from main context */
@@ -1266,7 +1312,7 @@ int pa_sink_input_start_move(pa_sink_input *i) {
     if (pa_sink_input_get_state(i) == PA_SINK_INPUT_CORKED)
         pa_assert_se(i->sink->n_corked-- >= 1);
 
-    if (i->sink->flags & PA_SINK_FLAT_VOLUME)
+    if (pa_sink_flat_volume_enabled(i->sink))
         /* We might need to update the sink's volume if we are in flat
          * volume mode. */
         pa_sink_set_volume(i->sink, NULL, FALSE, FALSE);
@@ -1282,6 +1328,156 @@ int pa_sink_input_start_move(pa_sink_input *i) {
     return 0;
 }
 
+/* Called from main context. If i has an origin sink that uses volume sharing,
+ * then also the origin sink and all streams connected to it need to update
+ * their volume - this function does all that by using recursion. */
+static void update_volume_due_to_moving(pa_sink_input *i, pa_sink *dest) {
+    pa_cvolume old_volume;
+
+    pa_assert(i);
+    pa_assert(dest);
+    pa_assert(i->sink); /* The destination sink should already be set. */
+
+    if (i->origin_sink && (i->origin_sink->flags & PA_SINK_SHARE_VOLUME_WITH_MASTER)) {
+        pa_sink *root_sink = i->sink;
+        pa_sink_input *origin_sink_input;
+        uint32_t idx;
+
+        while (root_sink->flags & PA_SINK_SHARE_VOLUME_WITH_MASTER)
+            root_sink = root_sink->input_to_master->sink;
+
+        if (pa_sink_flat_volume_enabled(i->sink)) {
+            /* Ok, so the origin sink uses volume sharing, and flat volume is
+             * enabled. The volume will have to be updated as follows:
+             *
+             *     i->volume := i->sink->real_volume
+             *         (handled later by pa_sink_set_volume)
+             *     i->reference_ratio := i->volume / i->sink->reference_volume
+             *         (handled later by pa_sink_set_volume)
+             *     i->real_ratio stays unchanged
+             *         (streams whose origin sink uses volume sharing should
+             *          always have real_ratio of 0 dB)
+             *     i->soft_volume stays unchanged
+             *         (streams whose origin sink uses volume sharing should
+             *          always have volume_factor as soft_volume, so no change
+             *          should be needed) */
+
+            pa_assert(pa_cvolume_is_norm(&i->real_ratio));
+            pa_assert(pa_cvolume_equal(&i->soft_volume, &i->volume_factor));
+
+            /* Notifications will be sent by pa_sink_set_volume(). */
+
+        } else {
+            /* Ok, so the origin sink uses volume sharing, and flat volume is
+             * disabled. The volume will have to be updated as follows:
+             *
+             *     i->volume := 0 dB
+             *     i->reference_ratio := 0 dB
+             *     i->real_ratio stays unchanged
+             *         (streams whose origin sink uses volume sharing should
+             *          always have real_ratio of 0 dB)
+             *     i->soft_volume stays unchanged
+             *         (streams whose origin sink uses volume sharing should
+             *          always have volume_factor as soft_volume, so no change
+             *          should be needed) */
+
+            old_volume = i->volume;
+            pa_cvolume_reset(&i->volume, i->volume.channels);
+            pa_cvolume_reset(&i->reference_ratio, i->reference_ratio.channels);
+            pa_assert(pa_cvolume_is_norm(&i->real_ratio));
+            pa_assert(pa_cvolume_equal(&i->soft_volume, &i->volume_factor));
+
+            /* Notify others about the changed sink input volume. */
+            if (!pa_cvolume_equal(&i->volume, &old_volume)) {
+                if (i->volume_changed)
+                    i->volume_changed(i);
+
+                pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+            }
+        }
+
+        /* Additionally, the origin sink volume needs updating:
+         *
+         *     i->origin_sink->reference_volume := root_sink->reference_volume
+         *     i->origin_sink->real_volume := root_sink->real_volume
+         *     i->origin_sink->soft_volume stays unchanged
+         *         (sinks that use volume sharing should always have
+         *          soft_volume of 0 dB) */
+
+        old_volume = i->origin_sink->reference_volume;
+
+        i->origin_sink->reference_volume = root_sink->reference_volume;
+        pa_cvolume_remap(&i->origin_sink->reference_volume, &root_sink->channel_map, &i->origin_sink->channel_map);
+
+        i->origin_sink->real_volume = root_sink->real_volume;
+        pa_cvolume_remap(&i->origin_sink->real_volume, &root_sink->channel_map, &i->origin_sink->channel_map);
+
+        pa_assert(pa_cvolume_is_norm(&i->origin_sink->soft_volume));
+
+        /* Notify others about the changed sink volume. If you wonder whether
+         * i->origin_sink->set_volume() should be called somewhere, that's not
+         * the case, because sinks that use volume sharing shouldn't have any
+         * internal volume that set_volume() would update. If you wonder
+         * whether the thread_info variables should be synced, yes, they
+         * should, and it's done by the PA_SINK_MESSAGE_FINISH_MOVE message
+         * handler. */
+        if (!pa_cvolume_equal(&i->origin_sink->reference_volume, &old_volume))
+            pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK|PA_SUBSCRIPTION_EVENT_CHANGE, i->origin_sink->index);
+
+        /* Recursively update origin sink inputs. */
+        PA_IDXSET_FOREACH(origin_sink_input, i->origin_sink->inputs, idx)
+            update_volume_due_to_moving(origin_sink_input, dest);
+
+    } else {
+        old_volume = i->volume;
+
+        if (pa_sink_flat_volume_enabled(i->sink)) {
+            /* Ok, so this is a regular stream, and flat volume is enabled. The
+             * volume will have to be updated as follows:
+             *
+             *     i->volume := i->reference_ratio * i->sink->reference_volume
+             *     i->reference_ratio stays unchanged
+             *     i->real_ratio := i->volume / i->sink->real_volume
+             *         (handled later by pa_sink_set_volume)
+             *     i->soft_volume := i->real_ratio * i->volume_factor
+             *         (handled later by pa_sink_set_volume) */
+
+            i->volume = i->sink->reference_volume;
+            pa_cvolume_remap(&i->volume, &i->sink->channel_map, &i->channel_map);
+            pa_sw_cvolume_multiply(&i->volume, &i->volume, &i->reference_ratio);
+
+        } else {
+            /* Ok, so this is a regular stream, and flat volume is disabled.
+             * The volume will have to be updated as follows:
+             *
+             *     i->volume := i->reference_ratio
+             *     i->reference_ratio stays unchanged
+             *     i->real_ratio := i->reference_ratio
+             *     i->soft_volume := i->real_ratio * i->volume_factor */
+
+            i->volume = i->reference_ratio;
+            i->real_ratio = i->reference_ratio;
+            pa_sw_cvolume_multiply(&i->soft_volume, &i->real_ratio, &i->volume_factor);
+        }
+
+        /* Notify others about the changed sink input volume. */
+        if (!pa_cvolume_equal(&i->volume, &old_volume)) {
+            /* XXX: In case i->sink has flat volume enabled, then real_ratio
+             * and soft_volume are not updated yet. Let's hope that the
+             * callback implementation doesn't care about those variables... */
+            if (i->volume_changed)
+                i->volume_changed(i);
+
+            pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
+        }
+    }
+
+    /* If i->sink == dest, then recursion has finished, and we can finally call
+     * pa_sink_set_volume(), which will do the rest of the updates. */
+    if ((i->sink == dest) && pa_sink_flat_volume_enabled(i->sink))
+        pa_sink_set_volume(i->sink, NULL, FALSE, i->save_volume);
+}
+
 /* Called from main context */
 int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
     pa_resampler *new_resampler;
@@ -1355,17 +1551,7 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
     }
     pa_sink_update_status(dest);
 
-    if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
-        pa_cvolume remapped;
-
-        /* Make relative volumes absolute */
-        remapped = dest->reference_volume;
-        pa_cvolume_remap(&remapped, &dest->channel_map, &i->channel_map);
-        pa_sw_cvolume_multiply(&i->volume, &i->reference_ratio, &remapped);
-
-        /* We might need to update the sink's volume if we are in flat volume mode. */
-        pa_sink_set_volume(i->sink, NULL, FALSE, i->save_volume);
-    }
+    update_volume_due_to_moving(i, dest);
 
     pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i->sink), PA_SINK_MESSAGE_FINISH_MOVE, i, 0, NULL) == 0);
 
@@ -1374,9 +1560,6 @@ int pa_sink_input_finish_move(pa_sink_input *i, pa_sink *dest, pa_bool_t save) {
     /* Notify everyone */
     pa_hook_fire(&i->core->hooks[PA_CORE_HOOK_SINK_INPUT_MOVE_FINISH], i);
 
-    if (i->volume_changed)
-        i->volume_changed(i);
-
     pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
 
     return 0;
@@ -1485,23 +1668,15 @@ int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t
     switch (code) {
 
         case PA_SINK_INPUT_MESSAGE_SET_SOFT_VOLUME:
-            if (pa_atomic_load(&i->before_ramping_v))
-                i->thread_info.future_soft_volume = i->soft_volume;
-
             if (!pa_cvolume_equal(&i->thread_info.soft_volume, &i->soft_volume)) {
-                if (!pa_atomic_load(&i->before_ramping_v))
-                    i->thread_info.soft_volume = i->soft_volume;
+                i->thread_info.soft_volume = i->soft_volume;
                 pa_sink_input_request_rewind(i, 0, TRUE, FALSE, FALSE);
             }
             return 0;
 
         case PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE:
-            if (pa_atomic_load(&i->before_ramping_m))
-                i->thread_info.future_muted = i->muted;
-
             if (i->thread_info.muted != i->muted) {
-                if (!pa_atomic_load(&i->before_ramping_m))
-                    i->thread_info.muted = i->muted;
+                i->thread_info.muted = i->muted;
                 pa_sink_input_request_rewind(i, 0, TRUE, FALSE, FALSE);
             }
             return 0;
@@ -1549,26 +1724,6 @@ int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t
             *r = i->thread_info.requested_sink_latency;
             return 0;
         }
-
-        case PA_SINK_INPUT_MESSAGE_SET_ENVELOPE: {
-            if (!i->thread_info.ramp_info.envelope)
-                i->thread_info.ramp_info.envelope = pa_envelope_new(&i->sink->sample_spec);
-
-            if (i->thread_info.ramp_info.envelope && i->thread_info.ramp_info.item) {
-                pa_envelope_remove(i->thread_info.ramp_info.envelope, i->thread_info.ramp_info.item);
-                i->thread_info.ramp_info.item = NULL;
-            }
-
-            i->thread_info.ramp_info.item = pa_envelope_add(i->thread_info.ramp_info.envelope, &i->using_def);
-            i->thread_info.ramp_info.is_ramping = TRUE;
-            i->thread_info.ramp_info.envelope_dead = FALSE;
-            i->thread_info.ramp_info.envelope_dying = 0;
-
-            if (i->thread_info.ramp_info.envelope)
-                pa_envelope_restart(i->thread_info.ramp_info.envelope);
-
-            return 0;
-        }
     }
 
     return -PA_ERR_NOTIMPLEMENTED;
@@ -1731,238 +1886,3 @@ finish:
     if (pl)
         pa_proplist_free(pl);
 }
-
-/* Called from IO context */
-static void sink_input_volume_ramping(pa_sink_input* i, pa_memchunk* chunk) {
-    pa_assert(i);
-    pa_assert(chunk);
-    pa_assert(chunk->memblock);
-    pa_assert(i->thread_info.ramp_info.is_ramping);
-
-    /* Volume is adjusted with ramping effect here */
-    pa_envelope_apply(i->thread_info.ramp_info.envelope, chunk);
-
-    if (pa_envelope_is_finished(i->thread_info.ramp_info.envelope)) {
-        i->thread_info.ramp_info.is_ramping = FALSE;
-        if (pa_atomic_load(&i->before_ramping_v)) {
-            i->thread_info.soft_volume = i->thread_info.future_soft_volume;
-            pa_atomic_store(&i->before_ramping_v, 0);
-        }
-        else if (pa_atomic_load(&i->before_ramping_m)) {
-            i->thread_info.muted = i->thread_info.future_muted;
-            pa_atomic_store(&i->before_ramping_m, 0);
-        }
-    }
-}
-
-/*
- * Called from main context
- * This function should be called inside pa_sink_input_set_volume_with_ramping
- * should be called after soft_volume of sink_input and sink are all adjusted
- */
-static void sink_input_set_ramping_info(pa_sink_input* i, pa_volume_t  pre_virtual_volume, pa_volume_t target_virtual_volume, pa_usec_t t) {
-
-    int32_t target_abs_vol, target_apply_vol, pre_apply_vol;
-    pa_assert(i);
-
-    pa_log_debug("Sink input's soft volume is %d= %f ", pa_cvolume_avg(&i->soft_volume), pa_sw_volume_to_linear(pa_cvolume_avg(&i->soft_volume)));
-
-    /* Calculation formula are target_abs_vol := i->soft_volume
-     *                                   target_apply_vol := lrint(pa_sw_volume_to_linear(target_abs_vol) * 0x10000)
-     *                                   pre_apply_vol := ( previous_virtual_volume / target_virtual_volume ) * target_apply_vol
-     *
-     * Will do volume adjustment inside pa_sink_input_peek
-     */
-    target_abs_vol = pa_cvolume_avg(&i->soft_volume);
-    target_apply_vol = (int32_t) lrint(pa_sw_volume_to_linear(target_abs_vol) * 0x10000);
-    pre_apply_vol = (int32_t) ((pa_sw_volume_to_linear(pre_virtual_volume) / pa_sw_volume_to_linear(target_virtual_volume)) * target_apply_vol);
-
-    i->using_def.n_points = 2;
-    i->using_def.points_x[0] = 0;
-    i->using_def.points_x[1] = t;
-    i->using_def.points_y.i[0] = pre_apply_vol;
-    i->using_def.points_y.i[1] = target_apply_vol;
-    i->using_def.points_y.f[0] = ((float) i->using_def.points_y.i[0]) /0x10000;
-    i->using_def.points_y.f[1] = ((float) i->using_def.points_y.i[1]) /0x10000;
-
-    pa_log_debug("Volume Ramping: Point 1 is %d=%f, Point 2 is %d=%f\n", i->using_def.points_y.i[0], i->using_def.points_y.f[0],
-                                   i->using_def.points_y.i[1], i->using_def.points_y.f[1]);
-
-    pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_ENVELOPE, NULL, 0, NULL) == 0);
-}
-
-/* Called from main context */
-static void sink_input_set_ramping_info_for_mute(pa_sink_input* i, pa_bool_t mute, pa_usec_t t) {
-
-    int32_t cur_vol;
-    pa_assert(i);
-
-    i->using_def.n_points = 2;
-    i->using_def.points_x[0] = 0;
-    i->using_def.points_x[1] = t;
-    cur_vol = (int32_t) lrint( pa_sw_volume_to_linear(pa_cvolume_avg(&i->soft_volume)) * 0x10000);
-
-    if (mute) {
-        i->using_def.points_y.i[0] = cur_vol;
-        i->using_def.points_y.i[1] = 0;
-    } else {
-        i->using_def.points_y.i[0] = 0;
-        i->using_def.points_y.i[1] = cur_vol;
-    }
-
-    i->using_def.points_y.f[0] = ((float) i->using_def.points_y.i[0]) /0x10000;
-    i->using_def.points_y.f[1] = ((float) i->using_def.points_y.i[1]) /0x10000;
-
-    pa_log_debug("Mute Ramping: Point 1 is %d=%f, Point 2 is %d=%f\n", i->using_def.points_y.i[0], i->using_def.points_y.f[0],
-                   i->using_def.points_y.i[1], i->using_def.points_y.f[1]);
-
-    pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_ENVELOPE, NULL, 0, NULL) == 0);
-}
-
-/* Called from IO context */
-static void sink_input_release_envelope(pa_sink_input *i) {
-    pa_assert(i);
-    pa_assert(!i->thread_info.ramp_info.is_ramping);
-    pa_assert(i->thread_info.ramp_info.envelope_dead);
-
-    pa_envelope_free(i->thread_info.ramp_info.envelope);
-    i->thread_info.ramp_info.envelope = NULL;
-    i->thread_info.ramp_info.item = NULL;
-}
-
-/* Called from IO context */
-static void sink_input_rewind_ramp_info(pa_sink_input *i, size_t nbytes) {
-    pa_assert(i);
-
-    if (!i->thread_info.ramp_info.envelope_dead) {
-        int32_t envelope_length;
-
-        pa_assert(i->thread_info.ramp_info.envelope);
-
-        envelope_length = pa_envelope_length(i->thread_info.ramp_info.envelope);
-
-        if (i->thread_info.ramp_info.envelope_dying > envelope_length) {
-            if ((int32_t) (i->thread_info.ramp_info.envelope_dying - nbytes) < envelope_length) {
-                pa_log_debug("Envelope Become Alive");
-                pa_envelope_rewind(i->thread_info.ramp_info.envelope, envelope_length - (i->thread_info.ramp_info.envelope_dying - nbytes));
-                i->thread_info.ramp_info.is_ramping = TRUE;
-            }
-        } else if (i->thread_info.ramp_info.envelope_dying < envelope_length) {
-            if ((i->thread_info.ramp_info.envelope_dying - (ssize_t) nbytes) <= 0) {
-                pa_log_debug("Envelope Restart");
-                pa_envelope_restart(i->thread_info.ramp_info.envelope);
-            }
-            else {
-                pa_log_debug("Envelope Simple Rewind");
-                pa_envelope_rewind(i->thread_info.ramp_info.envelope, nbytes);
-            }
-        }
-
-        i->thread_info.ramp_info.envelope_dying -= nbytes;
-        if (i->thread_info.ramp_info.envelope_dying <= 0)
-            i->thread_info.ramp_info.envelope_dying = 0;
-    }
-}
-
-void pa_sink_input_set_volume_with_ramping(pa_sink_input *i, const pa_cvolume *volume, pa_bool_t save, pa_bool_t absolute, pa_usec_t t){
-    pa_cvolume v;
-    pa_volume_t previous_virtual_volume, target_virtual_volume;
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_ctl_context();
-    pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
-    pa_assert(volume);
-    pa_assert(pa_cvolume_valid(volume));
-    pa_assert(volume->channels == 1 || pa_cvolume_compatible(volume, &i->sample_spec));
-    pa_assert(pa_sink_input_is_volume_writable(i));
-
-    if ((i->sink->flags & PA_SINK_FLAT_VOLUME) && !absolute) {
-        v = i->sink->reference_volume;
-        pa_cvolume_remap(&v, &i->sink->channel_map, &i->channel_map);
-
-        if (pa_cvolume_compatible(volume, &i->sample_spec))
-            volume = pa_sw_cvolume_multiply(&v, &v, volume);
-        else
-            volume = pa_sw_cvolume_multiply_scalar(&v, &v, pa_cvolume_max(volume));
-    } else {
-
-        if (!pa_cvolume_compatible(volume, &i->sample_spec)) {
-            v = i->volume;
-            volume = pa_cvolume_scale(&v, pa_cvolume_max(volume));
-        }
-    }
-
-    if (pa_cvolume_equal(volume, &i->volume)) {
-        i->save_volume = i->save_volume || save;
-        return;
-    }
-
-    previous_virtual_volume = pa_cvolume_avg(&i->volume);
-    target_virtual_volume = pa_cvolume_avg(volume);
-
-    if (t > 0 && target_virtual_volume > 0)
-        pa_log_debug("SetVolumeWithRamping: Virtual Volume From %u=%f to %u=%f\n", previous_virtual_volume, pa_sw_volume_to_linear(previous_virtual_volume),
-                                             target_virtual_volume, pa_sw_volume_to_linear(target_virtual_volume));
-
-    i->volume = *volume;
-    i->save_volume = save;
-
-    /* Set this flag before the following code modify i->thread_info.soft_volume */
-    if (t > 0 && target_virtual_volume > 0)
-        pa_atomic_store(&i->before_ramping_v, 1);
-
-    if (i->sink->flags & PA_SINK_FLAT_VOLUME) {
-        /* We are in flat volume mode, so let's update all sink input
-         * volumes and update the flat volume of the sink */
-
-        pa_sink_set_volume(i->sink, NULL, TRUE, save);
-
-    } else {
-        /* OK, we are in normal volume mode. The volume only affects
-         * ourselves */
-        set_real_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);
-    }
-
-    if (t > 0 && target_virtual_volume > 0)
-        sink_input_set_ramping_info(i, previous_virtual_volume, target_virtual_volume, t);
-
-    /* The volume changed, let's tell people so */
-    if (i->volume_changed)
-        i->volume_changed(i);
-
-    /* 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);
-}
-
-void pa_sink_input_set_mute_with_ramping(pa_sink_input *i, pa_bool_t mute, pa_bool_t save, pa_usec_t t){
-
-    pa_sink_input_assert_ref(i);
-    pa_assert_ctl_context();
-    pa_assert(PA_SINK_INPUT_IS_LINKED(i->state));
-
-    if (!i->muted == !mute) {
-        i->save_muted = i->save_muted || mute;
-        return;
-    }
-
-    i->muted = mute;
-    i->save_muted = save;
-
-    /* Set this flag before the following code modify i->thread_info.muted, otherwise distortion will be heard */
-    if (t > 0)
-        pa_atomic_store(&i->before_ramping_m, 1);
-
-    pa_assert_se(pa_asyncmsgq_send(i->sink->asyncmsgq, PA_MSGOBJECT(i), PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE, NULL, 0, NULL) == 0);
-
-    if (t > 0)
-        sink_input_set_ramping_info_for_mute(i, mute, t);
-
-    /* The mute status changed, let's tell people so */
-    if (i->mute_changed)
-        i->mute_changed(i);
-
-    pa_subscription_post(i->core, PA_SUBSCRIPTION_EVENT_SINK_INPUT|PA_SUBSCRIPTION_EVENT_CHANGE, i->index);
-}