gst/equalizer/: Add 3 and 10 band version and add missing gst_object_sync_values.
authorStefan Kost <ensonic@users.sourceforge.net>
Wed, 14 Mar 2007 14:48:08 +0000 (14:48 +0000)
committerStefan Kost <ensonic@users.sourceforge.net>
Wed, 14 Mar 2007 14:48:08 +0000 (14:48 +0000)
Original commit message from CVS:
* gst/equalizer/Makefile.am:
* gst/equalizer/gstiirequalizer.c: (_do_init),
(gst_iir_equalizer_band_set_property),
(gst_iir_equalizer_band_class_init),
(gst_iir_equalizer_band_get_type),
(gst_iir_equalizer_child_proxy_get_child_by_index),
(gst_iir_equalizer_child_proxy_get_children_count),
(gst_iir_equalizer_child_proxy_interface_init), (setup_filter),
(gst_iir_equalizer_compute_frequencies),
(gst_iir_equalizer_transform_ip), (plugin_init):
* gst/equalizer/gstiirequalizer10bands.c:
(gst_iir_equalizer_10bands_base_init),
(gst_iir_equalizer_10bands_class_init),
(gst_iir_equalizer_10bands_init),
(gst_iir_equalizer_10bands_set_property),
(gst_iir_equalizer_10bands_get_property):
* gst/equalizer/gstiirequalizer10bands.h:
* gst/equalizer/gstiirequalizer3bands.c:
(gst_iir_equalizer_3bands_base_init),
(gst_iir_equalizer_3bands_class_init),
(gst_iir_equalizer_3bands_init),
(gst_iir_equalizer_3bands_set_property),
(gst_iir_equalizer_3bands_get_property):
* gst/equalizer/gstiirequalizer3bands.h:
* gst/equalizer/gstiirequalizernbands.c:
(gst_iir_equalizer_nbands_base_init),
(gst_iir_equalizer_nbands_init):
Add 3 and 10 band version and add missing gst_object_sync_values.
* gst/spectrum/gstspectrum.c: (gst_spectrum_event),
(gst_spectrum_transform_ip):
Add some comments about float support.

gst/equalizer/Makefile.am
gst/equalizer/gstiirequalizer.c
gst/equalizer/gstiirequalizer10bands.c [new file with mode: 0644]
gst/equalizer/gstiirequalizer10bands.h [new file with mode: 0644]
gst/equalizer/gstiirequalizer3bands.c [new file with mode: 0644]
gst/equalizer/gstiirequalizer3bands.h [new file with mode: 0644]
gst/equalizer/gstiirequalizernbands.c
gst/spectrum/gstspectrum.c

index 2588fa8..042f32c 100644 (file)
@@ -2,8 +2,10 @@ plugin_LTLIBRARIES = libgstequalizer.la
 
 libgstequalizer_la_SOURCES = \
         gstiirequalizer.c gstiirequalizer.h \
-        gstiirequalizernbands.c gstiirequalizernbands.h
-        
+        gstiirequalizernbands.c gstiirequalizernbands.h \
+        gstiirequalizer3bands.c gstiirequalizer3bands.h \
+        gstiirequalizer10bands.c gstiirequalizer10bands.h
+
 libgstequalizer_la_CFLAGS = $(GST_CFLAGS) $(GST_PLUGINS_BASE_CFLAGS) $(GST_BASE_CFLAGS) $(GST_CONTROLLER_CFLAGS)
 libgstequalizer_la_LIBADD = $(GST_LIBS) $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GST_MAJORMINOR) $(GST_BASE_LIBS) $(GST_CONTROLLER_LIBS) $(LIBM)
 libgstequalizer_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
index 1dc19b4..659aa18 100644 (file)
@@ -27,6 +27,8 @@
 
 #include "gstiirequalizer.h"
 #include "gstiirequalizernbands.h"
+#include "gstiirequalizer3bands.h"
+#include "gstiirequalizer10bands.h"
 
 GST_DEBUG_CATEGORY (equalizer_debug);
 #define GST_CAT_DEFAULT equalizer_debug
@@ -145,8 +147,11 @@ gst_iir_equalizer_band_set_property (GObject * object, guint prop_id,
             GST_IIR_EQUALIZER (gst_object_get_parent (GST_OBJECT (band)));
 
         band->gain = gain;
-        setup_filter (equ, band);
+        if (GST_AUDIO_FILTER (equ)->format.rate) {
+          setup_filter (equ, band);
+        }
         gst_object_unref (equ);
+        GST_INFO_OBJECT (band, "changed gain = %lf ", band->gain);
       }
       break;
     }
@@ -319,21 +324,25 @@ arg_to_scale (gdouble arg)
 static void
 setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
 {
-  gdouble gain = arg_to_scale (band->gain);
-  gdouble frequency = band->freq / GST_AUDIO_FILTER (equ)->format.rate;
-  gdouble q = pow (HIGHEST_FREQ / LOWEST_FREQ,
-      1.0 / (equ->freq_band_count - 1)) * equ->band_width;
-  gdouble theta = frequency * 2 * M_PI;
-
-  band->beta = (q - theta / 2) / (2 * q + theta);
-  band->gamma = (0.5 + band->beta) * cos (theta);
-  band->alpha = (0.5 - band->beta) / 2;
-
-  band->beta *= 2.0;
-  band->alpha *= 2.0 * gain;
-  band->gamma *= 2.0;
-  GST_INFO ("gain = %g, frequency = %g, alpha = %g, beta = %g, gamma=%g",
-      gain, frequency, band->alpha, band->beta, band->gamma);
+  g_return_if_fail (GST_AUDIO_FILTER (equ)->format.rate);
+
+  {
+    gdouble gain = arg_to_scale (band->gain);
+    gdouble frequency = band->freq / GST_AUDIO_FILTER (equ)->format.rate;
+    gdouble q = pow (HIGHEST_FREQ / LOWEST_FREQ,
+        1.0 / (equ->freq_band_count - 1)) * equ->band_width;
+    gdouble theta = frequency * 2 * M_PI;
+
+    band->beta = (q - theta / 2) / (2 * q + theta);
+    band->gamma = (0.5 + band->beta) * cos (theta);
+    band->alpha = (0.5 - band->beta) / 2;
+
+    band->beta *= 2.0;
+    band->alpha *= 2.0 * gain;
+    band->gamma *= 2.0;
+    GST_INFO ("gain = %g, frequency = %g, alpha = %g, beta = %g, gamma=%g",
+        gain, frequency, band->alpha, band->beta, band->gamma);
+  }
 }
 
 void
@@ -363,9 +372,10 @@ gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint new_count)
   } else {
     /* free unused bands */
     for (i = new_count; i < old_count; i++) {
+      GST_DEBUG ("removing band[%d]=%p", i, equ->bands[i]);
       gst_child_proxy_child_removed (GST_OBJECT (equ),
           GST_OBJECT (equ->bands[i]));
-      gst_object_unref (equ->bands[i]);
+      gst_object_unparent (GST_OBJECT (equ->bands[i]));
       equ->bands[i] = NULL;
     }
   }
@@ -381,6 +391,7 @@ gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint new_count)
    *   application should read band->freq
    */
   equ->bands[0]->freq = LOWEST_FREQ;
+  GST_DEBUG ("band[ 0] = '%lf'", equ->bands[0]->freq);
   /*
      if(equ->bands[0]->freq<10000.0) {
      sprintf (name,"%dHz",(gint)equ->bands[0]->freq);
@@ -394,6 +405,7 @@ gst_iir_equalizer_compute_frequencies (GstIirEqualizer * equ, guint new_count)
 
   for (i = 1; i < new_count; i++) {
     equ->bands[i]->freq = equ->bands[i - 1]->freq * step;
+    GST_DEBUG ("band[%2d] = '%lf'", i, equ->bands[i]->freq);
     /*
        if(equ->bands[i]->freq<10000.0) {
        sprintf (name,"%dHz",(gint)equ->bands[i]->freq);
@@ -525,10 +537,18 @@ gst_iir_equalizer_transform_ip (GstBaseTransform * btrans, GstBuffer * buf)
 {
   GstAudioFilter *filter = GST_AUDIO_FILTER (btrans);
   GstIirEqualizer *equ = GST_IIR_EQUALIZER (btrans);
+  GstClockTime timestamp;
 
   if (G_UNLIKELY (filter->format.channels < 1 || equ->process == NULL))
     return GST_FLOW_NOT_NEGOTIATED;
 
+  timestamp = GST_BUFFER_TIMESTAMP (buf);
+  timestamp =
+      gst_segment_to_stream_time (&btrans->segment, GST_FORMAT_TIME, timestamp);
+
+  if (GST_CLOCK_TIME_IS_VALID (timestamp))
+    gst_object_sync_values (G_OBJECT (equ), timestamp);
+
   equ->process (equ, GST_BUFFER_DATA (buf), GST_BUFFER_SIZE (buf),
       filter->format.channels);
 
@@ -562,8 +582,19 @@ plugin_init (GstPlugin * plugin)
 {
   GST_DEBUG_CATEGORY_INIT (equalizer_debug, "equalizer", 0, "equalizer");
 
-  return gst_element_register (plugin, "equalizer-nbands", GST_RANK_NONE,
-      GST_TYPE_IIR_EQUALIZER_NBANDS);
+  if (!(gst_element_register (plugin, "equalizer-nbands", GST_RANK_NONE,
+              GST_TYPE_IIR_EQUALIZER_NBANDS)))
+    return FALSE;
+
+  if (!(gst_element_register (plugin, "equalizer-3bands", GST_RANK_NONE,
+              GST_TYPE_IIR_EQUALIZER_3BANDS)))
+    return FALSE;
+
+  if (!(gst_element_register (plugin, "equalizer-10bands", GST_RANK_NONE,
+              GST_TYPE_IIR_EQUALIZER_10BANDS)))
+    return FALSE;
+
+  return TRUE;
 }
 
 GST_PLUGIN_DEFINE (GST_VERSION_MAJOR,
diff --git a/gst/equalizer/gstiirequalizer10bands.c b/gst/equalizer/gstiirequalizer10bands.c
new file mode 100644 (file)
index 0000000..66a9906
--- /dev/null
@@ -0,0 +1,216 @@
+/* GStreamer
+ * Copyright (C) <2007> Stefan Kost <ensonic@users.sf.net>
+ *
+ * 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.
+ */
+
+/*
+ *
+ * gst-launch filesrc location=song.ogg ! oggdemux ! vorbisdec ! audioconvert ! equalizer-10bands band1=-1.0 ! alsasink
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gstiirequalizer.h"
+#include "gstiirequalizer10bands.h"
+
+
+enum
+{
+  ARG_BAND0 = 1,
+  ARG_BAND1,
+  ARG_BAND2,
+  ARG_BAND3,
+  ARG_BAND4,
+  ARG_BAND5,
+  ARG_BAND6,
+  ARG_BAND7,
+  ARG_BAND8,
+  ARG_BAND9,
+};
+
+static void gst_iir_equalizer_10bands_set_property (GObject * object,
+    guint prop_id, const GValue * value, GParamSpec * pspec);
+static void gst_iir_equalizer_10bands_get_property (GObject * object,
+    guint prop_id, GValue * value, GParamSpec * pspec);
+
+GST_DEBUG_CATEGORY_EXTERN ()(equalizer_debug);
+#define GST_CAT_DEFAULT equalizer_debug
+
+GST_BOILERPLATE (GstIirEqualizer10Bands, gst_iir_equalizer_10bands,
+    GstIirEqualizer, GST_TYPE_IIR_EQUALIZER);
+
+/* equalizer implementation */
+
+static void
+gst_iir_equalizer_10bands_base_init (gpointer g_class)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+  const GstElementDetails iir_equalizer_details =
+      GST_ELEMENT_DETAILS ("10 Band Equalizer",
+      "Filter/Effect/Audio",
+      "Direct Form 10 band IIR equalizer",
+      "Stefan Kost <ensonic@users.sf.net>");
+
+  gst_element_class_set_details (element_class, &iir_equalizer_details);
+}
+
+static void
+gst_iir_equalizer_10bands_class_init (GstIirEqualizer10BandsClass * klass)
+{
+  GObjectClass *gobject_class = (GObjectClass *) klass;
+
+  gobject_class->set_property = gst_iir_equalizer_10bands_set_property;
+  gobject_class->get_property = gst_iir_equalizer_10bands_get_property;
+
+  g_object_class_install_property (gobject_class, ARG_BAND0,
+      g_param_spec_double ("band0", "20 Hz",
+          "gain for the frequency band 20 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND1,
+      g_param_spec_double ("band1", "43 Hz",
+          "gain for the frequency band 43 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND2,
+      g_param_spec_double ("band2", "93 Hz",
+          "gain for the frequency band 93 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND3,
+      g_param_spec_double ("band3", "200 Hz",
+          "gain for the frequency band 200 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND4,
+      g_param_spec_double ("band4", "430 Hz",
+          "gain for the frequency band 430 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND5,
+      g_param_spec_double ("band5", "928 Hz",
+          "gain for the frequency band 928 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND6,
+      g_param_spec_double ("band6", "2000 Hz",
+          "gain for the frequency band 2000 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND7,
+      g_param_spec_double ("band7", "4308 Hz",
+          "gain for the frequency band 4308 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND8,
+      g_param_spec_double ("band8", "9283 Hz",
+          "gain for the frequency band 9283 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND9,
+      g_param_spec_double ("band9", "20 kHz",
+          "gain for the frequency band 20 kHz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+}
+
+static void
+gst_iir_equalizer_10bands_init (GstIirEqualizer10Bands * equ_n,
+    GstIirEqualizer10BandsClass * g_class)
+{
+  GstIirEqualizer *equ = GST_IIR_EQUALIZER (equ_n);
+
+  gst_iir_equalizer_compute_frequencies (equ, 3);
+}
+
+static void
+gst_iir_equalizer_10bands_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
+
+  switch (prop_id) {
+    case ARG_BAND0:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band0::gain", value);
+      break;
+    case ARG_BAND1:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band1::gain", value);
+      break;
+    case ARG_BAND2:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band2::gain", value);
+      break;
+    case ARG_BAND3:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band3::gain", value);
+      break;
+    case ARG_BAND4:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band4::gain", value);
+      break;
+    case ARG_BAND5:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band5::gain", value);
+      break;
+    case ARG_BAND6:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band6::gain", value);
+      break;
+    case ARG_BAND7:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band7::gain", value);
+      break;
+    case ARG_BAND8:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band8::gain", value);
+      break;
+    case ARG_BAND9:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band9::gain", value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_iir_equalizer_10bands_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
+
+  switch (prop_id) {
+    case ARG_BAND0:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band0::gain", value);
+      break;
+    case ARG_BAND1:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band1::gain", value);
+      break;
+    case ARG_BAND2:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band2::gain", value);
+      break;
+    case ARG_BAND3:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band3::gain", value);
+      break;
+    case ARG_BAND4:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band4::gain", value);
+      break;
+    case ARG_BAND5:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band5::gain", value);
+      break;
+    case ARG_BAND6:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band6::gain", value);
+      break;
+    case ARG_BAND7:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band7::gain", value);
+      break;
+    case ARG_BAND8:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band8::gain", value);
+      break;
+    case ARG_BAND9:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band9::gain", value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
diff --git a/gst/equalizer/gstiirequalizer10bands.h b/gst/equalizer/gstiirequalizer10bands.h
new file mode 100644 (file)
index 0000000..96bed28
--- /dev/null
@@ -0,0 +1,51 @@
+/* GStreamer
+ * Copyright (C) <2007> Stefan Kost <ensonic@users.sf.net>
+ *
+ * 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_IIR_EQUALIZER_10BANDS__
+#define __GST_IIR_EQUALIZER_10BANDS__
+
+#include "gstiirequalizer.h"
+
+typedef struct _GstIirEqualizer10Bands GstIirEqualizer10Bands;
+typedef struct _GstIirEqualizer10BandsClass GstIirEqualizer10BandsClass;
+
+#define GST_TYPE_IIR_EQUALIZER_10BANDS \
+  (gst_iir_equalizer_10bands_get_type())
+#define GST_IIR_EQUALIZER_10BANDS(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IIR_EQUALIZER_10BANDS,GstIirEqualizer10Bands))
+#define GST_IIR_EQUALIZER_10BANDS_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IIR_EQUALIZER_10BANDS,GstIirEqualizer10BandsClass))
+#define GST_IS_IIR_EQUALIZER_10BANDS(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IIR_EQUALIZER_10BANDS))
+#define GST_IS_IIR_EQUALIZER_10BANDS_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IIR_EQUALIZER_10BANDS))
+
+struct _GstIirEqualizer10Bands
+{
+  GstIirEqualizer equalizer;
+};
+
+struct _GstIirEqualizer10BandsClass
+{
+  GstIirEqualizer equalizer_class;
+};
+
+extern GType gst_iir_equalizer_10bands_get_type(void);
+
+#endif /* __GST_IIR_EQUALIZER_10BANDS__ */
diff --git a/gst/equalizer/gstiirequalizer3bands.c b/gst/equalizer/gstiirequalizer3bands.c
new file mode 100644 (file)
index 0000000..aa9a98b
--- /dev/null
@@ -0,0 +1,151 @@
+/* GStreamer
+ * Copyright (C) <2007> Stefan Kost <ensonic@users.sf.net>
+ *
+ * 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-equalizer-3bands
+ *
+ * <refsect2>
+ * <title>Example launch line</title>
+ * <para>
+ * The 3 band equalizer element changes the frequency spectrum of the audio data.
+ * </para>
+ * <para>
+ * <programlisting>
+ * gst-launch filesrc location=song.ogg ! oggdemux ! vorbisdec ! audioconvert ! equalizer-3bands band1=-1.0 ! alsasink
+ * </programlisting>
+ * This lowers the volume of the 2nd band which is at 632 Hz by FIXME db.
+ * </para>
+ * </refsect2>
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "gstiirequalizer.h"
+#include "gstiirequalizer3bands.h"
+
+
+enum
+{
+  ARG_BAND0 = 1,
+  ARG_BAND1,
+  ARG_BAND2,
+};
+
+static void gst_iir_equalizer_3bands_set_property (GObject * object,
+    guint prop_id, const GValue * value, GParamSpec * pspec);
+static void gst_iir_equalizer_3bands_get_property (GObject * object,
+    guint prop_id, GValue * value, GParamSpec * pspec);
+
+GST_DEBUG_CATEGORY_EXTERN ()(equalizer_debug);
+#define GST_CAT_DEFAULT equalizer_debug
+
+GST_BOILERPLATE (GstIirEqualizer3Bands, gst_iir_equalizer_3bands,
+    GstIirEqualizer, GST_TYPE_IIR_EQUALIZER);
+
+/* equalizer implementation */
+
+static void
+gst_iir_equalizer_3bands_base_init (gpointer g_class)
+{
+  GstElementClass *element_class = GST_ELEMENT_CLASS (g_class);
+  const GstElementDetails iir_equalizer_details =
+      GST_ELEMENT_DETAILS ("3 Band Equalizer",
+      "Filter/Effect/Audio",
+      "Direct Form 3 band IIR equalizer",
+      "Stefan Kost <ensonic@users.sf.net>");
+
+  gst_element_class_set_details (element_class, &iir_equalizer_details);
+}
+
+static void
+gst_iir_equalizer_3bands_class_init (GstIirEqualizer3BandsClass * klass)
+{
+  GObjectClass *gobject_class = (GObjectClass *) klass;
+
+  gobject_class->set_property = gst_iir_equalizer_3bands_set_property;
+  gobject_class->get_property = gst_iir_equalizer_3bands_get_property;
+
+  g_object_class_install_property (gobject_class, ARG_BAND0,
+      g_param_spec_double ("band0", "20 Hz",
+          "gain for the frequency band 20 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND1,
+      g_param_spec_double ("band1", "632 Hz",
+          "gain for the frequency band 632 Hz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+  g_object_class_install_property (gobject_class, ARG_BAND2,
+      g_param_spec_double ("band2", "20 kHz",
+          "gain for the frequency band 20 kHz, ranging from -1.0 to +1.0",
+          -1.0, 1.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+}
+
+static void
+gst_iir_equalizer_3bands_init (GstIirEqualizer3Bands * equ_n,
+    GstIirEqualizer3BandsClass * g_class)
+{
+  GstIirEqualizer *equ = GST_IIR_EQUALIZER (equ_n);
+
+  gst_iir_equalizer_compute_frequencies (equ, 3);
+}
+
+static void
+gst_iir_equalizer_3bands_set_property (GObject * object, guint prop_id,
+    const GValue * value, GParamSpec * pspec)
+{
+  GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
+
+  switch (prop_id) {
+    case ARG_BAND0:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band0::gain", value);
+      break;
+    case ARG_BAND1:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band1::gain", value);
+      break;
+    case ARG_BAND2:
+      gst_child_proxy_set_property (GST_OBJECT (equ), "band2::gain", value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
+
+static void
+gst_iir_equalizer_3bands_get_property (GObject * object, guint prop_id,
+    GValue * value, GParamSpec * pspec)
+{
+  GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
+
+  switch (prop_id) {
+    case ARG_BAND0:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band0::gain", value);
+      break;
+    case ARG_BAND1:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band1::gain", value);
+      break;
+    case ARG_BAND2:
+      gst_child_proxy_get_property (GST_OBJECT (equ), "band2::gain", value);
+      break;
+    default:
+      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
+      break;
+  }
+}
diff --git a/gst/equalizer/gstiirequalizer3bands.h b/gst/equalizer/gstiirequalizer3bands.h
new file mode 100644 (file)
index 0000000..e167f52
--- /dev/null
@@ -0,0 +1,51 @@
+/* GStreamer
+ * Copyright (C) <2007> Stefan Kost <ensonic@users.sf.net>
+ *
+ * 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_IIR_EQUALIZER_3BANDS__
+#define __GST_IIR_EQUALIZER_3BANDS__
+
+#include "gstiirequalizer.h"
+
+typedef struct _GstIirEqualizer3Bands GstIirEqualizer3Bands;
+typedef struct _GstIirEqualizer3BandsClass GstIirEqualizer3BandsClass;
+
+#define GST_TYPE_IIR_EQUALIZER_3BANDS \
+  (gst_iir_equalizer_3bands_get_type())
+#define GST_IIR_EQUALIZER_3BANDS(obj) \
+  (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_IIR_EQUALIZER_3BANDS,GstIirEqualizer3Bands))
+#define GST_IIR_EQUALIZER_3BANDS_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_IIR_EQUALIZER_3BANDS,GstIirEqualizer3BandsClass))
+#define GST_IS_IIR_EQUALIZER_3BANDS(obj) \
+  (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_IIR_EQUALIZER_3BANDS))
+#define GST_IS_IIR_EQUALIZER_3BANDS_CLASS(klass) \
+  (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_IIR_EQUALIZER_3BANDS))
+
+struct _GstIirEqualizer3Bands
+{
+  GstIirEqualizer equalizer;
+};
+
+struct _GstIirEqualizer3BandsClass
+{
+  GstIirEqualizer equalizer_class;
+};
+
+extern GType gst_iir_equalizer_3bands_get_type(void);
+
+#endif /* __GST_IIR_EQUALIZER_3BANDS__ */
index 53d3c12..939085b 100644 (file)
  * Boston, MA 02111-1307, USA.
  */
 
-/*
+/**
+ * SECTION:element-equalizer-nbands
  *
- * gst-launch filesrc location=song.ogg ! oggdemux ! vorbisdec ! audioconvert ! equalizer-nbands rband5::gain=-1.0 ! alsasink
+ * <refsect2>
+ * <title>Example launch line</title>
+ * <para>
+ * The n-band equalizer element changes the frequency spectrum of the audio data.
+ * </para>
+ * <para>
+ * <programlisting>
+ * gst-launch filesrc location=song.ogg ! oggdemux ! vorbisdec ! audioconvert ! equalizer-nbands num-bands=15 band5::gain=-1.0 ! alsasink
+ * </programlisting>
+ * This make the equalizer use 15 bands and lowers the volume of the 5th band by FIXME db.
+ * </para>
+ * </refsect2>
  */
 
 #ifdef HAVE_CONFIG_H
@@ -57,7 +69,7 @@ gst_iir_equalizer_nbands_base_init (gpointer g_class)
       GST_ELEMENT_DETAILS ("N Band Equalizer",
       "Filter/Effect/Audio",
       "Direct Form IIR equalizer",
-      "Benjamin Otte <otte@gnome.org>," " Stefan Kost <ensonic@user.sf.net>");
+      "Benjamin Otte <otte@gnome.org>," " Stefan Kost <ensonic@users.sf.net>");
 
   gst_element_class_set_details (element_class, &iir_equalizer_details);
 }
index 3747b24..4cbd889 100644 (file)
@@ -405,7 +405,10 @@ gst_spectrum_transform_ip (GstBaseTransform * trans, GstBuffer * in)
 
     samples = (const gint16 *) gst_adapter_peek (spectrum->adapter, wanted);
 
+    /* the current fft code is gint16 based, so supporting other formats would
+     * not really benefit now */
     for (i = 0, j = 0; i < spectrum->len; i++) {
+      /* convert to mono */
       for (k = 0, acc = 0; k < spectrum->channels; k++)
         acc += samples[j++];
       spectrum->re[i] = (gint16) (acc / spectrum->channels);