Commit 6d7debb0 authored by Sebastian Dröge's avatar Sebastian Dröge

gst/volume/gstvolume.c: Correctly clamp float/double samples in the [-1.0,1.0]...

gst/volume/gstvolume.c: Correctly clamp float/double samples in the [-1.0,1.0] range to prevent weird effects.

Original commit message from CVS:
* gst/volume/gstvolume.c: (volume_choose_func),
(volume_process_double), (volume_process_double_clamp),
(volume_process_float_clamp):
Correctly clamp float/double samples in the [-1.0,1.0] range to
prevent weird effects.
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
Add unit tests for all samples types that had none before.
parent 7ea0798a
2007-09-05 Sebastian Dröge <slomo@circular-chaos.org>
* gst/volume/gstvolume.c: (volume_choose_func),
(volume_process_double), (volume_process_double_clamp),
(volume_process_float_clamp):
Correctly clamp float/double samples in the [-1.0,1.0] range to
prevent weird effects.
* tests/check/elements/volume.c: (GST_START_TEST), (volume_suite):
Add unit tests for all samples types that had none before.
2007-09-05 Tim-Philipp Müller <tim at centricular dot net>
* gst-libs/gst/rtp/gstrtpbuffer.c:
......@@ -214,8 +214,12 @@ 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,
......@@ -284,10 +288,22 @@ volume_choose_func (GstVolume * this)
case GST_VOLUME_FORMAT_FLOAT:
switch (this->width) {
case 32:
this->process = volume_process_float;
/* 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;
break;
case 64:
this->process = volume_process_double;
/* 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;
break;
}
break;
......@@ -481,22 +497,34 @@ gst_volume_init (GstVolume * this, GstVolumeClass * g_class)
/* NOTE: although it might be tempting to have volume_process_mute() which uses
* memset(bytes, 0, nbytes) for the vol=0 case, this has the downside that
* unmuting would unly take place after processing a buffer.
* unmuting would only take place after processing a buffer.
*/
static void
volume_process_double (GstVolume * this, gpointer bytes, guint n_bytes)
{
gdouble *data = (gdouble *) bytes;
guint i, num_samples;
num_samples = n_bytes / sizeof (gdouble);
guint i, num_samples = n_bytes / sizeof (gdouble);
for (i = 0; i < num_samples; i++) {
*data++ *= this->real_vol_f;
}
}
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)
{
......@@ -515,6 +543,19 @@ volume_process_float (GstVolume * this, gpointer bytes, guint n_bytes)
oil_scalarmultiply_f32_ns (data, data, &this->real_vol_f, num_samples);
}
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)
{
......
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment