summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Dröge <slomo@circular-chaos.org>2007-11-03 19:50:11 +0000
committerSebastian Dröge <slomo@circular-chaos.org>2007-11-03 19:50:11 +0000
commitf627f21233890b35e0420171c67b2b380108da73 (patch)
treecaa05e9b4a6a00f37516cf11678d9902253578ea
parentc67ad65c91417d171692d34e49e412516895ac3a (diff)
downloadgst-plugins-bad-f627f21233890b35e0420171c67b2b380108da73.tar.gz
gst-plugins-bad-f627f21233890b35e0420171c67b2b380108da73.tar.bz2
gst-plugins-bad-f627f21233890b35e0420171c67b2b380108da73.zip
gst/equalizer/: Allow setting 0 as bandwidth and handle this correctly.
Original commit message from CVS: * gst/equalizer/demo.c: (main): * gst/equalizer/gstiirequalizer.c: (gst_iir_equalizer_band_class_init), (setup_filter): Allow setting 0 as bandwidth and handle this correctly. Also handle a bandwidth of rate/2 properly. * gst/equalizer/gstiirequalizernbands.c: (gst_iir_equalizer_nbands_class_init): Make it possible to generate a N-band equalizer with 1 bands. The previous limit of 2 was caused by a nowadays replaced calculation doing a division by zero if number of bands was 1.
-rw-r--r--ChangeLog14
-rw-r--r--gst/equalizer/demo.c2
-rw-r--r--gst/equalizer/gstiirequalizer.c27
-rw-r--r--gst/equalizer/gstiirequalizernbands.c2
4 files changed, 37 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 2689544a..889881b9 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2007-11-03 Sebastian Dröge <slomo@circular-chaos.org>
+
+ * gst/equalizer/demo.c: (main):
+ * gst/equalizer/gstiirequalizer.c:
+ (gst_iir_equalizer_band_class_init), (setup_filter):
+ Allow setting 0 as bandwidth and handle this correctly.
+ Also handle a bandwidth of rate/2 properly.
+
+ * gst/equalizer/gstiirequalizernbands.c:
+ (gst_iir_equalizer_nbands_class_init):
+ Make it possible to generate a N-band equalizer with 1 bands. The
+ previous limit of 2 was caused by a nowadays replaced calculation
+ doing a division by zero if number of bands was 1.
+
2007-11-02 Tim-Philipp Müller <tim at centricular dot net>
Patch by: Ole André Vadla Ravnås <ole.andre.ravnas@tandberg.com>
diff --git a/gst/equalizer/demo.c b/gst/equalizer/demo.c
index 7e7fae4a..cf361a9d 100644
--- a/gst/equalizer/demo.c
+++ b/gst/equalizer/demo.c
@@ -208,7 +208,7 @@ main (int argc, char *argv[])
G_CALLBACK (on_gain_changed), (gpointer) band);
gtk_box_pack_start (GTK_BOX (scales_hbox), widget, FALSE, FALSE, 0);
- widget = gtk_vscale_new_with_range (1.0, 20000.0, 5.0);
+ widget = gtk_vscale_new_with_range (0.0, 20000.0, 5.0);
gtk_scale_set_draw_value (GTK_SCALE (widget), TRUE);
gtk_scale_set_value_pos (GTK_SCALE (widget), GTK_POS_TOP);
gtk_range_set_value (GTK_RANGE (widget), bw);
diff --git a/gst/equalizer/gstiirequalizer.c b/gst/equalizer/gstiirequalizer.c
index 25ee6972..cd955e28 100644
--- a/gst/equalizer/gstiirequalizer.c
+++ b/gst/equalizer/gstiirequalizer.c
@@ -232,7 +232,7 @@ gst_iir_equalizer_band_class_init (GstIirEqualizerBandClass * klass)
g_object_class_install_property (gobject_class, ARG_BANDWIDTH,
g_param_spec_double ("bandwidth", "bandwidth",
"difference between bandedges in Hz",
- 1.0, 100000.0, 1.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ 0.0, 100000.0, 1.0, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
}
static void
@@ -390,12 +390,26 @@ setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
else
omega = 2.0 * M_PI * (band->freq / GST_AUDIO_FILTER (equ)->format.rate);
- if (band->width / GST_AUDIO_FILTER (equ)->format.rate > 0.5)
- bw = M_PI;
- else if (band->width <= 1.0)
- bw = 2.0 * M_PI * (1.0 / GST_AUDIO_FILTER (equ)->format.rate);
- else
+ if (band->width / GST_AUDIO_FILTER (equ)->format.rate >= 0.5) {
+ /* If bandwidth == 0.5 the calculation below fails as tan(M_PI/2)
+ * is undefined. So set the bandwidth to a slightly smaller value.
+ */
+ bw = M_PI - 0.00000001;
+ } else if (band->width <= 0.0) {
+ /* If bandwidth == 0 this band won't change anything so set
+ * the coefficients accordingly. The coefficient calculation
+ * below would create coefficients that for some reason amplify
+ * the band.
+ */
+ band->a0 = 1.0;
+ band->a1 = 0.0;
+ band->a2 = 0.0;
+ band->b1 = 0.0;
+ band->b2 = 0.0;
+ goto out;
+ } else {
bw = 2.0 * M_PI * (band->width / GST_AUDIO_FILTER (equ)->format.rate);
+ }
edge_gain = sqrt (gain);
gamma = tan (bw / 2.0);
@@ -409,6 +423,7 @@ setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band)
band->b1 = (2.0 * cos (omega)) / (1.0 + beta);
band->b2 = -(1.0 - beta) / (1.0 + beta);
+ out:
GST_INFO
("gain = %7.5g, , bandwidth= %7.5g, frequency = %7.5g, a0 = %7.5g, a1 = %7.5g, a2=%7.5g b1 = %7.5g, b2 = %7.5g",
band->gain, band->width, band->freq, band->a0, band->a1, band->a2,
diff --git a/gst/equalizer/gstiirequalizernbands.c b/gst/equalizer/gstiirequalizernbands.c
index b6482f6e..a3401b33 100644
--- a/gst/equalizer/gstiirequalizernbands.c
+++ b/gst/equalizer/gstiirequalizernbands.c
@@ -84,7 +84,7 @@ gst_iir_equalizer_nbands_class_init (GstIirEqualizerNBandsClass * klass)
g_object_class_install_property (gobject_class, ARG_NUM_BANDS,
g_param_spec_uint ("num-bands", "num-bands",
- "number of different bands to use", 2, 64, 10,
+ "number of different bands to use", 1, 64, 10,
G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
}