Revert the latest change: floating point samples are allowed to have any value, not...
authorSebastian Dröge <slomo@circular-chaos.org>
Sun, 9 Sep 2007 04:08:48 +0000 (04:08 +0000)
committerSebastian Dröge <slomo@circular-chaos.org>
Sun, 9 Sep 2007 04:08:48 +0000 (04:08 +0000)
Original commit message from CVS:
* gst/volume/gstvolume.c: (volume_choose_func):
* tests/check/elements/volume.c: (GST_START_TEST):
Revert the latest change: floating point samples are allowed to
have any value, not only values in the range [-1,1]. Thanks to Andy
Wingo for noticing.
Also fix processing of int32 samples with volumes > 4 by making the
unity value smaller which prevents overflows.

ChangeLog
gst/volume/gstvolume.c
tests/check/elements/volume.c

index b6d5397..7e476bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2007-09-09  Sebastian Dröge  <slomo@circular-chaos.org>
+
+       * gst/volume/gstvolume.c: (volume_choose_func):
+       * tests/check/elements/volume.c: (GST_START_TEST):
+       Revert the latest change: floating point samples are allowed to
+       have any value, not only values in the range [-1,1]. Thanks to Andy
+       Wingo for noticing.
+       Also fix processing of int32 samples with volumes > 4 by making the
+       unity value smaller which prevents overflows.
+
 2007-09-07  Tim-Philipp Müller  <tim at centricular dot net>
 
        * gst-libs/gst/rtp/gstrtpbuffer.c:
index 4747581..942cda9 100644 (file)
@@ -64,8 +64,8 @@
 #define VOLUME_UNITY_INT16_BIT_SHIFT 13 /* number of bits to shift for unity */
 #define VOLUME_UNITY_INT24           2097152    /* internal int for unity 2^(24-3) */
 #define VOLUME_UNITY_INT24_BIT_SHIFT 21 /* number of bits to shift for unity */
-#define VOLUME_UNITY_INT32           536870912  /* internal int for unity 2^(32-3) */
-#define VOLUME_UNITY_INT32_BIT_SHIFT 29
+#define VOLUME_UNITY_INT32           134217728  /* internal int for unity 2^(32-5) */
+#define VOLUME_UNITY_INT32_BIT_SHIFT 27
 #define VOLUME_MAX_DOUBLE            10.0
 #define VOLUME_MAX_INT8              G_MAXINT8
 #define VOLUME_MIN_INT8              G_MININT8
@@ -214,12 +214,8 @@ static gboolean volume_set_caps (GstBaseTransform * base, GstCaps * incaps,
 
 static void volume_process_double (GstVolume * this, gpointer bytes,
     guint n_bytes);
-static void volume_process_double_clamp (GstVolume * this, gpointer bytes,
-    guint n_bytes);
 static void volume_process_float (GstVolume * this, gpointer bytes,
     guint n_bytes);
-static void volume_process_float_clamp (GstVolume * this, gpointer bytes,
-    guint n_bytes);
 static void volume_process_int32 (GstVolume * this, gpointer bytes,
     guint n_bytes);
 static void volume_process_int32_clamp (GstVolume * this, gpointer bytes,
@@ -288,22 +284,10 @@ volume_choose_func (GstVolume * this)
     case GST_VOLUME_FORMAT_FLOAT:
       switch (this->width) {
         case 32:
-          /* only clamp if the gain is greater than 1.0
-           * FIXME: real_vol_f can change while processing the buffer!
-           */
-          if (this->real_vol_f > 1.0)
-            this->process = volume_process_float_clamp;
-          else
-            this->process = volume_process_float;
+          this->process = volume_process_float;
           break;
         case 64:
-          /* only clamp if the gain is greater than 1.0
-           * FIXME: real_vol_f can change while processing the buffer!
-           */
-          if (this->real_vol_f > 1.0)
-            this->process = volume_process_double_clamp;
-          else
-            this->process = volume_process_double;
+          this->process = volume_process_double;
           break;
       }
       break;
@@ -512,20 +496,6 @@ volume_process_double (GstVolume * this, gpointer bytes, guint n_bytes)
 }
 
 static void
-volume_process_double_clamp (GstVolume * this, gpointer bytes, guint n_bytes)
-{
-  gdouble *data = (gdouble *) bytes;
-  guint i, num_samples = n_bytes / sizeof (gdouble);
-  gdouble tmp;
-
-  for (i = 0; i < num_samples; i++) {
-    tmp = *data * this->real_vol_f;
-    *data++ = CLAMP (tmp, -1.0, 1.0);
-  }
-
-}
-
-static void
 volume_process_float (GstVolume * this, gpointer bytes, guint n_bytes)
 {
   gfloat *data = (gfloat *) bytes;
@@ -544,19 +514,6 @@ volume_process_float (GstVolume * this, gpointer bytes, guint n_bytes)
 }
 
 static void
-volume_process_float_clamp (GstVolume * this, gpointer bytes, guint n_bytes)
-{
-  gfloat *data = (gfloat *) bytes;
-  guint i, num_samples = n_bytes / sizeof (gfloat);
-  gfloat tmp;
-
-  for (i = 0; i < num_samples; i++) {
-    tmp = *data * this->real_vol_f;
-    *data++ = CLAMP (tmp, -1.0, 1.0);
-  }
-}
-
-static void
 volume_process_int32 (GstVolume * this, gpointer bytes, guint n_bytes)
 {
   gint *data = (gint *) bytes;
index c0ca64c..0bb12f4 100644 (file)
@@ -1006,7 +1006,7 @@ GST_START_TEST (test_double_f32)
   GstBuffer *outbuffer;
   GstCaps *caps;
   gfloat in[2] = { 0.75, -0.25 };
-  gfloat out[2] = { 1.0, -0.5 };        /* notice the clamped sample */
+  gfloat out[2] = { 1.5, -0.5 };        /* nothing is clamped */
   gfloat *res;
 
   volume = setup_volume ();
@@ -1190,7 +1190,7 @@ GST_START_TEST (test_double_f64)
   GstBuffer *outbuffer;
   GstCaps *caps;
   gdouble in[2] = { 0.75, -0.25 };
-  gdouble out[2] = { 1.0, -0.5 };       /* notice the clamped sample */
+  gdouble out[2] = { 1.5, -0.5 };       /* nothing is clamped */
   gdouble *res;
 
   volume = setup_volume ();