gst/filter/gstbpwsinc.*: Implement latency query and only forward those samples downstream that actually contain the ...

Original commit message from CVS:
* gst/filter/gstbpwsinc.c: (gst_bpwsinc_class_init),
(gst_bpwsinc_init), (process_32), (process_64),
(bpwsinc_build_kernel), (bpwsinc_push_residue),
(bpwsinc_transform), (bpwsinc_start), (bpwsinc_query),
(bpwsinc_query_type), (bpwsinc_event), (bpwsinc_set_property):
* gst/filter/gstbpwsinc.h:
Implement latency query and only forward those samples downstream
that actually contain the data we want, i.e. drop kernel_length/2
in the beginning and append kernel_length/2 (created by convolving
the filter kernel with zeroes) to the end.
* tests/check/elements/bpwsinc.c: (GST_START_TEST):
Adjust the unit test for this slightly changed behaviour.
* gst/filter/gstlpwsinc.c: (lpwsinc_build_kernel):
Reset residue length only when actually creating a residue.
This commit is contained in:
Sebastian Dröge 2007-08-16 19:22:48 +00:00
parent 842451a720
commit fc8a487616
4 changed files with 392 additions and 76 deletions

View file

@ -173,10 +173,14 @@ static GstFlowReturn bpwsinc_transform (GstBaseTransform * base,
static gboolean bpwsinc_get_unit_size (GstBaseTransform * base, GstCaps * caps, static gboolean bpwsinc_get_unit_size (GstBaseTransform * base, GstCaps * caps,
guint * size); guint * size);
static gboolean bpwsinc_start (GstBaseTransform * base); static gboolean bpwsinc_start (GstBaseTransform * base);
static gboolean bpwsinc_event (GstBaseTransform * base, GstEvent * event);
static gboolean bpwsinc_setup (GstAudioFilter * base, static gboolean bpwsinc_setup (GstAudioFilter * base,
GstRingBufferSpec * format); GstRingBufferSpec * format);
static gboolean bpwsinc_query (GstPad * pad, GstQuery * query);
static const GstQueryType *bpwsinc_query_type (GstPad * pad);
/* Element class */ /* Element class */
static void static void
@ -252,6 +256,7 @@ gst_bpwsinc_class_init (GstBPWSincClass * klass)
trans_class->transform = GST_DEBUG_FUNCPTR (bpwsinc_transform); trans_class->transform = GST_DEBUG_FUNCPTR (bpwsinc_transform);
trans_class->get_unit_size = GST_DEBUG_FUNCPTR (bpwsinc_get_unit_size); trans_class->get_unit_size = GST_DEBUG_FUNCPTR (bpwsinc_get_unit_size);
trans_class->start = GST_DEBUG_FUNCPTR (bpwsinc_start); trans_class->start = GST_DEBUG_FUNCPTR (bpwsinc_start);
trans_class->event = GST_DEBUG_FUNCPTR (bpwsinc_event);
filter_class->setup = GST_DEBUG_FUNCPTR (bpwsinc_setup); filter_class->setup = GST_DEBUG_FUNCPTR (bpwsinc_setup);
} }
@ -259,6 +264,7 @@ static void
gst_bpwsinc_init (GstBPWSinc * self, GstBPWSincClass * g_class) gst_bpwsinc_init (GstBPWSinc * self, GstBPWSincClass * g_class)
{ {
self->kernel_length = 101; self->kernel_length = 101;
self->latency = 50;
self->lower_frequency = 0.0; self->lower_frequency = 0.0;
self->upper_frequency = 0.0; self->upper_frequency = 0.0;
self->mode = MODE_BAND_PASS; self->mode = MODE_BAND_PASS;
@ -266,6 +272,14 @@ gst_bpwsinc_init (GstBPWSinc * self, GstBPWSincClass * g_class)
self->kernel = NULL; self->kernel = NULL;
self->have_kernel = FALSE; self->have_kernel = FALSE;
self->residue = NULL; self->residue = NULL;
self->residue_length = 0;
self->next_ts = GST_CLOCK_TIME_NONE;
self->next_off = GST_BUFFER_OFFSET_NONE;
gst_pad_set_query_function (GST_BASE_TRANSFORM (self)->srcpad, bpwsinc_query);
gst_pad_set_query_type_function (GST_BASE_TRANSFORM (self)->srcpad,
bpwsinc_query_type);
} }
static void static void
@ -302,6 +316,10 @@ process_32 (GstBPWSinc * self, gfloat * src, gfloat * dst, guint input_samples)
self->residue[i] = self->residue[i + input_samples]; self->residue[i] = self->residue[i + input_samples];
for (i = res_start; i < kernel_length * channels; i++) for (i = res_start; i < kernel_length * channels; i++)
self->residue[i] = src[input_samples - 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 static void
@ -339,6 +357,10 @@ process_64 (GstBPWSinc * self, gdouble * src, gdouble * dst,
self->residue[i] = self->residue[i + input_samples]; self->residue[i] = self->residue[i + input_samples];
for (i = res_start; i < kernel_length * channels; i++) for (i = res_start; i < kernel_length * channels; i++)
self->residue[i] = src[input_samples - 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 static void
@ -458,14 +480,91 @@ bpwsinc_build_kernel (GstBPWSinc * self)
} }
/* set up the residue memory space */ /* set up the residue memory space */
if (self->residue) if (!self->residue) {
g_free (self->residue); self->residue =
self->residue = g_new0 (gdouble, len * GST_AUDIO_FILTER (self)->format.channels);
g_new0 (gdouble, len * GST_AUDIO_FILTER (self)->format.channels); self->residue_length = 0;
}
self->have_kernel = TRUE; self->have_kernel = TRUE;
} }
static void
bpwsinc_push_residue (GstBPWSinc * self)
{
GstBuffer *outbuf;
GstFlowReturn res;
gint rate = GST_AUDIO_FILTER (self)->format.rate;
gint channels = GST_AUDIO_FILTER (self)->format.channels;
gint outsize, outsamples;
gint diffsize, diffsamples;
guint8 *in, *out;
/* Calculate the number of samples and their memory size that
* should be pushed from the residue */
outsamples = MIN (self->latency, self->residue_length / channels);
outsize = outsamples * channels * (GST_AUDIO_FILTER (self)->format.width / 8);
if (outsize == 0)
return;
/* Process the difference between latency and residue_length samples
* to start at the actual data instead of starting at the zeros before
* when we only got one buffer smaller than latency */
diffsamples = self->latency - self->residue_length / channels;
diffsize =
diffsamples * channels * (GST_AUDIO_FILTER (self)->format.width / 8);
if (diffsize > 0) {
in = g_new0 (guint8, diffsize);
out = g_new0 (guint8, diffsize);
self->process (self, in, out, diffsamples * channels);
g_free (in);
g_free (out);
}
res = gst_pad_alloc_buffer (GST_BASE_TRANSFORM (self)->srcpad,
GST_BUFFER_OFFSET_NONE, outsize,
GST_PAD_CAPS (GST_BASE_TRANSFORM (self)->srcpad), &outbuf);
if (G_UNLIKELY (res != GST_FLOW_OK)) {
GST_WARNING_OBJECT (self, "failed allocating buffer of %d bytes", outsize);
return;
}
/* Convolve the residue with zeros to get the actual remaining data */
in = g_new0 (guint8, outsize);
self->process (self, in, GST_BUFFER_DATA (outbuf), outsamples * channels);
g_free (in);
/* Set timestamp, offset, etc from the values we
* saved when processing the regular buffers */
if (GST_CLOCK_TIME_IS_VALID (self->next_ts))
GST_BUFFER_TIMESTAMP (outbuf) = self->next_ts;
else
GST_BUFFER_TIMESTAMP (outbuf) = 0;
GST_BUFFER_DURATION (outbuf) =
gst_util_uint64_scale (outsamples, GST_SECOND, rate);
self->next_ts += gst_util_uint64_scale (outsamples, GST_SECOND, rate);
if (self->next_off != GST_BUFFER_OFFSET_NONE) {
GST_BUFFER_OFFSET (outbuf) = self->next_off;
GST_BUFFER_OFFSET_END (outbuf) = self->next_off + outsamples;
}
GST_DEBUG_OBJECT (self, "Pushing residue buffer of size %d with timestamp: %"
GST_TIME_FORMAT ", duration: %" GST_TIME_FORMAT ", offset: %lld,"
" offset_end: %lld, nsamples: %d", GST_BUFFER_SIZE (outbuf),
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)), GST_BUFFER_OFFSET (outbuf),
GST_BUFFER_OFFSET_END (outbuf), outsamples);
res = gst_pad_push (GST_BASE_TRANSFORM (self)->srcpad, outbuf);
if (G_UNLIKELY (res != GST_FLOW_OK)) {
GST_WARNING_OBJECT (self, "failed to push residue");
}
}
/* GstAudioFilter vmethod implementations */ /* GstAudioFilter vmethod implementations */
/* get notified of caps and plug in the correct process function */ /* get notified of caps and plug in the correct process function */
@ -514,8 +613,12 @@ bpwsinc_transform (GstBaseTransform * base, GstBuffer * inbuf,
{ {
GstBPWSinc *self = GST_BPWSINC (base); GstBPWSinc *self = GST_BPWSINC (base);
GstClockTime timestamp; GstClockTime timestamp;
gint channels = GST_AUDIO_FILTER (self)->format.channels;
gint rate = GST_AUDIO_FILTER (self)->format.rate;
gint input_samples = gint input_samples =
GST_BUFFER_SIZE (outbuf) / (GST_AUDIO_FILTER (self)->format.width / 8); GST_BUFFER_SIZE (outbuf) / (GST_AUDIO_FILTER (self)->format.width / 8);
gint output_samples = input_samples;
gint diff;
/* don't process data in passthrough-mode */ /* don't process data in passthrough-mode */
if (gst_base_transform_is_passthrough (base)) if (gst_base_transform_is_passthrough (base))
@ -530,9 +633,100 @@ bpwsinc_transform (GstBaseTransform * base, GstBuffer * inbuf,
if (!self->have_kernel) if (!self->have_kernel)
bpwsinc_build_kernel (self); bpwsinc_build_kernel (self);
/* Reset the residue if already existing on discont buffers */
if (GST_BUFFER_IS_DISCONT (inbuf)) {
if (channels && self->residue)
memset (self->residue, 0, channels *
self->kernel_length * sizeof (gdouble));
self->residue_length = 0;
self->next_ts = GST_CLOCK_TIME_NONE;
self->next_off = GST_BUFFER_OFFSET_NONE;
}
/* Calculate the number of samples we can push out now without outputting
* kernel_length/2 zeros in the beginning */
diff = (self->kernel_length / 2) * channels - self->residue_length;
if (diff > 0)
output_samples -= diff;
self->process (self, GST_BUFFER_DATA (inbuf), GST_BUFFER_DATA (outbuf), self->process (self, GST_BUFFER_DATA (inbuf), GST_BUFFER_DATA (outbuf),
input_samples); input_samples);
if (output_samples <= 0) {
/* Drop buffer and save original timestamp/offset for later use */
if (!GST_CLOCK_TIME_IS_VALID (self->next_ts)
&& GST_BUFFER_TIMESTAMP_IS_VALID (outbuf))
self->next_ts = GST_BUFFER_TIMESTAMP (outbuf);
if (self->next_off == GST_BUFFER_OFFSET_NONE
&& GST_BUFFER_OFFSET_IS_VALID (outbuf))
self->next_off = GST_BUFFER_OFFSET (outbuf);
return GST_BASE_TRANSFORM_FLOW_DROPPED;
} else if (output_samples < input_samples) {
/* First (probably partial) buffer after starting from
* a clean residue. Use stored timestamp/offset here */
if (GST_CLOCK_TIME_IS_VALID (self->next_ts))
GST_BUFFER_TIMESTAMP (outbuf) = self->next_ts;
if (self->next_off != GST_BUFFER_OFFSET_NONE) {
GST_BUFFER_OFFSET (outbuf) = self->next_off;
if (GST_BUFFER_OFFSET_END_IS_VALID (outbuf))
GST_BUFFER_OFFSET_END (outbuf) =
self->next_off + output_samples / channels;
} else {
/* We dropped no buffer, offset is valid, offset_end must be adjusted by diff */
if (GST_BUFFER_OFFSET_END_IS_VALID (outbuf))
GST_BUFFER_OFFSET_END (outbuf) -= diff / channels;
}
if (GST_BUFFER_DURATION_IS_VALID (outbuf))
GST_BUFFER_DURATION (outbuf) -=
gst_util_uint64_scale (diff, GST_SECOND, channels * rate);
GST_BUFFER_DATA (outbuf) +=
diff * (GST_AUDIO_FILTER (self)->format.width / 8);
GST_BUFFER_SIZE (outbuf) -=
diff * (GST_AUDIO_FILTER (self)->format.width / 8);
} else {
GstClockTime ts_latency =
gst_util_uint64_scale (self->latency, GST_SECOND, rate);
/* Normal buffer, adjust timestamp/offset/etc by latency */
if (GST_BUFFER_TIMESTAMP (outbuf) < ts_latency) {
GST_WARNING_OBJECT (self, "GST_BUFFER_TIMESTAMP (outbuf) < latency");
GST_BUFFER_TIMESTAMP (outbuf) = 0;
} else {
GST_BUFFER_TIMESTAMP (outbuf) -= ts_latency;
}
if (GST_BUFFER_OFFSET_IS_VALID (outbuf)) {
if (GST_BUFFER_OFFSET (outbuf) > self->latency) {
GST_BUFFER_OFFSET (outbuf) -= self->latency;
} else {
GST_WARNING_OBJECT (self, "GST_BUFFER_OFFSET (outbuf) < latency");
GST_BUFFER_OFFSET (outbuf) = 0;
}
}
if (GST_BUFFER_OFFSET_END_IS_VALID (outbuf)) {
if (GST_BUFFER_OFFSET_END (outbuf) > self->latency) {
GST_BUFFER_OFFSET_END (outbuf) -= self->latency;
} else {
GST_WARNING_OBJECT (self, "GST_BUFFER_OFFSET_END (outbuf) < latency");
GST_BUFFER_OFFSET_END (outbuf) = 0;
}
}
}
GST_DEBUG_OBJECT (self, "Pushing buffer of size %d with timestamp: %"
GST_TIME_FORMAT ", duration: %" GST_TIME_FORMAT ", offset: %lld,"
" offset_end: %lld, nsamples: %d", GST_BUFFER_SIZE (outbuf),
GST_TIME_ARGS (GST_BUFFER_TIMESTAMP (outbuf)),
GST_TIME_ARGS (GST_BUFFER_DURATION (outbuf)), GST_BUFFER_OFFSET (outbuf),
GST_BUFFER_OFFSET_END (outbuf), output_samples / channels);
self->next_ts = GST_BUFFER_TIMESTAMP (outbuf) + GST_BUFFER_DURATION (outbuf);
self->next_off = GST_BUFFER_OFFSET_END (outbuf);
return GST_FLOW_OK; return GST_FLOW_OK;
} }
@ -547,9 +741,93 @@ bpwsinc_start (GstBaseTransform * base)
memset (self->residue, 0, channels * memset (self->residue, 0, channels *
self->kernel_length * sizeof (gdouble)); self->kernel_length * sizeof (gdouble));
self->residue_length = 0;
self->next_ts = GST_CLOCK_TIME_NONE;
self->next_off = GST_BUFFER_OFFSET_NONE;
return TRUE; return TRUE;
} }
static gboolean
bpwsinc_query (GstPad * pad, GstQuery * query)
{
GstBPWSinc *self = GST_BPWSINC (gst_pad_get_parent (pad));
gboolean res = TRUE;
switch (GST_QUERY_TYPE (query)) {
case GST_QUERY_LATENCY:
{
GstClockTime min, max;
gboolean live;
guint64 latency;
GstPad *peer;
gint rate = GST_AUDIO_FILTER (self)->format.rate;
if ((peer = gst_pad_get_peer (GST_BASE_TRANSFORM (self)->sinkpad))) {
if ((res = gst_pad_query (peer, query))) {
gst_query_parse_latency (query, &live, &min, &max);
GST_DEBUG_OBJECT (self, "Peer latency: min %"
GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
GST_TIME_ARGS (min), GST_TIME_ARGS (max));
/* add our own latency */
latency =
(rate != 0) ? gst_util_uint64_scale (self->latency, GST_SECOND,
rate) : 0;
GST_DEBUG_OBJECT (self, "Our latency: %"
GST_TIME_FORMAT, GST_TIME_ARGS (latency));
min += latency;
if (max != GST_CLOCK_TIME_NONE)
max += latency;
GST_DEBUG_OBJECT (self, "Calculated total latency : min %"
GST_TIME_FORMAT " max %" GST_TIME_FORMAT,
GST_TIME_ARGS (min), GST_TIME_ARGS (max));
gst_query_set_latency (query, live, min, max);
}
gst_object_unref (peer);
}
break;
}
default:
res = gst_pad_query_default (pad, query);
break;
}
gst_object_unref (self);
return res;
}
static const GstQueryType *
bpwsinc_query_type (GstPad * pad)
{
static const GstQueryType types[] = {
GST_QUERY_LATENCY,
0
};
return types;
}
static gboolean
bpwsinc_event (GstBaseTransform * base, GstEvent * event)
{
GstBPWSinc *self = GST_BPWSINC (base);
switch (GST_EVENT_TYPE (event)) {
case GST_EVENT_EOS:
bpwsinc_push_residue (self);
break;
default:
break;
}
return GST_BASE_TRANSFORM_CLASS (parent_class)->event (base, event);
}
static void static void
bpwsinc_set_property (GObject * object, guint prop_id, const GValue * value, bpwsinc_set_property (GObject * object, guint prop_id, const GValue * value,
GParamSpec * pspec) GParamSpec * pspec)
@ -566,8 +844,17 @@ bpwsinc_set_property (GObject * object, guint prop_id, const GValue * value,
val = g_value_get_int (value); val = g_value_get_int (value);
if (val % 2 == 0) if (val % 2 == 0)
val++; val++;
self->kernel_length = val;
bpwsinc_build_kernel (self); if (val != self->kernel_length) {
if (self->residue) {
bpwsinc_push_residue (self);
g_free (self->residue);
self->residue = NULL;
}
self->kernel_length = val;
self->latency = val / 2;
bpwsinc_build_kernel (self);
}
GST_BASE_TRANSFORM_UNLOCK (self); GST_BASE_TRANSFORM_UNLOCK (self);
break; break;
} }

View file

@ -71,6 +71,10 @@ struct _GstBPWSinc {
gdouble *residue; /* buffer for left-over samples from previous buffer */ gdouble *residue; /* buffer for left-over samples from previous buffer */
gdouble *kernel; gdouble *kernel;
gboolean have_kernel; gboolean have_kernel;
gint residue_length;
guint64 latency;
GstClockTime next_ts;
guint64 next_off;
}; };
struct _GstBPWSincClass { struct _GstBPWSincClass {

View file

@ -421,12 +421,13 @@ lpwsinc_build_kernel (GstLPWSinc * self)
} }
/* set up the residue memory space */ /* set up the residue memory space */
if (!self->residue) if (!self->residue) {
self->residue = self->residue =
g_new0 (gdouble, len * GST_AUDIO_FILTER (self)->format.channels); g_new0 (gdouble, len * GST_AUDIO_FILTER (self)->format.channels);
self->residue_length = 0;
}
self->have_kernel = TRUE; self->have_kernel = TRUE;
self->residue_length = 0;
} }
static void static void

View file

@ -96,6 +96,7 @@ GST_START_TEST (test_bp_0hz)
GstCaps *caps; GstCaps *caps;
gdouble *in, *res, rms; gdouble *in, *res, rms;
gint i; gint i;
GList *node;
bpwsinc = setup_bpwsinc (); bpwsinc = setup_bpwsinc ();
/* Set to bandpass */ /* Set to bandpass */
@ -122,22 +123,24 @@ GST_START_TEST (test_bp_0hz)
/* pushing gives away my reference ... */ /* pushing gives away my reference ... */
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
/* ... and puts a new buffer on the global list */ /* ... and puts a new buffer on the global list */
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless (g_list_length (buffers) >= 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); for (node = buffers; node; node = node->next) {
for (i = 31; i < 1024; i++) { gint buffer_length;
fail_unless (res[i] <= 0.01
&& res[i] >= -0.01, "res[%d] = %lf\n", i, res[i]); fail_if ((outbuffer = (GstBuffer *) node->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
buffer_length = GST_BUFFER_SIZE (outbuffer) / sizeof (gdouble);
rms = 0.0;
for (i = 0; i < buffer_length; i++)
rms += res[i] * res[i];
rms = sqrt (rms / buffer_length);
fail_unless (rms <= 0.1);
} }
rms = 0.0;
for (i = 0; i < 1024; i++)
rms += res[i] * res[i];
rms = sqrt (rms / 1024.0);
fail_unless (rms <= 0.1);
/* cleanup */ /* cleanup */
cleanup_bpwsinc (bpwsinc); cleanup_bpwsinc (bpwsinc);
} }
@ -154,6 +157,7 @@ GST_START_TEST (test_bp_11025hz)
GstCaps *caps; GstCaps *caps;
gdouble *in, *res, rms; gdouble *in, *res, rms;
gint i; gint i;
GList *node;
bpwsinc = setup_bpwsinc (); bpwsinc = setup_bpwsinc ();
/* Set to bandpass */ /* Set to bandpass */
@ -184,17 +188,23 @@ GST_START_TEST (test_bp_11025hz)
/* pushing gives away my reference ... */ /* pushing gives away my reference ... */
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
/* ... and puts a new buffer on the global list */ /* ... and puts a new buffer on the global list */
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless (g_list_length (buffers) >= 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); for (node = buffers; node; node = node->next) {
gint buffer_length;
rms = 0.0; fail_if ((outbuffer = (GstBuffer *) node->data) == NULL);
for (i = 0; i < 1024; i++)
rms += res[i] * res[i]; res = (gdouble *) GST_BUFFER_DATA (outbuffer);
rms = sqrt (rms / 1024.0); buffer_length = GST_BUFFER_SIZE (outbuffer) / sizeof (gdouble);
fail_unless (rms >= 0.4); rms = 0.0;
for (i = 0; i < buffer_length; i++)
rms += res[i] * res[i];
rms = sqrt (rms / buffer_length);
fail_unless (rms >= 0.4);
}
/* cleanup */ /* cleanup */
cleanup_bpwsinc (bpwsinc); cleanup_bpwsinc (bpwsinc);
@ -213,6 +223,7 @@ GST_START_TEST (test_bp_22050hz)
GstCaps *caps; GstCaps *caps;
gdouble *in, *res, rms; gdouble *in, *res, rms;
gint i; gint i;
GList *node;
bpwsinc = setup_bpwsinc (); bpwsinc = setup_bpwsinc ();
/* Set to bandpass */ /* Set to bandpass */
@ -241,21 +252,24 @@ GST_START_TEST (test_bp_22050hz)
/* pushing gives away my reference ... */ /* pushing gives away my reference ... */
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
/* ... and puts a new buffer on the global list */ /* ... and puts a new buffer on the global list */
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless (g_list_length (buffers) >= 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); for (node = buffers; node; node = node->next) {
for (i = 31; i < 1024; i++) { gint buffer_length;
fail_unless (abs (res[i]) <= 0.01, "res[%d] = %lf\n", i, res[i]);
fail_if ((outbuffer = (GstBuffer *) node->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
buffer_length = GST_BUFFER_SIZE (outbuffer) / sizeof (gdouble);
rms = 0.0;
for (i = 0; i < buffer_length; i++)
rms += res[i] * res[i];
rms = sqrt (rms / buffer_length);
fail_unless (rms <= 0.3);
} }
rms = 0.0;
for (i = 0; i < 1024; i++)
rms += res[i] * res[i];
rms = sqrt (rms / 1024.0);
fail_unless (rms <= 0.1);
/* cleanup */ /* cleanup */
cleanup_bpwsinc (bpwsinc); cleanup_bpwsinc (bpwsinc);
} }
@ -272,6 +286,7 @@ GST_START_TEST (test_br_0hz)
GstCaps *caps; GstCaps *caps;
gdouble *in, *res, rms; gdouble *in, *res, rms;
gint i; gint i;
GList *node;
bpwsinc = setup_bpwsinc (); bpwsinc = setup_bpwsinc ();
/* Set to bandreject */ /* Set to bandreject */
@ -298,22 +313,24 @@ GST_START_TEST (test_br_0hz)
/* pushing gives away my reference ... */ /* pushing gives away my reference ... */
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
/* ... and puts a new buffer on the global list */ /* ... and puts a new buffer on the global list */
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless (g_list_length (buffers) >= 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); for (node = buffers; node; node = node->next) {
for (i = 31; i < 1024; i++) { gint buffer_length;
fail_unless (res[i] <= 1.01
&& res[i] >= 0.99, "res[%d] = %lf\n", i, res[i]); fail_if ((outbuffer = (GstBuffer *) node->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
buffer_length = GST_BUFFER_SIZE (outbuffer) / sizeof (gdouble);
rms = 0.0;
for (i = 0; i < buffer_length; i++)
rms += res[i] * res[i];
rms = sqrt (rms / buffer_length);
fail_unless (rms >= 0.9);
} }
rms = 0.0;
for (i = 0; i < 1024; i++)
rms += res[i] * res[i];
rms = sqrt (rms / 1024.0);
fail_unless (rms >= 0.9);
/* cleanup */ /* cleanup */
cleanup_bpwsinc (bpwsinc); cleanup_bpwsinc (bpwsinc);
} }
@ -330,6 +347,7 @@ GST_START_TEST (test_br_11025hz)
GstCaps *caps; GstCaps *caps;
gdouble *in, *res, rms; gdouble *in, *res, rms;
gint i; gint i;
GList *node;
bpwsinc = setup_bpwsinc (); bpwsinc = setup_bpwsinc ();
/* Set to bandreject */ /* Set to bandreject */
@ -361,21 +379,24 @@ GST_START_TEST (test_br_11025hz)
/* pushing gives away my reference ... */ /* pushing gives away my reference ... */
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
/* ... and puts a new buffer on the global list */ /* ... and puts a new buffer on the global list */
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless (g_list_length (buffers) >= 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); for (node = buffers; node; node = node->next) {
for (i = 31; i < 1024; i++) { gint buffer_length;
fail_unless (abs (res[i]) <= 0.01, "res[%d] = %lf\n", i, res[i]);
fail_if ((outbuffer = (GstBuffer *) node->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
buffer_length = GST_BUFFER_SIZE (outbuffer) / sizeof (gdouble);
rms = 0.0;
for (i = 0; i < buffer_length; i++)
rms += res[i] * res[i];
rms = sqrt (rms / buffer_length);
fail_unless (rms <= 0.35);
} }
rms = 0.0;
for (i = 0; i < 1024; i++)
rms += res[i] * res[i];
rms = sqrt (rms / 1024.0);
fail_unless (rms <= 0.3);
/* cleanup */ /* cleanup */
cleanup_bpwsinc (bpwsinc); cleanup_bpwsinc (bpwsinc);
} }
@ -393,6 +414,7 @@ GST_START_TEST (test_br_22050hz)
GstCaps *caps; GstCaps *caps;
gdouble *in, *res, rms; gdouble *in, *res, rms;
gint i; gint i;
GList *node;
bpwsinc = setup_bpwsinc (); bpwsinc = setup_bpwsinc ();
/* Set to bandreject */ /* Set to bandreject */
@ -421,22 +443,24 @@ GST_START_TEST (test_br_22050hz)
/* pushing gives away my reference ... */ /* pushing gives away my reference ... */
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
/* ... and puts a new buffer on the global list */ /* ... and puts a new buffer on the global list */
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless (g_list_length (buffers) >= 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer); for (node = buffers; node; node = node->next) {
for (i = 31; i < 1024; i++) { gint buffer_length;
fail_unless (abs (res[i]) <= 1.01
&& abs (res[i]) >= 0.99, "res[%d] = %lf\n", i, res[i]); fail_if ((outbuffer = (GstBuffer *) node->data) == NULL);
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
buffer_length = GST_BUFFER_SIZE (outbuffer) / sizeof (gdouble);
rms = 0.0;
for (i = 0; i < buffer_length; i++)
rms += res[i] * res[i];
rms = sqrt (rms / buffer_length);
fail_unless (rms >= 0.9);
} }
rms = 0.0;
for (i = 0; i < 1024; i++)
rms += res[i] * res[i];
rms = sqrt (rms / 1024.0);
fail_unless (rms >= 0.9);
/* cleanup */ /* cleanup */
cleanup_bpwsinc (bpwsinc); cleanup_bpwsinc (bpwsinc);
} }
@ -479,9 +503,9 @@ GST_START_TEST (test_small_buffer)
/* pushing gives away my reference ... */ /* pushing gives away my reference ... */
fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK); fail_unless (gst_pad_push (mysrcpad, inbuffer) == GST_FLOW_OK);
fail_unless (gst_pad_push_event (mysrcpad, gst_event_new_eos ()));
/* ... and puts a new buffer on the global list */ /* ... and puts a new buffer on the global list */
fail_unless_equals_int (g_list_length (buffers), 1); fail_unless (g_list_length (buffers) >= 1);
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
/* cleanup */ /* cleanup */
cleanup_bpwsinc (bpwsinc); cleanup_bpwsinc (bpwsinc);