mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-24 09:10:36 +00:00
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:
parent
1df9f40304
commit
e221638fdd
5 changed files with 411 additions and 76 deletions
19
ChangeLog
19
ChangeLog
|
@ -1,3 +1,22 @@
|
|||
2007-08-16 Sebastian Dröge <slomo@circular-chaos.org>
|
||||
|
||||
* 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.
|
||||
|
||||
2007-08-16 Wim Taymans <wim.taymans@gmail.com>
|
||||
|
||||
* gst-libs/gst/app/gstappsink.c: (gst_app_sink_class_init):
|
||||
|
|
|
@ -173,10 +173,14 @@ static GstFlowReturn bpwsinc_transform (GstBaseTransform * base,
|
|||
static gboolean bpwsinc_get_unit_size (GstBaseTransform * base, GstCaps * caps,
|
||||
guint * size);
|
||||
static gboolean bpwsinc_start (GstBaseTransform * base);
|
||||
static gboolean bpwsinc_event (GstBaseTransform * base, GstEvent * event);
|
||||
|
||||
static gboolean bpwsinc_setup (GstAudioFilter * base,
|
||||
GstRingBufferSpec * format);
|
||||
|
||||
static gboolean bpwsinc_query (GstPad * pad, GstQuery * query);
|
||||
static const GstQueryType *bpwsinc_query_type (GstPad * pad);
|
||||
|
||||
/* Element class */
|
||||
|
||||
static void
|
||||
|
@ -252,6 +256,7 @@ gst_bpwsinc_class_init (GstBPWSincClass * klass)
|
|||
trans_class->transform = GST_DEBUG_FUNCPTR (bpwsinc_transform);
|
||||
trans_class->get_unit_size = GST_DEBUG_FUNCPTR (bpwsinc_get_unit_size);
|
||||
trans_class->start = GST_DEBUG_FUNCPTR (bpwsinc_start);
|
||||
trans_class->event = GST_DEBUG_FUNCPTR (bpwsinc_event);
|
||||
filter_class->setup = GST_DEBUG_FUNCPTR (bpwsinc_setup);
|
||||
}
|
||||
|
||||
|
@ -259,6 +264,7 @@ static void
|
|||
gst_bpwsinc_init (GstBPWSinc * self, GstBPWSincClass * g_class)
|
||||
{
|
||||
self->kernel_length = 101;
|
||||
self->latency = 50;
|
||||
self->lower_frequency = 0.0;
|
||||
self->upper_frequency = 0.0;
|
||||
self->mode = MODE_BAND_PASS;
|
||||
|
@ -266,6 +272,14 @@ gst_bpwsinc_init (GstBPWSinc * self, GstBPWSincClass * g_class)
|
|||
self->kernel = NULL;
|
||||
self->have_kernel = FALSE;
|
||||
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
|
||||
|
@ -302,6 +316,10 @@ process_32 (GstBPWSinc * self, gfloat * src, gfloat * dst, guint input_samples)
|
|||
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
|
||||
|
@ -339,6 +357,10 @@ process_64 (GstBPWSinc * self, gdouble * src, gdouble * dst,
|
|||
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
|
||||
|
@ -458,14 +480,91 @@ bpwsinc_build_kernel (GstBPWSinc * self)
|
|||
}
|
||||
|
||||
/* set up the residue memory space */
|
||||
if (self->residue)
|
||||
g_free (self->residue);
|
||||
self->residue =
|
||||
g_new0 (gdouble, len * GST_AUDIO_FILTER (self)->format.channels);
|
||||
if (!self->residue) {
|
||||
self->residue =
|
||||
g_new0 (gdouble, len * GST_AUDIO_FILTER (self)->format.channels);
|
||||
self->residue_length = 0;
|
||||
}
|
||||
|
||||
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 */
|
||||
|
||||
/* 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);
|
||||
GstClockTime timestamp;
|
||||
gint channels = GST_AUDIO_FILTER (self)->format.channels;
|
||||
gint rate = GST_AUDIO_FILTER (self)->format.rate;
|
||||
gint input_samples =
|
||||
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 */
|
||||
if (gst_base_transform_is_passthrough (base))
|
||||
|
@ -530,9 +633,100 @@ bpwsinc_transform (GstBaseTransform * base, GstBuffer * inbuf,
|
|||
if (!self->have_kernel)
|
||||
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),
|
||||
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;
|
||||
}
|
||||
|
||||
|
@ -547,9 +741,93 @@ bpwsinc_start (GstBaseTransform * base)
|
|||
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;
|
||||
|
||||
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
|
||||
bpwsinc_set_property (GObject * object, guint prop_id, const GValue * value,
|
||||
GParamSpec * pspec)
|
||||
|
@ -566,8 +844,17 @@ bpwsinc_set_property (GObject * object, guint prop_id, const GValue * value,
|
|||
val = g_value_get_int (value);
|
||||
if (val % 2 == 0)
|
||||
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);
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -71,6 +71,10 @@ struct _GstBPWSinc {
|
|||
gdouble *residue; /* buffer for left-over samples from previous buffer */
|
||||
gdouble *kernel;
|
||||
gboolean have_kernel;
|
||||
gint residue_length;
|
||||
guint64 latency;
|
||||
GstClockTime next_ts;
|
||||
guint64 next_off;
|
||||
};
|
||||
|
||||
struct _GstBPWSincClass {
|
||||
|
|
|
@ -421,12 +421,13 @@ lpwsinc_build_kernel (GstLPWSinc * self)
|
|||
}
|
||||
|
||||
/* set up the residue memory space */
|
||||
if (!self->residue)
|
||||
if (!self->residue) {
|
||||
self->residue =
|
||||
g_new0 (gdouble, len * GST_AUDIO_FILTER (self)->format.channels);
|
||||
self->residue_length = 0;
|
||||
}
|
||||
|
||||
self->have_kernel = TRUE;
|
||||
self->residue_length = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -96,6 +96,7 @@ GST_START_TEST (test_bp_0hz)
|
|||
GstCaps *caps;
|
||||
gdouble *in, *res, rms;
|
||||
gint i;
|
||||
GList *node;
|
||||
|
||||
bpwsinc = setup_bpwsinc ();
|
||||
/* Set to bandpass */
|
||||
|
@ -122,22 +123,24 @@ GST_START_TEST (test_bp_0hz)
|
|||
|
||||
/* pushing gives away my reference ... */
|
||||
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 */
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (g_list_length (buffers) >= 1);
|
||||
|
||||
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
|
||||
for (i = 31; i < 1024; i++) {
|
||||
fail_unless (res[i] <= 0.01
|
||||
&& res[i] >= -0.01, "res[%d] = %lf\n", i, res[i]);
|
||||
for (node = buffers; node; node = node->next) {
|
||||
gint buffer_length;
|
||||
|
||||
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_bpwsinc (bpwsinc);
|
||||
}
|
||||
|
@ -154,6 +157,7 @@ GST_START_TEST (test_bp_11025hz)
|
|||
GstCaps *caps;
|
||||
gdouble *in, *res, rms;
|
||||
gint i;
|
||||
GList *node;
|
||||
|
||||
bpwsinc = setup_bpwsinc ();
|
||||
/* Set to bandpass */
|
||||
|
@ -184,17 +188,23 @@ GST_START_TEST (test_bp_11025hz)
|
|||
|
||||
/* pushing gives away my reference ... */
|
||||
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 */
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (g_list_length (buffers) >= 1);
|
||||
|
||||
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
|
||||
for (node = buffers; node; node = node->next) {
|
||||
gint buffer_length;
|
||||
|
||||
rms = 0.0;
|
||||
for (i = 0; i < 1024; i++)
|
||||
rms += res[i] * res[i];
|
||||
rms = sqrt (rms / 1024.0);
|
||||
fail_unless (rms >= 0.4);
|
||||
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.4);
|
||||
}
|
||||
|
||||
/* cleanup */
|
||||
cleanup_bpwsinc (bpwsinc);
|
||||
|
@ -213,6 +223,7 @@ GST_START_TEST (test_bp_22050hz)
|
|||
GstCaps *caps;
|
||||
gdouble *in, *res, rms;
|
||||
gint i;
|
||||
GList *node;
|
||||
|
||||
bpwsinc = setup_bpwsinc ();
|
||||
/* Set to bandpass */
|
||||
|
@ -241,21 +252,24 @@ GST_START_TEST (test_bp_22050hz)
|
|||
|
||||
/* pushing gives away my reference ... */
|
||||
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 */
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (g_list_length (buffers) >= 1);
|
||||
|
||||
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
|
||||
for (i = 31; i < 1024; i++) {
|
||||
fail_unless (abs (res[i]) <= 0.01, "res[%d] = %lf\n", i, res[i]);
|
||||
for (node = buffers; node; node = node->next) {
|
||||
gint buffer_length;
|
||||
|
||||
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_bpwsinc (bpwsinc);
|
||||
}
|
||||
|
@ -272,6 +286,7 @@ GST_START_TEST (test_br_0hz)
|
|||
GstCaps *caps;
|
||||
gdouble *in, *res, rms;
|
||||
gint i;
|
||||
GList *node;
|
||||
|
||||
bpwsinc = setup_bpwsinc ();
|
||||
/* Set to bandreject */
|
||||
|
@ -298,22 +313,24 @@ GST_START_TEST (test_br_0hz)
|
|||
|
||||
/* pushing gives away my reference ... */
|
||||
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 */
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (g_list_length (buffers) >= 1);
|
||||
|
||||
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
|
||||
for (i = 31; i < 1024; i++) {
|
||||
fail_unless (res[i] <= 1.01
|
||||
&& res[i] >= 0.99, "res[%d] = %lf\n", i, res[i]);
|
||||
for (node = buffers; node; node = node->next) {
|
||||
gint buffer_length;
|
||||
|
||||
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_bpwsinc (bpwsinc);
|
||||
}
|
||||
|
@ -330,6 +347,7 @@ GST_START_TEST (test_br_11025hz)
|
|||
GstCaps *caps;
|
||||
gdouble *in, *res, rms;
|
||||
gint i;
|
||||
GList *node;
|
||||
|
||||
bpwsinc = setup_bpwsinc ();
|
||||
/* Set to bandreject */
|
||||
|
@ -361,21 +379,24 @@ GST_START_TEST (test_br_11025hz)
|
|||
|
||||
/* pushing gives away my reference ... */
|
||||
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 */
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (g_list_length (buffers) >= 1);
|
||||
|
||||
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
|
||||
for (i = 31; i < 1024; i++) {
|
||||
fail_unless (abs (res[i]) <= 0.01, "res[%d] = %lf\n", i, res[i]);
|
||||
for (node = buffers; node; node = node->next) {
|
||||
gint buffer_length;
|
||||
|
||||
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_bpwsinc (bpwsinc);
|
||||
}
|
||||
|
@ -393,6 +414,7 @@ GST_START_TEST (test_br_22050hz)
|
|||
GstCaps *caps;
|
||||
gdouble *in, *res, rms;
|
||||
gint i;
|
||||
GList *node;
|
||||
|
||||
bpwsinc = setup_bpwsinc ();
|
||||
/* Set to bandreject */
|
||||
|
@ -421,22 +443,24 @@ GST_START_TEST (test_br_22050hz)
|
|||
|
||||
/* pushing gives away my reference ... */
|
||||
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 */
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (g_list_length (buffers) >= 1);
|
||||
|
||||
res = (gdouble *) GST_BUFFER_DATA (outbuffer);
|
||||
for (i = 31; i < 1024; i++) {
|
||||
fail_unless (abs (res[i]) <= 1.01
|
||||
&& abs (res[i]) >= 0.99, "res[%d] = %lf\n", i, res[i]);
|
||||
for (node = buffers; node; node = node->next) {
|
||||
gint buffer_length;
|
||||
|
||||
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_bpwsinc (bpwsinc);
|
||||
}
|
||||
|
@ -479,9 +503,9 @@ GST_START_TEST (test_small_buffer)
|
|||
|
||||
/* pushing gives away my reference ... */
|
||||
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 */
|
||||
fail_unless_equals_int (g_list_length (buffers), 1);
|
||||
fail_if ((outbuffer = (GstBuffer *) buffers->data) == NULL);
|
||||
fail_unless (g_list_length (buffers) >= 1);
|
||||
|
||||
/* cleanup */
|
||||
cleanup_bpwsinc (bpwsinc);
|
||||
|
|
Loading…
Reference in a new issue