From ceb068d0e9d5fab22131f70be2cc3ab395c337f5 Mon Sep 17 00:00:00 2001 From: Sebastian Dröge Date: Tue, 30 Oct 2007 21:37:49 +0000 Subject: gst/equalizer/: Add small demo application based on the spectrum demo applications that gets white noise as input, pu... Original commit message from CVS: * gst/equalizer/Makefile.am: * gst/equalizer/demo.c: (on_window_destroy), (on_configure_event), (on_gain_changed), (on_bandwidth_changed), (on_freq_changed), (draw_spectrum), (message_handler), (main): Add small demo application based on the spectrum demo applications that gets white noise as input, pushes it through an equalizer and paints the spectrum. For every equalizer band it's possible to set gain, bandwidth and frequency. * gst/equalizer/gstiirequalizer.c: (setup_filter): Add some guarding against too large or too small frequencies and bandwidths. Also improve debugging a bit. --- gst/equalizer/Makefile.am | 9 +++++++++ gst/equalizer/gstiirequalizer.c | 39 +++++++++++++++++++++++++++------------ 2 files changed, 36 insertions(+), 12 deletions(-) (limited to 'gst/equalizer') diff --git a/gst/equalizer/Makefile.am b/gst/equalizer/Makefile.am index 042f32c6..ceb6877d 100644 --- a/gst/equalizer/Makefile.am +++ b/gst/equalizer/Makefile.am @@ -11,3 +11,12 @@ libgstequalizer_la_LIBADD = $(GST_LIBS) $(GST_PLUGINS_BASE_LIBS) -lgstaudio-$(GS libgstequalizer_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) noinst_HEADERS = gstiirequalizer.h + +if HAVE_GTK +noinst_PROGRAMS = demo +endif + +demo_SOURCES = demo.c +demo_CFLAGS = $(GST_BASE_CFLAGS) $(GST_CFLAGS) $(GTK_CFLAGS) +demo_LDFLAGS = $(GST_BASE_LIBS) $(GST_LIBS) $(GTK_LIBS) + diff --git a/gst/equalizer/gstiirequalizer.c b/gst/equalizer/gstiirequalizer.c index 8c87a664..25ee6972 100644 --- a/gst/equalizer/gstiirequalizer.c +++ b/gst/equalizer/gstiirequalizer.c @@ -1,6 +1,7 @@ /* GStreamer * Copyright (C) <2004> Benjamin Otte * <2007> Stefan Kost + * <2007> Sebastian Dröge * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -33,7 +34,6 @@ GST_DEBUG_CATEGORY (equalizer_debug); #define GST_CAT_DEFAULT equalizer_debug - static void gst_iir_equalizer_child_proxy_interface_init (gpointer g_iface, gpointer iface_data); @@ -376,17 +376,32 @@ setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band) * - we need shelf-filter for 1st and last band */ { - gdouble gain = arg_to_scale (band->gain); - gdouble frequency = band->freq / GST_AUDIO_FILTER (equ)->format.rate; - gdouble omega = 2.0 * M_PI * frequency; - gdouble bw = - 2.0 * M_PI * (band->width / GST_AUDIO_FILTER (equ)->format.rate); + gdouble gain, omega, bw; + gdouble edge_gain, gamma; + gdouble alpha, beta; + + + gain = arg_to_scale (band->gain); + + if (band->freq / GST_AUDIO_FILTER (equ)->format.rate > 0.5) + omega = M_PI; + else if (band->freq < 0.0) + omega = 0.0; + 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 + bw = 2.0 * M_PI * (band->width / GST_AUDIO_FILTER (equ)->format.rate); - gdouble edge_gain = sqrt (gain); - gdouble gamma = tan (bw / 2.0); + edge_gain = sqrt (gain); + gamma = tan (bw / 2.0); - gdouble alpha = gamma * edge_gain; - gdouble beta = gamma / edge_gain; + alpha = gamma * edge_gain; + beta = gamma / edge_gain; band->a0 = (1.0 + alpha) / (1.0 + beta); band->a1 = (-2.0 * cos (omega)) / (1.0 + beta); @@ -396,8 +411,8 @@ setup_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band) 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", - gain, band->width, frequency, band->a0, band->a1, band->a2, band->b1, - band->b2); + band->gain, band->width, band->freq, band->a0, band->a1, band->a2, + band->b1, band->b2); } } -- cgit