summaryrefslogtreecommitdiffstats
path: root/gst/equalizer/gstiirequalizer10bands.c
blob: e56bf19eeed4e0cb334d192a09e9433123bb009f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/* 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-10bands
 *
 * The 10 band equalizer element allows to change the gain of 10 equally distributed
 * frequency bands between 30 Hz and 15 kHz.
 *
 * <refsect2>
 * <title>Example launch line</title>
 * |[
 * gst-launch filesrc location=song.ogg ! oggdemux ! vorbisdec ! audioconvert ! equalizer-10bands band2=3.0 ! alsasink
 * ]| This raises the volume of the 3rd band which is at 119 Hz by 3 db.
 * </refsect2>
 */

#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


static void
_do_init (GType object_type)
{
  const GInterfaceInfo preset_interface_info = {
    NULL,                       /* interface_init */
    NULL,                       /* interface_finalize */
    NULL                        /* interface_data */
  };

  g_type_add_interface_static (object_type, GST_TYPE_PRESET,
      &preset_interface_info);
}

GST_BOILERPLATE_FULL (GstIirEqualizer10Bands, gst_iir_equalizer_10bands,
    GstIirEqualizer, GST_TYPE_IIR_EQUALIZER, _do_init);

/* 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", "29 Hz",
          "gain for the frequency band 29 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
  g_object_class_install_property (gobject_class, ARG_BAND1,
      g_param_spec_double ("band1", "59 Hz",
          "gain for the frequency band 59 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
  g_object_class_install_property (gobject_class, ARG_BAND2,
      g_param_spec_double ("band2", "119 Hz",
          "gain for the frequency band 119 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
  g_object_class_install_property (gobject_class, ARG_BAND3,
      g_param_spec_double ("band3", "227 Hz",
          "gain for the frequency band 227 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
  g_object_class_install_property (gobject_class, ARG_BAND4,
      g_param_spec_double ("band4", "474 Hz",
          "gain for the frequency band 474 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
  g_object_class_install_property (gobject_class, ARG_BAND5,
      g_param_spec_double ("band5", "947 Hz",
          "gain for the frequency band 947 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
  g_object_class_install_property (gobject_class, ARG_BAND6,
      g_param_spec_double ("band6", "1889 Hz",
          "gain for the frequency band 1889 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
  g_object_class_install_property (gobject_class, ARG_BAND7,
      g_param_spec_double ("band7", "3770 Hz",
          "gain for the frequency band 3770 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
  g_object_class_install_property (gobject_class, ARG_BAND8,
      g_param_spec_double ("band8", "7523 Hz",
          "gain for the frequency band 7523 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.0, 0.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
  g_object_class_install_property (gobject_class, ARG_BAND9,
      g_param_spec_double ("band9", "15011 Hz",
          "gain for the frequency band 15011 Hz, ranging from -24 dB to +12 dB",
          -24.0, 12.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, 10);
}

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;
  }
}