diff options
Diffstat (limited to 'gst/filter/gstlpwsinc.c')
-rw-r--r-- | gst/filter/gstlpwsinc.c | 138 |
1 files changed, 69 insertions, 69 deletions
diff --git a/gst/filter/gstlpwsinc.c b/gst/filter/gstlpwsinc.c index 603d8775..0ce33b32 100644 --- a/gst/filter/gstlpwsinc.c +++ b/gst/filter/gstlpwsinc.c @@ -38,20 +38,19 @@ #include <math.h> /* M_PI */ #include <string.h> /* memmove */ -static GstElementDetails gst_lpwsinc_details = GST_ELEMENT_DETAILS ( - "LPWSinc", - "Filter/Effect/Audio", - "Low-pass Windowed sinc filter", - "Thomas <thomas@apestaart.org>, " - "Steven W. Smith" -); - -enum { +static GstElementDetails gst_lpwsinc_details = GST_ELEMENT_DETAILS ("LPWSinc", + "Filter/Effect/Audio", + "Low-pass Windowed sinc filter", + "Thomas <thomas@apestaart.org>, " "Steven W. Smith"); + +enum +{ /* FILL ME */ LAST_SIGNAL }; -enum { +enum +{ ARG_0, ARG_LENGTH, ARG_FREQUENCY, @@ -78,42 +77,43 @@ struct _GstLPWSinc GstPad *sinkpad, *srcpad; double frequency; - int wing_size; /* length of a "wing" of the filter; - actual length is 2 * wing_size + 1 */ + int wing_size; /* length of a "wing" of the filter; + actual length is 2 * wing_size + 1 */ - gfloat *residue; /* buffer for left-over samples from previous buffer */ + gfloat *residue; /* buffer for left-over samples from previous buffer */ double *kernel; }; struct _GstLPWSincClass { - GstElementClass parent_class; + GstElementClass parent_class; }; -static void gst_lpwsinc_base_init (gpointer g_class); -static void gst_lpwsinc_class_init (GstLPWSincClass * klass); -static void gst_lpwsinc_init (GstLPWSinc * filter); +static void gst_lpwsinc_base_init (gpointer g_class); +static void gst_lpwsinc_class_init (GstLPWSincClass * klass); +static void gst_lpwsinc_init (GstLPWSinc * filter); -static void gst_lpwsinc_set_property (GObject * object, guint prop_id, - const GValue * value, - GParamSpec * pspec); -static void gst_lpwsinc_get_property (GObject * object, guint prop_id, - GValue * value, GParamSpec * pspec); +static void gst_lpwsinc_set_property (GObject * object, guint prop_id, + const GValue * value, GParamSpec * pspec); +static void gst_lpwsinc_get_property (GObject * object, guint prop_id, + GValue * value, GParamSpec * pspec); -static void gst_lpwsinc_chain (GstPad * pad, GstData *_data); +static void gst_lpwsinc_chain (GstPad * pad, GstData * _data); static GstPadLinkReturn - gst_lpwsinc_sink_connect (GstPad * pad, const GstCaps * caps); +gst_lpwsinc_sink_connect (GstPad * pad, const GstCaps * caps); static GstElementClass *parent_class = NULL; + /*static guint gst_lpwsinc_signals[LAST_SIGNAL] = { 0 }; */ -GType gst_lpwsinc_get_type (void) +GType +gst_lpwsinc_get_type (void) { static GType lpwsinc_type = 0; if (!lpwsinc_type) { static const GTypeInfo lpwsinc_info = { - sizeof (GstLPWSincClass), + sizeof (GstLPWSincClass), gst_lpwsinc_base_init, NULL, (GClassInitFunc) gst_lpwsinc_class_init, NULL, NULL, @@ -121,8 +121,8 @@ GType gst_lpwsinc_get_type (void) (GInstanceInitFunc) gst_lpwsinc_init, }; - lpwsinc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstLPWSinc", - &lpwsinc_info, 0); + lpwsinc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstLPWSinc", + &lpwsinc_info, 0); } return lpwsinc_type; } @@ -136,9 +136,9 @@ gst_lpwsinc_base_init (gpointer g_class) gst_element_class_add_pad_template (element_class, gst_static_pad_template_get (&gst_filter_src_template)); gst_element_class_add_pad_template (element_class, - gst_static_pad_template_get (&gst_filter_sink_template)); + gst_static_pad_template_get (&gst_filter_sink_template)); - gst_element_class_set_details (element_class, &gst_lpwsinc_details); + gst_element_class_set_details (element_class, &gst_lpwsinc_details); } static void @@ -153,15 +153,13 @@ gst_lpwsinc_class_init (GstLPWSincClass * klass) parent_class = g_type_class_ref (GST_TYPE_ELEMENT); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_FREQUENCY, - g_param_spec_double ("frequency", "Frequency", - "Cut-off Frequency relative to sample rate)", - 0.0, 0.5, - 0, G_PARAM_READWRITE)); + g_param_spec_double ("frequency", "Frequency", + "Cut-off Frequency relative to sample rate)", + 0.0, 0.5, 0, G_PARAM_READWRITE)); g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LENGTH, - g_param_spec_int ("length", "Length", - "N such that the filter length = 2N + 1", - 1, G_MAXINT, - 1, G_PARAM_READWRITE)); + g_param_spec_int ("length", "Length", + "N such that the filter length = 2N + 1", + 1, G_MAXINT, 1, G_PARAM_READWRITE)); gobject_class->set_property = gst_lpwsinc_set_property; gobject_class->get_property = gst_lpwsinc_get_property; @@ -170,14 +168,16 @@ gst_lpwsinc_class_init (GstLPWSincClass * klass) static void gst_lpwsinc_init (GstLPWSinc * filter) { - filter->sinkpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_filter_sink_template), "sink"); + filter->sinkpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_filter_sink_template), "sink"); gst_pad_set_chain_function (filter->sinkpad, gst_lpwsinc_chain); gst_pad_set_link_function (filter->sinkpad, gst_lpwsinc_sink_connect); gst_element_add_pad (GST_ELEMENT (filter), filter->sinkpad); - filter->srcpad = gst_pad_new_from_template ( - gst_static_pad_template_get (&gst_filter_src_template), "src"); + filter->srcpad = + gst_pad_new_from_template (gst_static_pad_template_get + (&gst_filter_src_template), "src"); gst_element_add_pad (GST_ELEMENT (filter), filter->srcpad); filter->wing_size = 50; @@ -197,45 +197,45 @@ gst_lpwsinc_sink_connect (GstPad * pad, const GstCaps * caps) g_assert (GST_IS_PAD (pad)); g_assert (caps != NULL); - set_retval = gst_pad_try_set_caps(filter->srcpad, caps); - - if (set_retval > 0) - { + set_retval = gst_pad_try_set_caps (filter->srcpad, caps); + + if (set_retval > 0) { /* connection works, so init the filter */ /* FIXME: remember to free it */ /* fill the kernel */ g_print ("DEBUG: initing filter kernel\n"); len = filter->wing_size; - GST_DEBUG ( - "lpwsinc: initializing filter kernel of length %d", len * 2 + 1); + GST_DEBUG ("lpwsinc: initializing filter kernel of length %d", len * 2 + 1); filter->kernel = (double *) g_malloc (sizeof (double) * (2 * len + 1)); - for (i = 0; i <= len * 2; ++i) - { + for (i = 0; i <= len * 2; ++i) { if (i == len) filter->kernel[i] = 2 * M_PI * filter->frequency; else - filter->kernel[i] = sin (2 * M_PI * filter->frequency * (i - len)) - / (i - len); + filter->kernel[i] = sin (2 * M_PI * filter->frequency * (i - len)) + / (i - len); /* windowing */ filter->kernel[i] *= (0.54 - 0.46 * cos (M_PI * i / len)); } /* normalize for unity gain at DC * FIXME: sure this is not supposed to be quadratic ? */ - for (i = 0; i <= len * 2; ++i) sum += filter->kernel[i]; - for (i = 0; i <= len * 2; ++i) filter->kernel[i] /= sum; + for (i = 0; i <= len * 2; ++i) + sum += filter->kernel[i]; + for (i = 0; i <= len * 2; ++i) + filter->kernel[i] /= sum; /* set up the residue memory space */ filter->residue = (gfloat *) g_malloc (sizeof (gfloat) * (len * 2 + 1)); - for (i = 0; i <= len * 2; ++i) filter->residue[i] = 0.0; + for (i = 0; i <= len * 2; ++i) + filter->residue[i] = 0.0; } return set_retval; } static void -gst_lpwsinc_chain (GstPad * pad, GstData *_data) +gst_lpwsinc_chain (GstPad * pad, GstData * _data) { GstBuffer *buf = GST_BUFFER (_data); GstLPWSinc *filter; @@ -271,24 +271,24 @@ gst_lpwsinc_chain (GstPad * pad, GstData *_data) memcpy (&input[residue_samples], src, sizeof (gfloat) * input_samples); /* copy the tail of the current input buffer to the residue */ memcpy (filter->residue, &src[input_samples - residue_samples], - sizeof (gfloat) * residue_samples); + sizeof (gfloat) * residue_samples); /* convolution */ /* since we copied the previous set of samples we needed before the actual * input data, we need to add the filter length to our indices for input */ - for (i = 0; i < input_samples; ++i) - { + for (i = 0; i < input_samples; ++i) { src[i] = 0.0; for (j = 0; j < residue_samples; ++j) src[i] += input[i - j + residue_samples] * filter->kernel[j]; } - + g_free (input); gst_pad_push (filter->srcpad, GST_DATA (buf)); } static void -gst_lpwsinc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec) +gst_lpwsinc_set_property (GObject * object, guint prop_id, const GValue * value, + GParamSpec * pspec) { GstLPWSinc *filter; @@ -299,24 +299,25 @@ gst_lpwsinc_set_property (GObject * object, guint prop_id, const GValue * value, switch (prop_id) { case ARG_LENGTH: - filter->wing_size = g_value_get_int (value); - break; + filter->wing_size = g_value_get_int (value); + break; case ARG_FREQUENCY: - filter->frequency = g_value_get_double (value); - break; + filter->frequency = g_value_get_double (value); + break; default: break; } } static void -gst_lpwsinc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec) +gst_lpwsinc_get_property (GObject * object, guint prop_id, GValue * value, + GParamSpec * pspec) { GstLPWSinc *filter; /* it's not null if we got it, but it might not be ours */ g_return_if_fail (GST_IS_LPWSINC (object)); - + filter = GST_LPWSINC (object); switch (prop_id) { @@ -330,5 +331,4 @@ gst_lpwsinc_get_property (GObject * object, guint prop_id, GValue * value, GPara G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } -} - +} |