• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * @title: equalizer-nbands
24  *
25  * The n-band equalizer element is a fully parametric equalizer. It allows to
26  * select between 1 and 64 bands and has properties on each band to change
27  * the center frequency, band width and gain.
28  *
29  * ## Example launch line
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  *
34  * ## Example code
35  * |[
36  * #include <gst/gst.h>
37  *
38  * ...
39  * typedef struct {
40  *   gfloat freq;
41  *   gfloat width;
42  *   gfloat gain;
43  * } GstEqualizerBandState;
44  *
45  * ...
46  *
47  *   GstElement *equalizer;
48  *   GObject *band;
49  *   gint i;
50  *   GstEqualizerBandState state[] = {
51  *     { 120.0,   50.0, - 3.0},
52  *     { 500.0,   20.0,  12.0},
53  *     {1503.0,    2.0, -20.0},
54  *     {6000.0, 1000.0,   6.0},
55  *     {3000.0,  120.0,   2.0}
56  *   };
57  *
58  * ...
59  *
60  *   equalizer = gst_element_factory_make ("equalizer-nbands", "equalizer");
61  *   g_object_set (G_OBJECT (equalizer), "num-bands", 5, NULL);
62  *
63  * ...
64  *
65  *   for (i = 0; i < 5; i++) {
66  *     band = gst_child_proxy_get_child_by_index (GST_CHILD_PROXY (equalizer), i);
67  *     g_object_set (G_OBJECT (band), "freq", state[i].freq,
68  *         "bandwidth", state[i].width,
69  * 	"gain", state[i].gain);
70  *     g_object_unref (G_OBJECT (band));
71  *   }
72  *
73  * ...
74  * ]|
75  *
76  */
77 
78 #ifdef HAVE_CONFIG_H
79 #include "config.h"
80 #endif
81 
82 #include "gstiirequalizer.h"
83 #include "gstiirequalizernbands.h"
84 
85 
86 enum
87 {
88   PROP_NUM_BANDS = 1
89 };
90 
91 static void gst_iir_equalizer_nbands_set_property (GObject * object,
92     guint prop_id, const GValue * value, GParamSpec * pspec);
93 static void gst_iir_equalizer_nbands_get_property (GObject * object,
94     guint prop_id, GValue * value, GParamSpec * pspec);
95 
96 GST_DEBUG_CATEGORY_EXTERN (equalizer_debug);
97 #define GST_CAT_DEFAULT equalizer_debug
98 
99 #define gst_iir_equalizer_nbands_parent_class parent_class
100 G_DEFINE_TYPE (GstIirEqualizerNBands, gst_iir_equalizer_nbands,
101     GST_TYPE_IIR_EQUALIZER);
102 GST_ELEMENT_REGISTER_DEFINE_WITH_CODE (equalizer_nbands, "equalizer-nbands",
103     GST_RANK_NONE, GST_TYPE_IIR_EQUALIZER_NBANDS,
104     equalizer_element_init (plugin));
105 /* equalizer implementation */
106 
107 static void
gst_iir_equalizer_nbands_class_init(GstIirEqualizerNBandsClass * klass)108 gst_iir_equalizer_nbands_class_init (GstIirEqualizerNBandsClass * klass)
109 {
110   GObjectClass *gobject_class = (GObjectClass *) klass;
111   GstElementClass *gstelement_class = (GstElementClass *) klass;
112 
113   gobject_class->set_property = gst_iir_equalizer_nbands_set_property;
114   gobject_class->get_property = gst_iir_equalizer_nbands_get_property;
115 
116   g_object_class_install_property (gobject_class, PROP_NUM_BANDS,
117       g_param_spec_uint ("num-bands", "num-bands",
118           "number of different bands to use", 1, 64, 10,
119           G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT));
120 
121   gst_element_class_set_static_metadata (gstelement_class, "N Band Equalizer",
122       "Filter/Effect/Audio",
123       "Direct Form IIR equalizer",
124       "Benjamin Otte <otte@gnome.org>," " Stefan Kost <ensonic@users.sf.net>");
125 }
126 
127 static void
gst_iir_equalizer_nbands_init(GstIirEqualizerNBands * equ_n)128 gst_iir_equalizer_nbands_init (GstIirEqualizerNBands * equ_n)
129 {
130   GstIirEqualizer *equ = GST_IIR_EQUALIZER (equ_n);
131 
132   gst_iir_equalizer_compute_frequencies (equ, 10);
133 }
134 
135 static void
gst_iir_equalizer_nbands_set_property(GObject * object,guint prop_id,const GValue * value,GParamSpec * pspec)136 gst_iir_equalizer_nbands_set_property (GObject * object, guint prop_id,
137     const GValue * value, GParamSpec * pspec)
138 {
139   GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
140 
141   switch (prop_id) {
142     case PROP_NUM_BANDS:
143       gst_iir_equalizer_compute_frequencies (equ, g_value_get_uint (value));
144       break;
145     default:
146       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
147       break;
148   }
149 }
150 
151 static void
gst_iir_equalizer_nbands_get_property(GObject * object,guint prop_id,GValue * value,GParamSpec * pspec)152 gst_iir_equalizer_nbands_get_property (GObject * object, guint prop_id,
153     GValue * value, GParamSpec * pspec)
154 {
155   GstIirEqualizer *equ = GST_IIR_EQUALIZER (object);
156 
157   switch (prop_id) {
158     case PROP_NUM_BANDS:
159       g_value_set_uint (value, equ->freq_band_count);
160       break;
161     default:
162       G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
163       break;
164   }
165 }
166