volume ramp: fix warnings and a bug with mono files 45/15445/2
authorJaska Uimonen <jaska.uimonen@helsinki.fi>
Thu, 31 Oct 2013 08:57:39 +0000 (10:57 +0200)
committerJaska Uimonen <jaska.uimonen@intel.com>
Mon, 27 Jan 2014 11:16:43 +0000 (13:16 +0200)
Change-Id: I20a9b6a5a05b1ed39554d5f91def9f12bbdab413
Signed-off-by: Jaska Uimonen <jaska.uimonen@intel.com>
src/pulsecore/mix.c
src/pulsecore/sink-input.c
src/pulsecore/sink.c

index 8146177..62cff9c 100644 (file)
@@ -915,10 +915,20 @@ void pa_volume_ramp_memchunk(
 }
 
 pa_cvolume_ramp_int* pa_cvolume_ramp_convert(const pa_cvolume_ramp *src, pa_cvolume_ramp_int *dst, int sample_rate) {
-    int i;
+
+    int i, j, channels, remaining_channels;
     float temp;
 
-    for (i = 0; i < dst->channels; i++) {
+    if (dst->channels < src->channels) {
+        channels = dst->channels;
+        remaining_channels = 0;
+    }
+    else {
+        channels = src->channels;
+        remaining_channels = dst->channels;
+    }
+
+    for (i = 0; i < channels; i++) {
         dst->ramps[i].type = src->ramps[i].type;
         /* ms to samples */
         dst->ramps[i].length = src->ramps[i].length * sample_rate / 1000;
@@ -930,6 +940,17 @@ pa_cvolume_ramp_int* pa_cvolume_ramp_convert(const pa_cvolume_ramp *src, pa_cvol
         dst->ramps[i].end = temp * temp * temp;
     }
 
+    j = i;
+
+    for (i--; j < remaining_channels; j++) {
+        dst->ramps[j].type = dst->ramps[i].type;
+        dst->ramps[j].length = dst->ramps[i].length;
+        dst->ramps[j].left = dst->ramps[i].left;
+        dst->ramps[j].start = dst->ramps[i].start;
+        dst->ramps[j].target = dst->ramps[i].target;
+        dst->ramps[j].end = dst->ramps[i].end;
+    }
+
     return dst;
 }
 
index ae1847b..47bea00 100644 (file)
@@ -547,9 +547,9 @@ int pa_sink_input_new(
     i->userdata = NULL;
 
     if (data->flags & PA_SINK_INPUT_START_RAMP_MUTED)
-        pa_cvolume_ramp_int_init(&i->ramp, PA_VOLUME_MUTED, data->sample_spec.channels);
+        pa_cvolume_ramp_int_init(&i->ramp, PA_VOLUME_MUTED, data->sink->sample_spec.channels);
     else
-        pa_cvolume_ramp_int_init(&i->ramp, PA_VOLUME_NORM, data->sample_spec.channels);
+        pa_cvolume_ramp_int_init(&i->ramp, PA_VOLUME_NORM, data->sink->sample_spec.channels);
 
     i->thread_info.state = i->state;
     i->thread_info.attached = false;
@@ -2067,12 +2067,10 @@ int pa_sink_input_process_msg(pa_msgobject *o, int code, void *userdata, int64_t
             return 0;
 
         case PA_SINK_INPUT_MESSAGE_SET_VOLUME_RAMP:
-            if (!pa_cvolume_ramp_equal(&i->thread_info.ramp, &i->ramp)) {
-                /* we have ongoing ramp where we take current start values */
-                pa_cvolume_ramp_start_from(&i->thread_info.ramp, &i->ramp);
-                i->thread_info.ramp = i->ramp;
-                pa_sink_input_request_rewind(i, 0, TRUE, FALSE, FALSE);
-            }
+            /* we have ongoing ramp where we take current start values */
+            pa_cvolume_ramp_start_from(&i->thread_info.ramp, &i->ramp);
+            i->thread_info.ramp = i->ramp;
+            pa_sink_input_request_rewind(i, 0, TRUE, FALSE, FALSE);
             return 0;
 
         case PA_SINK_INPUT_MESSAGE_SET_SOFT_MUTE:
index b43971c..7984a34 100644 (file)
@@ -2812,12 +2812,10 @@ int pa_sink_process_msg(pa_msgobject *o, int code, void *userdata, int64_t offse
             return 0;
 
         case PA_SINK_MESSAGE_SET_VOLUME_RAMP:
-            if (!pa_cvolume_ramp_equal(&s->thread_info.ramp, &s->ramp)) {
-                /* if we have ongoing ramp where we take current start values */
-                pa_cvolume_ramp_start_from(&s->thread_info.ramp, &s->ramp);
-                s->thread_info.ramp = s->ramp;
-                pa_sink_request_rewind(s, (size_t) -1);
-            }
+            /* if we have ongoing ramp where we take current start values */
+            pa_cvolume_ramp_start_from(&s->thread_info.ramp, &s->ramp);
+            s->thread_info.ramp = s->ramp;
+            pa_sink_request_rewind(s, (size_t) -1);
             return 0;
 
         case PA_SINK_MESSAGE_GET_VOLUME: