summaryrefslogtreecommitdiffstats
path: root/gst/audiofx/audiowsinclimit.c
diff options
context:
space:
mode:
Diffstat (limited to 'gst/audiofx/audiowsinclimit.c')
-rw-r--r--gst/audiofx/audiowsinclimit.c143
1 files changed, 55 insertions, 88 deletions
diff --git a/gst/audiofx/audiowsinclimit.c b/gst/audiofx/audiowsinclimit.c
index 3869553b..3cf14e5d 100644
--- a/gst/audiofx/audiowsinclimit.c
+++ b/gst/audiofx/audiowsinclimit.c
@@ -227,15 +227,17 @@ gst_lpwsinc_class_init (GstLPWSincClass * klass)
gobject_class->get_property = lpwsinc_get_property;
gobject_class->dispose = gst_lpwsinc_dispose;
+
+ /* FIXME: Don't use the complete possible range but restrict the upper boundary
+ * so automatically generated UIs can use a slider */
g_object_class_install_property (gobject_class, PROP_FREQUENCY,
- g_param_spec_double ("frequency", "Frequency",
- "Cut-off Frequency (Hz)", 0.0, G_MAXDOUBLE, 0.0,
+ g_param_spec_float ("cutoff", "Cutoff",
+ "Cut-off Frequency (Hz)", 0.0, 100000.0, 0.0,
G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
-
g_object_class_install_property (gobject_class, PROP_LENGTH,
g_param_spec_int ("length", "Length",
"Filter kernel length, will be rounded to the next odd number",
- 3, G_MAXINT, 101, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
+ 3, 50000, 101, G_PARAM_READWRITE | GST_PARAM_CONTROLLABLE));
g_object_class_install_property (gobject_class, PROP_MODE,
g_param_spec_enum ("mode", "Mode",
@@ -261,7 +263,7 @@ gst_lpwsinc_init (GstLPWSinc * self, GstLPWSincClass * g_class)
self->window = WINDOW_HAMMING;
self->kernel_length = 101;
self->latency = 50;
- self->frequency = 0.0;
+ self->cutoff = 0.0;
self->kernel = NULL;
self->residue = NULL;
@@ -275,86 +277,51 @@ gst_lpwsinc_init (GstLPWSinc * self, GstLPWSincClass * g_class)
lpwsinc_query_type);
}
-static void
-process_32 (GstLPWSinc * self, gfloat * src, gfloat * dst, guint input_samples)
-{
- gint kernel_length = self->kernel_length;
- gint i, j, k, l;
- gint channels = GST_AUDIO_FILTER (self)->format.channels;
- gint res_start;
-
- /* convolution */
- for (i = 0; i < input_samples; i++) {
- dst[i] = 0.0;
- k = i % channels;
- l = i / channels;
- for (j = 0; j < kernel_length; j++)
- if (l < j)
- dst[i] +=
- self->residue[(kernel_length + l - j) * channels +
- k] * self->kernel[j];
- else
- dst[i] += src[(l - j) * channels + k] * self->kernel[j];
- }
-
- /* copy the tail of the current input buffer to the residue, while
- * keeping parts of the residue if the input buffer is smaller than
- * the kernel length */
- if (input_samples < kernel_length * channels)
- res_start = kernel_length * channels - input_samples;
- else
- res_start = 0;
-
- for (i = 0; i < res_start; i++)
- self->residue[i] = self->residue[i + input_samples];
- for (i = res_start; i < kernel_length * channels; i++)
- self->residue[i] = src[input_samples - kernel_length * channels + i];
-
- self->residue_length += kernel_length * channels - res_start;
- if (self->residue_length > kernel_length * channels)
- self->residue_length = kernel_length * channels;
+#define DEFINE_PROCESS_FUNC(width,ctype) \
+static void \
+process_##width (GstLPWSinc * self, g##ctype * src, g##ctype * dst, guint input_samples) \
+{ \
+ gint kernel_length = self->kernel_length; \
+ gint i, j, k, l; \
+ gint channels = GST_AUDIO_FILTER (self)->format.channels; \
+ gint res_start; \
+ \
+ /* convolution */ \
+ for (i = 0; i < input_samples; i++) { \
+ dst[i] = 0.0; \
+ k = i % channels; \
+ l = i / channels; \
+ for (j = 0; j < kernel_length; j++) \
+ if (l < j) \
+ dst[i] += \
+ self->residue[(kernel_length + l - j) * channels + \
+ k] * self->kernel[j]; \
+ else \
+ dst[i] += src[(l - j) * channels + k] * self->kernel[j]; \
+ } \
+ \
+ /* copy the tail of the current input buffer to the residue, while \
+ * keeping parts of the residue if the input buffer is smaller than \
+ * the kernel length */ \
+ if (input_samples < kernel_length * channels) \
+ res_start = kernel_length * channels - input_samples; \
+ else \
+ res_start = 0; \
+ \
+ for (i = 0; i < res_start; i++) \
+ self->residue[i] = self->residue[i + input_samples]; \
+ for (i = res_start; i < kernel_length * channels; i++) \
+ self->residue[i] = src[input_samples - kernel_length * channels + i]; \
+ \
+ self->residue_length += kernel_length * channels - res_start; \
+ if (self->residue_length > kernel_length * channels) \
+ self->residue_length = kernel_length * channels; \
}
-static void
-process_64 (GstLPWSinc * self, gdouble * src, gdouble * dst,
- guint input_samples)
-{
- gint kernel_length = self->kernel_length;
- gint i, j, k, l;
- gint channels = GST_AUDIO_FILTER (self)->format.channels;
- gint res_start;
-
- /* convolution */
- for (i = 0; i < input_samples; i++) {
- dst[i] = 0.0;
- k = i % channels;
- l = i / channels;
- for (j = 0; j < kernel_length; j++)
- if (l < j)
- dst[i] +=
- self->residue[(kernel_length + l - j) * channels +
- k] * self->kernel[j];
- else
- dst[i] += src[(l - j) * channels + k] * self->kernel[j];
- }
+DEFINE_PROCESS_FUNC (32, float);
+DEFINE_PROCESS_FUNC (64, double);
- /* copy the tail of the current input buffer to the residue, while
- * keeping parts of the residue if the input buffer is smaller than
- * the kernel length */
- if (input_samples < kernel_length * channels)
- res_start = kernel_length * channels - input_samples;
- else
- res_start = 0;
-
- for (i = 0; i < res_start; i++)
- self->residue[i] = self->residue[i + input_samples];
- for (i = res_start; i < kernel_length * channels; i++)
- self->residue[i] = src[input_samples - kernel_length * channels + i];
-
- self->residue_length += kernel_length * channels - res_start;
- if (self->residue_length > kernel_length * channels)
- self->residue_length = kernel_length * channels;
-}
+#undef DEFINE_PROCESS_FUNC
static void
lpwsinc_build_kernel (GstLPWSinc * self)
@@ -377,17 +344,17 @@ lpwsinc_build_kernel (GstLPWSinc * self)
}
/* Clamp cutoff frequency between 0 and the nyquist frequency */
- self->frequency =
- CLAMP (self->frequency, 0.0, GST_AUDIO_FILTER (self)->format.rate / 2);
+ self->cutoff =
+ CLAMP (self->cutoff, 0.0, GST_AUDIO_FILTER (self)->format.rate / 2);
GST_DEBUG ("lpwsinc: initializing filter kernel of length %d "
"with cutoff %.2lf Hz "
"for mode %s",
- len, self->frequency,
+ len, self->cutoff,
(self->mode == MODE_LOW_PASS) ? "low-pass" : "high-pass");
/* fill the kernel */
- w = 2 * M_PI * (self->frequency / GST_AUDIO_FILTER (self)->format.rate);
+ w = 2 * M_PI * (self->cutoff / GST_AUDIO_FILTER (self)->format.rate);
if (self->kernel)
g_free (self->kernel);
@@ -800,7 +767,7 @@ lpwsinc_set_property (GObject * object, guint prop_id, const GValue * value,
}
case PROP_FREQUENCY:
GST_BASE_TRANSFORM_LOCK (self);
- self->frequency = g_value_get_double (value);
+ self->cutoff = g_value_get_float (value);
lpwsinc_build_kernel (self);
GST_BASE_TRANSFORM_UNLOCK (self);
break;
@@ -833,7 +800,7 @@ lpwsinc_get_property (GObject * object, guint prop_id, GValue * value,
g_value_set_int (value, self->kernel_length);
break;
case PROP_FREQUENCY:
- g_value_set_double (value, self->frequency);
+ g_value_set_float (value, self->cutoff);
break;
case PROP_MODE:
g_value_set_enum (value, self->mode);