summaryrefslogtreecommitdiffstats
path: root/gst/audiofx/audiowsincband.c
diff options
context:
space:
mode:
authorThomas Vander Stichele <thomas@apestaart.org>2004-03-14 22:34:33 +0000
committerThomas Vander Stichele <thomas@apestaart.org>2004-03-14 22:34:33 +0000
commit5d25c00e4b613b9cdf2c04fa3a68dffa03834a68 (patch)
tree74a5b1eaf3a324b520e64e87404fd0b3018a7829 /gst/audiofx/audiowsincband.c
parent1e83b097f7b732ae49e294a5a398bdc3e88854a8 (diff)
gst-indent
Original commit message from CVS: gst-indent
Diffstat (limited to 'gst/audiofx/audiowsincband.c')
-rw-r--r--gst/audiofx/audiowsincband.c185
1 files changed, 93 insertions, 92 deletions
diff --git a/gst/audiofx/audiowsincband.c b/gst/audiofx/audiowsincband.c
index 77529053..a848cc26 100644
--- a/gst/audiofx/audiowsincband.c
+++ b/gst/audiofx/audiowsincband.c
@@ -39,20 +39,19 @@
#include <string.h> /* memmove */
/* elementfactory information */
-static GstElementDetails gst_bpwsinc_details = GST_ELEMENT_DETAILS (
- "BPWSinc",
- "Filter/Effect/Audio",
- "Band-Pass Windowed sinc filter",
- "Thomas <thomas@apestaart.org>, "
- "Steven W. Smith"
-);
-
-enum {
+static GstElementDetails gst_bpwsinc_details = GST_ELEMENT_DETAILS ("BPWSinc",
+ "Filter/Effect/Audio",
+ "Band-Pass Windowed sinc filter",
+ "Thomas <thomas@apestaart.org>, " "Steven W. Smith");
+
+enum
+{
/* FILL ME */
LAST_SIGNAL
};
-enum {
+enum
+{
ARG_0,
ARG_LENGTH,
ARG_LOWER_FREQUENCY,
@@ -81,51 +80,52 @@ struct _GstBPWSinc
double frequency;
double lower_frequency, upper_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 _GstBPWSincClass
{
- GstElementClass parent_class;
+ GstElementClass parent_class;
};
-static void gst_bpwsinc_base_init (gpointer g_class);
-static void gst_bpwsinc_class_init (GstBPWSincClass * klass);
-static void gst_bpwsinc_init (GstBPWSinc * filter);
+static void gst_bpwsinc_base_init (gpointer g_class);
+static void gst_bpwsinc_class_init (GstBPWSincClass * klass);
+static void gst_bpwsinc_init (GstBPWSinc * filter);
-static void gst_bpwsinc_set_property (GObject * object, guint prop_id,
- const GValue * value,
- GParamSpec * pspec);
-static void gst_bpwsinc_get_property (GObject * object, guint prop_id,
- GValue * value, GParamSpec * pspec);
+static void gst_bpwsinc_set_property (GObject * object, guint prop_id,
+ const GValue * value, GParamSpec * pspec);
+static void gst_bpwsinc_get_property (GObject * object, guint prop_id,
+ GValue * value, GParamSpec * pspec);
-static void gst_bpwsinc_chain (GstPad * pad, GstData *_data);
+static void gst_bpwsinc_chain (GstPad * pad, GstData * _data);
static GstPadLinkReturn
- gst_bpwsinc_sink_connect (GstPad * pad, const GstCaps * caps);
+gst_bpwsinc_sink_connect (GstPad * pad, const GstCaps * caps);
static GstElementClass *parent_class = NULL;
+
/*static guint gst_bpwsinc_signals[LAST_SIGNAL] = { 0 }; */
-GType gst_bpwsinc_get_type (void)
+GType
+gst_bpwsinc_get_type (void)
{
static GType bpwsinc_type = 0;
if (!bpwsinc_type) {
static const GTypeInfo bpwsinc_info = {
- sizeof (GstBPWSincClass),
- gst_bpwsinc_base_init,
+ sizeof (GstBPWSincClass),
+ gst_bpwsinc_base_init,
NULL,
(GClassInitFunc) gst_bpwsinc_class_init, NULL, NULL,
sizeof (GstBPWSinc), 0,
(GInstanceInitFunc) gst_bpwsinc_init,
};
- bpwsinc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstBPWSinc",
- &bpwsinc_info, 0);
+ bpwsinc_type = g_type_register_static (GST_TYPE_ELEMENT, "GstBPWSinc",
+ &bpwsinc_info, 0);
}
return bpwsinc_type;
}
@@ -139,9 +139,9 @@ gst_bpwsinc_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_bpwsinc_details);
+ gst_element_class_set_details (element_class, &gst_bpwsinc_details);
}
static void
@@ -156,20 +156,17 @@ gst_bpwsinc_class_init (GstBPWSincClass * klass)
parent_class = g_type_class_ref (GST_TYPE_ELEMENT);
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_LOWER_FREQUENCY,
- g_param_spec_double ("lower-frequency", "Lower Frequency",
- "Cut-off lower frequency (relative to sample rate)",
- 0.0, 0.5,
- 0, G_PARAM_READWRITE));
+ g_param_spec_double ("lower-frequency", "Lower Frequency",
+ "Cut-off lower frequency (relative to sample rate)",
+ 0.0, 0.5, 0, G_PARAM_READWRITE));
g_object_class_install_property (G_OBJECT_CLASS (klass), ARG_UPPER_FREQUENCY,
- g_param_spec_double ("upper-frequency", "Upper Frequency",
- "Cut-off upper frequency (relative to sample rate)",
- 0.0, 0.5,
- 0, G_PARAM_READWRITE));
+ g_param_spec_double ("upper-frequency", "Upper Frequency",
+ "Cut-off upper 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_bpwsinc_set_property;
gobject_class->get_property = gst_bpwsinc_get_property;
@@ -178,14 +175,16 @@ gst_bpwsinc_class_init (GstBPWSincClass * klass)
static void
gst_bpwsinc_init (GstBPWSinc * 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_bpwsinc_chain);
gst_pad_set_link_function (filter->sinkpad, gst_bpwsinc_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;
@@ -202,65 +201,65 @@ gst_bpwsinc_sink_connect (GstPad * pad, const GstCaps * caps)
int len = 0;
double *kernel_lp, *kernel_hp;
GstPadLinkReturn set_retval;
-
+
GstBPWSinc *filter = GST_BPWSINC (gst_pad_get_parent (pad));
g_assert (GST_IS_PAD (pad));
g_assert (caps != NULL);
set_retval = gst_pad_try_set_caps (filter->srcpad, caps);
-
- if (set_retval > 0)
- {
+
+ if (set_retval > 0) {
len = filter->wing_size;
/* fill the lp kernel */
- GST_DEBUG (
- "bpwsinc: initializing LP kernel of length %d with cut-off %f",
- len * 2 + 1, filter->lower_frequency);
+ GST_DEBUG ("bpwsinc: initializing LP kernel of length %d with cut-off %f",
+ len * 2 + 1, filter->lower_frequency);
kernel_lp = (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)
kernel_lp[i] = 2 * M_PI * filter->lower_frequency;
else
- kernel_lp[i] = sin (2 * M_PI * filter->lower_frequency * (i - len))
- / (i - len);
+ kernel_lp[i] = sin (2 * M_PI * filter->lower_frequency * (i - len))
+ / (i - len);
/* Blackman windowing */
- kernel_lp[i] *= (0.42 - 0.5 * cos (M_PI * i / len)
- + 0.08 * cos (2 * M_PI * i / len));
+ kernel_lp[i] *= (0.42 - 0.5 * cos (M_PI * i / len)
+ + 0.08 * cos (2 * M_PI * i / len));
}
/* normalize for unity gain at DC
* FIXME: sure this is not supposed to be quadratic ? */
sum = 0.0;
- for (i = 0; i <= len * 2; ++i) sum += kernel_lp[i];
- for (i = 0; i <= len * 2; ++i) kernel_lp[i] /= sum;
+ for (i = 0; i <= len * 2; ++i)
+ sum += kernel_lp[i];
+ for (i = 0; i <= len * 2; ++i)
+ kernel_lp[i] /= sum;
/* fill the hp kernel */
- GST_DEBUG (
- "bpwsinc: initializing HP kernel of length %d with cut-off %f",
- len * 2 + 1, filter->upper_frequency);
+ GST_DEBUG ("bpwsinc: initializing HP kernel of length %d with cut-off %f",
+ len * 2 + 1, filter->upper_frequency);
kernel_hp = (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)
kernel_hp[i] = 2 * M_PI * filter->upper_frequency;
else
- kernel_hp[i] = sin (2 * M_PI * filter->upper_frequency * (i - len))
- / (i - len);
+ kernel_hp[i] = sin (2 * M_PI * filter->upper_frequency * (i - len))
+ / (i - len);
/* Blackman windowing */
- kernel_hp[i] *= (0.42 - 0.5 * cos (M_PI * i / len)
- + 0.08 * cos (2 * M_PI * i / len));
+ kernel_hp[i] *= (0.42 - 0.5 * cos (M_PI * i / len)
+ + 0.08 * cos (2 * M_PI * i / len));
}
/* normalize for unity gain at DC
* FIXME: sure this is not supposed to be quadratic ? */
sum = 0.0;
- for (i = 0; i <= len * 2; ++i) sum += kernel_hp[i];
- for (i = 0; i <= len * 2; ++i) kernel_hp[i] /= sum;
+ for (i = 0; i <= len * 2; ++i)
+ sum += kernel_hp[i];
+ for (i = 0; i <= len * 2; ++i)
+ kernel_hp[i] /= sum;
/* do spectral inversion to get a HP filter */
- for (i = 0; i <= len * 2; ++i) kernel_hp[i] = -kernel_hp[i];
+ for (i = 0; i <= len * 2; ++i)
+ kernel_hp[i] = -kernel_hp[i];
kernel_hp[len] += 1;
/* combine the two filters */
@@ -271,7 +270,8 @@ gst_bpwsinc_sink_connect (GstPad * pad, const GstCaps * caps)
filter->kernel[i] = kernel_lp[i] + kernel_hp[i];
/* do spectral inversion to go from band reject to bandpass */
- for (i = 0; i <= len * 2; ++i) filter->kernel[i] = -filter->kernel[i];
+ for (i = 0; i <= len * 2; ++i)
+ filter->kernel[i] = -filter->kernel[i];
filter->kernel[len] += 1;
/* free the helper kernels */
@@ -280,14 +280,15 @@ gst_bpwsinc_sink_connect (GstPad * pad, const GstCaps * caps)
/* 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_bpwsinc_chain (GstPad *pad, GstData *_data)
+gst_bpwsinc_chain (GstPad * pad, GstData * _data)
{
GstBuffer *buf = GST_BUFFER (_data);
GstBPWSinc *filter;
@@ -323,24 +324,24 @@ gst_bpwsinc_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_bpwsinc_set_property (GObject * object, guint prop_id, const GValue * value, GParamSpec * pspec)
+gst_bpwsinc_set_property (GObject * object, guint prop_id, const GValue * value,
+ GParamSpec * pspec)
{
GstBPWSinc *filter;
@@ -351,27 +352,28 @@ gst_bpwsinc_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_LOWER_FREQUENCY:
- filter->lower_frequency = g_value_get_double (value);
- break;
+ filter->lower_frequency = g_value_get_double (value);
+ break;
case ARG_UPPER_FREQUENCY:
- filter->upper_frequency = g_value_get_double (value);
- break;
+ filter->upper_frequency = g_value_get_double (value);
+ break;
default:
break;
}
}
static void
-gst_bpwsinc_get_property (GObject * object, guint prop_id, GValue * value, GParamSpec * pspec)
+gst_bpwsinc_get_property (GObject * object, guint prop_id, GValue * value,
+ GParamSpec * pspec)
{
GstBPWSinc *filter;
/* it's not null if we got it, but it might not be ours */
g_return_if_fail (GST_IS_BPWSINC (object));
-
+
filter = GST_BPWSINC (object);
switch (prop_id) {
@@ -388,5 +390,4 @@ gst_bpwsinc_get_property (GObject * object, guint prop_id, GValue * value, GPara
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
-}
-
+}