Index: gst/audiofx/Makefile.am
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/audiofx/Makefile.am,v
retrieving revision 1.5
diff -u -p -r1.5 Makefile.am
--- gst/audiofx/Makefile.am	6 Feb 2007 11:16:49 -0000	1.5
+++ gst/audiofx/Makefile.am	6 Mar 2007 17:19:22 -0000
@@ -6,7 +6,8 @@ plugin_LTLIBRARIES = libgstaudiofx.la
 libgstaudiofx_la_SOURCES = audiofx.c\
 	audiopanorama.c \
 	audioinvert.c \
-	audioamplify.c
+	audioamplify.c \
+	audiodynamic.c
 
 # flags used to compile this plugin
 libgstaudiofx_la_CFLAGS = $(GST_CFLAGS) \
@@ -23,4 +24,6 @@ libgstaudiofx_la_LDFLAGS = $(GST_PLUGIN_
 # headers we need but don't want installed
 noinst_HEADERS = audiopanorama.h \
 	audioinvert.h \
-	audioamplify.h
+	audioamplify.h \
+	audiodynamic.h
+
Index: gst/audiofx/audiodynamic.c
===================================================================
RCS file: gst/audiofx/audiodynamic.c
diff -N gst/audiofx/audiodynamic.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gst/audiofx/audiodynamic.c	6 Mar 2007 17:19:23 -0000
@@ -0,0 +1,652 @@
+/* 
+ * GStreamer
+ * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+/**
+ * SECTION:element-audiodynamic
+ * @short_description: Compressor and Expander
+ *
+ * <refsect2>
+ * This element can act as a compressor or expander. A compressor changes the
+ * amplitude of all samples above a specific threshold with a specific ratio,
+ * a expander does the same for all samples below a specific threshold. If
+ * soft-knee mode is selected the ratio is applied smoothly.
+ * <title>Example launch line</title>
+ * <para>
+ * <programlisting>
+ * gst-launch audiotestsrc wave=saw ! audiodynamic characteristics=soft-knee mode=compressor threshold=0.5 rate=0.5 ! alsasink
+ * gst-launch filesrc location="melo1.ogg" ! oggdemux ! vorbisdec ! audioconvert ! audiodynamic characteristics=hard-knee mode=expander threshold=0.2 rate=4.0 ! alsasink
+ * gst-launch audiotestsrc wave=saw ! audioconvert ! audiodynamic ! audioconvert ! alsasink
+ * </programlisting>
+ * </para>
+ * </refsect2>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <gst/gst.h>
+#include <gst/base/gstbasetransform.h>
+#include <gst/audio/audio.h>
+#include <gst/audio/gstaudiofilter.h>
+#include <gst/controller/gstcontroller.h>
+
+#include "audiodynamic.h"
+
+#define GST_CAT_DEFAULT gst_audio_dynamic_debug
+GST_DEBUG_CATEGORY_STATIC (GST_CAT_DEFAULT);
+
+static const GstElementDetails element_details =
+GST_ELEMENT_DETAILS ("AudioDynamic",
+    "Filter/Effect/Audio",
+    "Compressor and Expander",
+    "Sebastian Dröge <slomo@circular-chaos.org>");
+
+/* Filter signals and args */
+enum
+{
+  /* FILL ME */
+  LAST_SIGNAL
+};
+
+enum
+{
+  PROP_0,
+  PROP_CHARACTERISTICS,
+  PROP_MODE,
+  PROP_THRESHOLD,
+  PROP_RATIO
+};
+
+#define ALLOWED_CAPS \
+    "audio/x-raw-int,"                                                \
+    " depth=(int)16,"                                                 \
+    " width=(int)16,"                                                 \
+    " endianness=(int)BYTE_ORDER,"                                    \
+    " signed=(bool)TRUE,"                                             \
+    " rate=(int)[1,MAX],"                                             \
+    " channels=(int)[1,MAX]; "                                        \
+    "audio/x-raw-float,"                                              \
+    " width=(int)32,"                                                 \
+    " endianness=(int)BYTE_ORDER,"                                    \
+    " rate=(int)[1,MAX],"                                             \
+    " channels=(int)[1,MAX]"
+
+#define DEBUG_INIT(bla) \
+  GST_DEBUG_CATEGORY_INIT (gst_audio_dynamic_debug, "audiodynamic", 0, "audiodynamic element");
+
+GST_BOILERPLATE_FULL (GstAudioDynamic, gst_audio_dynamic, GstAudioFilter,
+    GST_TYPE_AUDIO_FILTER, DEBUG_INIT);
+
+static void gst_audio_dynamic_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec);
+static void gst_audio_dynamic_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec);
+
+static gboolean gst_audio_dynamic_setup (GstAudioFilter * filter,
+    GstRingBufferSpec * format);
+static GstFlowReturn gst_audio_dynamic_transform_ip (GstBaseTransform * base,
+    GstBuffer * buf);
+
+static void
+gst_audio_dynamic_transform_hard_knee_compressor_int (GstAudioDynamic * filter,
+    gint16 * data, guint num_samples);
+static void
+gst_audio_dynamic_transform_hard_knee_compressor_float (GstAudioDynamic *
+    filter, gfloat * data, guint num_samples);
+static void
+gst_audio_dynamic_transform_soft_knee_compressor_int (GstAudioDynamic * filter,
+    gint16 * data, guint num_samples);
+static void
+gst_audio_dynamic_transform_soft_knee_compressor_float (GstAudioDynamic *
+    filter, gfloat * data, guint num_samples);
+static void gst_audio_dynamic_transform_hard_knee_expander_int (GstAudioDynamic
+    * filter, gint16 * data, guint num_samples);
+static void
+gst_audio_dynamic_transform_hard_knee_expander_float (GstAudioDynamic * filter,
+    gfloat * data, guint num_samples);
+static void gst_audio_dynamic_transform_soft_knee_expander_int (GstAudioDynamic
+    * filter, gint16 * data, guint num_samples);
+static void
+gst_audio_dynamic_transform_soft_knee_expander_float (GstAudioDynamic * filter,
+    gfloat * data, guint num_samples);
+
+static GstAudioDynamicProcessFunc process_functions[] = {
+  (GstAudioDynamicProcessFunc)
+      gst_audio_dynamic_transform_hard_knee_compressor_int,
+  (GstAudioDynamicProcessFunc)
+      gst_audio_dynamic_transform_hard_knee_compressor_float,
+  (GstAudioDynamicProcessFunc)
+      gst_audio_dynamic_transform_soft_knee_compressor_int,
+  (GstAudioDynamicProcessFunc)
+      gst_audio_dynamic_transform_soft_knee_compressor_float,
+  (GstAudioDynamicProcessFunc)
+      gst_audio_dynamic_transform_hard_knee_expander_int,
+  (GstAudioDynamicProcessFunc)
+      gst_audio_dynamic_transform_hard_knee_expander_float,
+  (GstAudioDynamicProcessFunc)
+      gst_audio_dynamic_transform_soft_knee_expander_int,
+  (GstAudioDynamicProcessFunc)
+  gst_audio_dynamic_transform_soft_knee_expander_float
+};
+
+enum
+{
+  CHARACTERISTICS_HARD_KNEE = 0,
+  CHARACTERISTICS_SOFT_KNEE
+};
+
+#define GST_TYPE_AUDIO_DYNAMIC_CHARACTERISTICS (gst_audio_dynamic_characteristics_get_type ())
+static GType
+gst_audio_dynamic_characteristics_get_type (void)
+{
+  static GType gtype = 0;
+
+  if (gtype == 0) {
+    static const GEnumValue values[] = {
+      {CHARACTERISTICS_HARD_KNEE, "Hard Knee (default)",
+          "hard-knee"},
+      {CHARACTERISTICS_SOFT_KNEE, "Soft Knee (smooth)",
+          "soft-knee"},
+      {0, NULL, NULL}
+    };
+
+    gtype = g_enum_register_static ("GstAudioDynamicCharacteristics", values);
+  }
+  return gtype;
+}
+
+enum
+{
+  MODE_COMPRESSOR = 0,
+  MODE_EXPANDER
+};
+
+#define GST_TYPE_AUDIO_DYNAMIC_MODE (gst_audio_dynamic_mode_get_type ())
+static GType
+gst_audio_dynamic_mode_get_type (void)
+{
+  static GType gtype = 0;
+
+  if (gtype == 0) {
+    static const GEnumValue values[] = {
+      {MODE_COMPRESSOR, "Compressor (default)",
+          "compressor"},
+      {MODE_EXPANDER, "Expander", "expander"},
+      {0, NULL, NULL}
+    };
+
+    gtype = g_enum_register_static ("GstAudioDynamicMode", values);
+  }
+  return gtype;
+}
+
+static gboolean
+gst_audio_dynamic_set_process_function (GstAudioDynamic * filter)
+{
+  gint func_index;
+
+  func_index = (filter->mode == MODE_COMPRESSOR) ? 0 : 4;
+  func_index += (filter->characteristics == CHARACTERISTICS_HARD_KNEE) ? 0 : 2;
+  func_index += (!filter->is_float) ? 0 : 1;
+
+  if (func_index >= 0 && func_index < 8) {
+    filter->process = process_functions[func_index];
+    return TRUE;
+  }
+
+  return FALSE;
+}
+
+/* GObject vmethod implementations */
+
+static void
+gst_audio_dynamic_base_init (gpointer klass)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (klass);
+  GstCaps *caps;
+
+  gst_element_class_set_details (element_class, &element_details);
+
+  caps = gst_caps_from_string (ALLOWED_CAPS);
+  gst_audio_filter_class_add_pad_templates (GST_AUDIO_FILTER_CLASS (klass),
+      caps);
+  gst_caps_unref (caps);
+}
+
+static void
+gst_audio_dynamic_class_init (GstAudioDynamicClass * klass)
+{
+  GObjectClass *gobject_class;
+
+  gobject_class = (GObjectClass *) klass;
+  gobject_class->set_property = gst_audio_dynamic_set_property;
+  gobject_class->get_property = gst_audio_dynamic_get_property;
+
+  g_object_class_install_property (gobject_class, PROP_CHARACTERISTICS,
+      g_param_spec_enum ("characteristics", "Characteristics",
+          "Selects whether the ratio should be applied smooth (soft-knee) "
+          "or hard (hard-knee).",
+          GST_TYPE_AUDIO_DYNAMIC_CHARACTERISTICS, CHARACTERISTICS_HARD_KNEE,
+          G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_MODE,
+      g_param_spec_enum ("mode", "Mode",
+          "Selects whether the filter should work on loud samples (compressor) or"
+          "quiet samples (expander).",
+          GST_TYPE_AUDIO_DYNAMIC_MODE, MODE_COMPRESSOR, G_PARAM_READWRITE));
+
+  g_object_class_install_property (gobject_class, PROP_THRESHOLD,
+      g_param_spec_float ("threshold", "Threshold",
+          "Threshold until the filter is activated", 0.0, 1.0,
+          0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+
+  g_object_class_install_property (gobject_class, PROP_RATIO,
+      g_param_spec_float ("ratio", "Ratio",
+          "Ratio that should be applied", 0.0, G_MAXDOUBLE,
+          1.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+
+  GST_AUDIO_FILTER_CLASS (klass)->setup =
+      GST_DEBUG_FUNCPTR (gst_audio_dynamic_setup);
+  GST_BASE_TRANSFORM_CLASS (klass)->transform_ip =
+      GST_DEBUG_FUNCPTR (gst_audio_dynamic_transform_ip);
+}
+
+static void
+gst_audio_dynamic_init (GstAudioDynamic * filter, GstAudioDynamicClass * klass)
+{
+  filter->ratio = 1.0;
+  filter->threshold = 0.0;
+  filter->characteristics = CHARACTERISTICS_HARD_KNEE;
+  filter->mode = MODE_COMPRESSOR;
+  filter->width = filter->channels = 0;
+  filter->is_float = FALSE;
+  gst_base_transform_set_in_place (GST_BASE_TRANSFORM (filter), TRUE);
+}
+
+static void
+gst_audio_dynamic_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstAudioDynamic *filter = GST_AUDIO_DYNAMIC (object);
+
+  switch (prop_id) {
+    case PROP_CHARACTERISTICS:
+      filter->characteristics = g_value_get_enum (value);
+      gst_audio_dynamic_set_process_function (filter);
+      break;
+    case PROP_MODE:
+      filter->mode = g_value_get_enum (value);
+      gst_audio_dynamic_set_process_function (filter);
+      break;
+    case PROP_THRESHOLD:
+      filter->threshold = g_value_get_float (value);
+      break;
+    case PROP_RATIO:
+      filter->ratio = g_value_get_float (value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_audio_dynamic_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstAudioDynamic *filter = GST_AUDIO_DYNAMIC (object);
+
+  switch (prop_id) {
+    case PROP_CHARACTERISTICS:
+      g_value_set_enum (value, filter->characteristics);
+      break;
+    case PROP_MODE:
+      g_value_set_enum (value, filter->mode);
+      break;
+    case PROP_THRESHOLD:
+      g_value_set_float (value, filter->threshold);
+      break;
+    case PROP_RATIO:
+      g_value_set_float (value, filter->ratio);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+/* GstAudioFilter vmethod implementations */
+
+static gboolean
+gst_audio_dynamic_setup (GstAudioFilter * base, GstRingBufferSpec * format)
+{
+  GstAudioDynamic *filter = GST_AUDIO_DYNAMIC (base);
+  gboolean ret = TRUE;
+
+  filter->width = format->width / 8;
+  filter->channels = format->channels;
+  filter->is_float = (format->type == GST_BUFTYPE_FLOAT) ? TRUE : FALSE;
+
+  ret = gst_audio_dynamic_set_process_function (filter);
+
+  return ret;
+}
+
+static void
+gst_audio_dynamic_transform_hard_knee_compressor_int (GstAudioDynamic * filter,
+    gint16 * data, guint num_samples)
+{
+  glong val;
+  glong thr_p = filter->threshold * G_MAXINT16;
+  glong thr_n = filter->threshold * G_MININT16;
+
+  for (; num_samples; num_samples--) {
+    val = *data;
+
+    if (val > thr_p) {
+      val = thr_p + (val - thr_p) * filter->ratio;
+    } else if (val < thr_n) {
+      val = thr_n + (val - thr_n) * filter->ratio;
+    }
+    *data++ = (gint16) CLAMP (val, G_MININT16, G_MAXINT16);
+  }
+}
+
+static void
+gst_audio_dynamic_transform_hard_knee_compressor_float (GstAudioDynamic *
+    filter, gfloat * data, guint num_samples)
+{
+  gfloat val, threshold = filter->threshold;
+
+  for (; num_samples; num_samples--) {
+    val = *data;
+
+    if (val > threshold) {
+      val = threshold + (val - threshold) * filter->ratio;
+    } else if (val < -threshold) {
+      val = -threshold + (val + threshold) * filter->ratio;
+    }
+    *data++ = val;
+  }
+}
+
+static void
+gst_audio_dynamic_transform_soft_knee_compressor_int (GstAudioDynamic * filter,
+    gint16 * data, guint num_samples)
+{
+  glong val;
+  glong thr_p = filter->threshold * G_MAXINT16;
+  glong thr_n = filter->threshold * G_MININT16;
+  gfloat a_p, b_p, c_p;
+  gfloat a_n, b_n, c_n;
+
+  /* 2nd degree polynomial with:
+   * f(t) = t, f'(t) = 1, f'(m) = r
+   * =>
+   * a = (1-r)/(2*(t-m))
+   * b = (r*t - m)/(t-m)
+   * c = t * (1 - b - a*t)
+   * f(x) = ax^2 + bx + c
+   */
+
+  /* FIXME: If treshold is the same as the maximum
+   * we need to lower it a bit to prevent
+   * division by zero. */
+  if (thr_p == G_MAXINT16)
+    thr_p = G_MAXINT16 - 1;
+  if (thr_n == G_MININT16)
+    thr_n = G_MININT16 + 1;
+
+  a_p = (1 - filter->ratio) / (2 * (thr_p - G_MAXINT16));
+  b_p = (filter->ratio * thr_p - G_MAXINT16) / (thr_p - G_MAXINT16);
+  c_p = thr_p * (1 - b_p - a_p * thr_p);
+  a_n = (1 - filter->ratio) / (2 * (thr_n - G_MININT16));
+  b_n = (filter->ratio * thr_n - G_MININT16) / (thr_n - G_MININT16);
+  c_n = thr_n * (1 - b_n - a_n * thr_n);
+
+  for (; num_samples; num_samples--) {
+    val = *data;
+
+    if (val > thr_p) {
+      val = a_p * val * val + b_p * val + c_p;
+    } else if (val < thr_n) {
+      val = a_n * val * val + b_n * val + c_n;
+    }
+    *data++ = (gint16) CLAMP (val, G_MININT16, G_MAXINT16);
+  }
+}
+
+static void
+gst_audio_dynamic_transform_soft_knee_compressor_float (GstAudioDynamic *
+    filter, gfloat * data, guint num_samples)
+{
+  gfloat val;
+  gfloat threshold = filter->threshold;
+  gfloat a_p, b_p, c_p;
+  gfloat a_n, b_n, c_n;
+
+  /* 2nd degree polynomial with:
+   * f(t) = t, f'(t) = 1, f'(m) = r
+   * =>
+   * a = (1-r)/(2*(t-m))
+   * b = (r*t - m)/(t-m)
+   * c = t * (1 - b - a*t)
+   * f(x) = ax^2 + bx + c
+   */
+
+  /* FIXME: If treshold is the same as the maximum
+   * we need to lower it a bit to prevent
+   * division by zero. */
+  if (threshold == 1.0)
+    threshold = 1.0 - 0.00001;
+
+  a_p = (1 - filter->ratio) / (2 * (threshold - 1));
+  b_p = (filter->ratio * threshold - 1) / (threshold - 1);
+  c_p = threshold * (1 - b_p - a_p * threshold);
+  a_n = (1 - filter->ratio) / (2 * (-threshold + 1));
+  b_n = (-filter->ratio * threshold + 1) / (-threshold + 1);
+  c_n = -threshold * (1 - b_n + a_n * threshold);
+
+  for (; num_samples; num_samples--) {
+    val = *data;
+
+    if (val > 1) {
+      val = 1 + (val - 1) * filter->ratio;
+    } else if (val > threshold) {
+      val = a_p * val * val + b_p * val + c_p;
+    } else if (val < -1) {
+      val = -1 + (val + 1) * filter->ratio;
+    } else if (val < -threshold) {
+      val = a_n * val * val + b_n * val + c_n;
+    }
+    *data++ = val;
+  }
+}
+
+static void
+gst_audio_dynamic_transform_hard_knee_expander_int (GstAudioDynamic * filter,
+    gint16 * data, guint num_samples)
+{
+  glong val;
+  glong thr_p = filter->threshold * G_MAXINT16;
+  glong thr_n = filter->threshold * G_MININT16;
+  gfloat zero_p, zero_n;
+
+  if (filter->ratio != 0) {
+    zero_p = thr_p - thr_p / filter->ratio;
+    zero_n = thr_n - thr_n / filter->ratio;
+  } else {
+    zero_p = zero_n = 0;
+  }
+
+  if (zero_p < 0)
+    zero_p = 0;
+  if (zero_n > 0)
+    zero_n = 0;
+
+  for (; num_samples; num_samples--) {
+    val = *data;
+
+    if (val < thr_p && val > zero_p) {
+      val = filter->ratio * val + thr_p * (1 - filter->ratio);
+    } else if ((val <= zero_p && val > 0) || (val >= zero_n && val < 0)) {
+      val = 0;
+    } else if (val > thr_n && val < zero_n) {
+      val = filter->ratio * val + thr_n * (1 - filter->ratio);
+    }
+    *data++ = (gint16) CLAMP (val, G_MININT16, G_MAXINT16);
+  }
+}
+
+static void
+gst_audio_dynamic_transform_hard_knee_expander_float (GstAudioDynamic * filter,
+    gfloat * data, guint num_samples)
+{
+  gfloat val, threshold = filter->threshold, zero;
+
+  if (filter->ratio != 0)
+    zero = threshold - threshold / filter->ratio;
+  else
+    zero = 0;
+
+  if (zero < 0)
+    zero = 0;
+
+  for (; num_samples; num_samples--) {
+    val = *data;
+
+    if (val < threshold && val > zero) {
+      val = filter->ratio * val + threshold * (1 - filter->ratio);
+    } else if ((val <= zero && val > 0) || (val >= -zero && val < 0)) {
+      val = 0;
+    } else if (val > -threshold && val < -zero) {
+      val = filter->ratio * val - threshold * (1 - filter->ratio);
+    }
+    *data++ = val;
+  }
+}
+
+static void
+gst_audio_dynamic_transform_soft_knee_expander_int (GstAudioDynamic * filter,
+    gint16 * data, guint num_samples)
+{
+  glong val;
+  glong thr_p = filter->threshold * G_MAXINT16;
+  glong thr_n = filter->threshold * G_MININT16;
+  gfloat zero_p, zero_n;
+  gfloat a_p, b_p, c_p;
+  gfloat a_n, b_n, c_n;
+
+  zero_p = (thr_p * (filter->ratio - 1)) / (1 + filter->ratio);
+  zero_n = (thr_n * (filter->ratio - 1)) / (1 + filter->ratio);
+
+  if (zero_p < 0)
+    zero_p = 0;
+  if (zero_n > 0)
+    zero_n = 0;
+
+  /* FIXME: prevent division by zero */
+  if (thr_p == 0)
+    thr_p = -1;
+  if (thr_n == 0)
+    thr_n = 1;
+
+  /* 2n degree polynomial with:
+   * f(t) = t, f'(t) = 1, f(z) = 0, f'(z) = r
+   * z between 0 and t */
+  a_p = (1 - filter->ratio * filter->ratio) / (4 * thr_p);
+  b_p = (1 + filter->ratio * filter->ratio) / 2;
+  c_p = thr_p * (1 - b_p - a_p * thr_p);
+  a_n = (1 - filter->ratio * filter->ratio) / (4 * thr_n);
+  b_n = (1 + filter->ratio * filter->ratio) / 2;
+  c_n = thr_n * (1 - b_n - a_n * thr_n);
+
+  for (; num_samples; num_samples--) {
+    val = *data;
+
+    if (val < thr_p && val > zero_p) {
+      val = a_p * val * val + b_p * val + c_p;
+    } else if ((val <= zero_p && val > 0) || (val >= zero_n && val < 0)) {
+      val = 0;
+    } else if (val > thr_n && val < zero_n) {
+      val = a_n * val * val + b_n * val + c_n;
+    }
+    *data++ = (gint16) CLAMP (val, G_MININT16, G_MAXINT16);
+  }
+}
+
+static void
+gst_audio_dynamic_transform_soft_knee_expander_float (GstAudioDynamic * filter,
+    gfloat * data, guint num_samples)
+{
+  gfloat val;
+  gfloat threshold = filter->threshold;
+  gfloat zero;
+  gfloat a_p, b_p, c_p;
+  gfloat a_n, b_n, c_n;
+
+  zero = (threshold * (filter->ratio - 1)) / (1 + filter->ratio);
+
+  if (zero < 0)
+    zero = 0;
+
+  /* FIXME: prevent division by zero */
+  if (threshold == 0)
+    threshold = -1;
+
+  /* 2n degree polynomial with:
+   * f(t) = t, f'(t) = 1, f(z) = 0, f'(z) = r
+   * z between 0 and t */
+  a_p = (1 - filter->ratio * filter->ratio) / (4 * threshold);
+  b_p = (1 + filter->ratio * filter->ratio) / 2;
+  c_p = threshold * (1 - b_p - a_p * threshold);
+  a_n = (1 - filter->ratio * filter->ratio) / (-4 * threshold);
+  b_n = (1 + filter->ratio * filter->ratio) / 2;
+  c_n = -threshold * (1 - b_n + a_n * threshold);
+
+  for (; num_samples; num_samples--) {
+    val = *data;
+
+    if (val < threshold && val > zero) {
+      val = a_p * val * val + b_p * val + c_p;
+    } else if ((val <= zero && val > 0) || (val >= -zero && val < 0)) {
+      val = 0;
+    } else if (val > -threshold && val < -zero) {
+      val = a_n * val * val + b_n * val + c_n;
+    }
+    *data++ = val;
+  }
+}
+
+/* GstBaseTransform vmethod implementations */
+static GstFlowReturn
+gst_audio_dynamic_transform_ip (GstBaseTransform * base, GstBuffer * buf)
+{
+  GstAudioDynamic *filter = GST_AUDIO_DYNAMIC (base);
+  guint num_samples = GST_BUFFER_SIZE (buf) / filter->width;
+
+  if (!gst_buffer_is_writable (buf))
+    return GST_FLOW_OK;
+
+  filter->process (filter, GST_BUFFER_DATA (buf), num_samples);
+
+  return GST_FLOW_OK;
+}
Index: gst/audiofx/audiodynamic.h
===================================================================
RCS file: gst/audiofx/audiodynamic.h
diff -N gst/audiofx/audiodynamic.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ gst/audiofx/audiodynamic.h	6 Mar 2007 17:19:23 -0000
@@ -0,0 +1,68 @@
+/* 
+ * GStreamer
+ * Copyright (C) 2007 Sebastian Dröge <slomo@circular-chaos.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __GST_AUDIO_DYNAMIC_H__
+#define __GST_AUDIO_DYNAMIC_H__
+
+#include <gst/gst.h>
+#include <gst/base/gstbasetransform.h>
+#include <gst/audio/audio.h>
+#include <gst/audio/gstaudiofilter.h>
+
+G_BEGIN_DECLS
+
+#define GST_TYPE_AUDIO_DYNAMIC            (gst_audio_dynamic_get_type())
+#define GST_AUDIO_DYNAMIC(obj)            (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_AUDIO_DYNAMIC,GstAudioDynamic))
+#define GST_IS_AUDIO_DYNAMIC(obj)         (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_AUDIO_DYNAMIC))
+#define GST_AUDIO_DYNAMIC_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST((klass) ,GST_TYPE_AUDIO_DYNAMIC,GstAudioDynamicClass))
+#define GST_IS_AUDIO_DYNAMIC_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass) ,GST_TYPE_AUDIO_DYNAMIC))
+#define GST_AUDIO_DYNAMIC_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS((obj) ,GST_TYPE_AUDIO_DYNAMIC,GstAudioDynamicClass))
+typedef struct _GstAudioDynamic GstAudioDynamic;
+typedef struct _GstAudioDynamicClass GstAudioDynamicClass;
+
+typedef void (*GstAudioDynamicProcessFunc) (GstAudioDynamic *, guint8 *, guint);
+
+struct _GstAudioDynamic
+{
+  GstAudioFilter audiofilter;
+
+  gfloat degree;
+
+  /* < private > */
+  GstAudioDynamicProcessFunc process;
+  gint width;
+  gint channels;
+  gboolean is_float;
+  gint characteristics;
+  gint mode;
+  gfloat threshold;
+  gfloat ratio;
+};
+
+struct _GstAudioDynamicClass
+{
+  GstAudioFilterClass parent;
+};
+
+GType gst_audio_dynamic_get_type (void);
+
+G_END_DECLS
+
+#endif /* __GST_AUDIO_DYNAMIC_H__ */
Index: gst/audiofx/audiofx.c
===================================================================
RCS file: /cvs/gstreamer/gst-plugins-good/gst/audiofx/audiofx.c,v
retrieving revision 1.4
diff -u -p -r1.4 audiofx.c
--- gst/audiofx/audiofx.c	24 Jan 2007 12:41:02 -0000	1.4
+++ gst/audiofx/audiofx.c	6 Mar 2007 17:19:23 -0000
@@ -28,6 +28,7 @@
 #include "audiopanorama.h"
 #include "audioinvert.h"
 #include "audioamplify.h"
+#include "audiodynamic.h"
 
 /* entry point to initialize the plug-in
  * initialize the plug-in itself
@@ -45,7 +46,9 @@ plugin_init (GstPlugin * plugin)
       gst_element_register (plugin, "audioinvert", GST_RANK_NONE,
           GST_TYPE_AUDIO_INVERT) &&
       gst_element_register (plugin, "audioamplify", GST_RANK_NONE,
-          GST_TYPE_AUDIO_AMPLIFY));
+          GST_TYPE_AUDIO_AMPLIFY) &&
+      gst_element_register (plugin, "audiodynamic", GST_RANK_NONE,
+          GST_TYPE_AUDIO_DYNAMIC));
 }
 
 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
