1 /* GStreamer
2  * Copyright (C) <2004> Benjamin Otte <otte@gnome.org>
3  *               <2007> Stefan Kost <ensonic@users.sf.net>
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the
17  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
18  * Boston, MA 02110-1301, USA.
19  */
20 
21 /**
22  * SECTION:element-equalizer-nbands
23  *
24  * The n-band equalizer element is a fully parametric equalizer. It allows to
25  * select between 1 and 64 bands and has properties on each band to change
26  * the center frequency, band width and gain.
27  *
28  * <refsect2>
29  * <title>Example launch line</title>
30  * |[
31  * gst-launch-1.0 filesrc location=song.ogg ! oggdemux ! vorbisdec ! audioconvert ! equalizer-nbands num-bands=15 band5::gain=6.0 ! alsasink
32  * ]| This make the equalizer use 15 bands and raises the volume of the 5th band by 6 db.
33  * </refsect2>
34  * <refsect2>
35  * <title>Example code</title>
36  * |[
37  * #include &lt;gst/gst.h&gt;
38  *
39  * ...
40  * typedef struct {
41  *   gfloat freq;
42  *   gfloat width;
43  *   gfloat gain;
44  * } GstEqualizerBandState;
45  *
46  * ...
47  *
48  *   GstElement *equalizer;
49  *   GObject *band;
50  *   gint i;
51  *   GstEqualizerBandState state[] = {
52  *     { 120.0,   50.0, - 3.0},
53  *     { 500.0,   20.0,  12.0},
54  *     {1503.0,    2.0, -20.0},
55  *     {6000.0, 1000.0,   6.0},
56  *     {3000.0,  120.0,   2.0}
57  *   };
58  *
59  * ...
60  *
61  *   equalizer = gst_element_factory_make ("equalizer-nbands", "equalizer");
62  *   g_object_set (G_OBJECT (equalizer), "num-bands", 5, NULL);
63  *
64  * ...
65  *
66  *   for (i = 0; i &lt; 5; i++) {
67  *     band = gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (equalizer), i);
68  *     g_object_set (G_OBJECT (band), "freq", state[i].freq,
69  *         "bandwidth", state[i].width,
70  * 	"gain", state[i].gain);
71  *     g_object_unref (G_OBJECT (band));
72  *   }
73  *
74  * ...
75  * ]|
76  * </refsect2>
77  */
78 
79 #ifdef HAVE_CONFIG_H
80 #include "config.h"
81 #endif
82 
83 #include "gstiirequalizer.h"
84 #include "gstiirequalizernbands.h"
85 
86 
87 enum
88 {
89   PROP_NUM_BANDS = 1
90 };
91 
92 static void gst_iir_equalizer_nbands_set_property (GObject * object,
93     guint prop_id, const GValue * value, GParamSpec * pspec);
94 static void gst_iir_equalizer_nbands_get_property (GObject * object,
95     guint prop_id, GValue * value, GParamSpec * pspec);
96 
97 GST_DEBUG_CATEGORY_EXTERN (equalizer_debug);
98 #define GST_CAT_DEFAULT equalizer_debug
99 
100 #define gst_iir_equalizer_nbands_parent_class parent_class
101 G_DEFINE_TYPE (GstIirEqualizerNBands, gst_iir_equalizer_nbands,
102     GST_TYPE_IIR_EQUALIZER);
103 
104 /* equalizer implementation */
105 
106 static void
gst_iir_equalizer_nbands_class_init(GstIirEqualizerNBandsClass * klass)107 gst_iir_equalizer_nbands_class_init (GstIirEqualizerNBandsClass * klass)
108 {
109   GObjectClass *gobject_class = (GObjectClass *) klass;
110   GstElementClass *gstelement_class = (GstElementClass *) klass;
111 
112   gobject_class->set_property = gst_iir_equalizer_nbands_set_property;
113   gobject_class->get_property = gst_iir_equalizer_nbands_get_property;
114 
115   g_object_class_install_property (gobject_class, PROP_NUM_BANDS,
116       g_param_spec_uint ("num-bands", "num-bands",
117           "number of different bands to use", 1, 64, 10,
118           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT));
119 
120   gst_element_class_set_static_metadata (gstelement_class, "N Band Equalizer",
121       "Filter/Effect/Audio",
122       "Direct Form IIR equalizer",
123       "Benjamin Otte <otte@gnome.org>," " Stefan Kost <ensonic@users.sf.net>");
124 }
125 
126 static void
gst_iir_equalizer_nbands_init(GstIirEqualizerNBands * equ_n)127 gst_iir_equalizer_nbands_init (GstIirEqualizerNBands * equ_n)
128 {
129   GstIirEqualizer *equ = GST_IIR_EQUALIZER (equ_n);
130 
131   gst_iir_equalizer_compute_frequencies (equ, 10);
132 }
133 
134 static void
gst_iir_equalizer_nbands_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)135 gst_iir_equalizer_nbands_set_property (GObject * object, guint prop_id,
136     const GValue * value, GParamSpec * pspec)
137 {
138   GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
139 
140   switch (prop_id) {
141     case PROP_NUM_BANDS:
142       gst_iir_equalizer_compute_frequencies (equ, g_value_get_uint (value));
143       break;
144     default:
145       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
146       break;
147   }
148 }
149 
150 static void
gst_iir_equalizer_nbands_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)151 gst_iir_equalizer_nbands_get_property (GObject * object, guint prop_id,
152     GValue * value, GParamSpec * pspec)
153 {
154   GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
155 
156   switch (prop_id) {
157     case PROP_NUM_BANDS:
158       g_value_set_uint (value, equ->freq_band_count);
159       break;
160     default:
161       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
162       break;
163   }
164 }
165