Commit fa3a196a authored by Leo Pound Singer's avatar Leo Pound Singer Committed by Kipp Cannon

gst/unary: removed; development continues at git://github.com/lpsinger/gst-plugins-math.git

parent a52c6eb4
......@@ -20,7 +20,6 @@ AC_CONFIG_FILES([ \
gst/Makefile \
gst/lal/Makefile \
gst/python/Makefile \
gst/unary/Makefile \
bin/Makefile \
tests/Makefile
])
......
SUBDIRS = lal python unary
SUBDIRS = lal python
plugin_LTLIBRARIES = libgstunary.la
libgstunary_la_SOURCES = \
unary.c \
unary_base.h unary_base.c \
unary_abs.c \
unary_exp.c \
unary_ln.c \
unary_log.c \
unary_log10.c \
unary_pow.c
libgstunary_la_CFLAGS = $(AM_CFLAGS) $(gstreamer_CFLAGS) $(gstreamer_audio_CFLAGS)
libgstunary_la_LDFLAGS = $(AM_LDFLAGS) $(gstreamer_LIBS) $(gstreamer_audio_LIBS) $(GSTLAL_PLUGIN_LDFLAGS)
/*
* Copyright (C) 2010 Leo Singer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/*
* ============================================================================
*
* Preamble
*
* ============================================================================
*/
/*
* Stuff from GStreamer
*/
#include <gst/gst.h>
/*
* Our own stuff
*/
#include <unary_base.h>
/*
* ============================================================================
*
* Plugin Entry Point
*
* ============================================================================
*/
GType unary_abs_get_type(void);
GType unary_exp_get_type(void);
GType unary_ln_get_type(void);
GType unary_log_get_type(void);
GType unary_log10_get_type(void);
GType unary_pow_get_type(void);
static gboolean plugin_init(GstPlugin *plugin)
{
struct {
const gchar *name;
GType type;
} *element, elements[] = {
{"unary_base", UNARY_BASE_TYPE},
{"abs", unary_abs_get_type()},
{"exp", unary_exp_get_type()},
{"ln", unary_ln_get_type()},
{"log", unary_log_get_type()},
{"log10", unary_log10_get_type()},
{"pow", unary_pow_get_type()},
{NULL, 0},
};
/*
* Tell GStreamer about the elements.
*/
for(element = elements; element->name; element++)
if(!gst_element_register(plugin, element->name, GST_RANK_NONE, element->type))
return FALSE;
/*
* Done.
*/
return TRUE;
}
/*
* This is the structure that gst-register looks for.
*/
GST_PLUGIN_DEFINE(GST_VERSION_MAJOR, GST_VERSION_MINOR, "unary", "Unary arithmetic elements", plugin_init, PACKAGE_VERSION, "GPL", PACKAGE_NAME, "http://www.lsc-group.phys.uwm.edu/daswg")
/*
* Copyright (C) 2010 Leo Singer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <unary_base.h>
#include <math.h>
static GstFlowReturn transform_ip(GstBaseTransform *trans, GstBuffer *buf)
{
GstAudioFilter *audiofilter = GST_AUDIO_FILTER(trans);
GstBufferFormat format = audiofilter->format.format;
gpointer data = GST_BUFFER_DATA(buf);
gpointer data_end = GST_BUFFER_DATA(buf) + GST_BUFFER_SIZE(buf);
if (format >= GST_FLOAT64_LE)
{
double *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = fabs(*ptr);
} else if (format >= GST_FLOAT32_LE) {
float *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = fabsf(*ptr);
} else {
g_assert_not_reached();
}
return GST_FLOW_OK;
}
/*
* ============================================================================
*
* Type Support
*
* ============================================================================
*/
static void base_init(gpointer class)
{
gst_element_class_set_details_simple(
GST_ELEMENT_CLASS(class),
"Absolute value",
"Filter/Audio",
"Calculate absolute value, y = |x|",
"Leo Singer <leo.singer@ligo.org>"
);
}
static void class_init(gpointer class, gpointer class_data)
{
GstBaseTransformClass *basetransform_class = GST_BASE_TRANSFORM_CLASS(class);
basetransform_class->transform_ip = GST_DEBUG_FUNCPTR(transform_ip);
}
GType unary_abs_get_type(void)
{
static GType type = 0;
if(!type) {
static const GTypeInfo info = {
.class_size = sizeof(UnaryBaseClass),
.base_init = base_init,
.class_init = class_init,
.instance_size = sizeof(UnaryBase),
};
type = g_type_register_static(UNARY_BASE_TYPE, "UnaryAbs", &info, 0);
}
return type;
}
/*
* Copyright (C) 2010 Leo Singer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <unary_base.h>
/*
* ============================================================================
*
* Type Support
*
* ============================================================================
*/
static void base_init(gpointer class)
{
gst_element_class_set_details_simple(
GST_ELEMENT_CLASS(class),
"Unary operation base class",
"Filter/Audio",
"Base class for elements that provide unary arithmetic operations",
"Leo Singer <leo.singer@ligo.org>"
);
gst_audio_filter_class_add_pad_templates(GST_AUDIO_FILTER_CLASS(class),
gst_caps_from_string(
"audio/x-raw-float, " \
"rate = (int) [1, MAX], " \
"endianness = (int) BYTE_ORDER, " \
"width = (int) {32, 64}, " \
"channels = (int) [1, MAX]"
)
);
}
GType unary_base_get_type(void)
{
static GType type = 0;
if(!type) {
static const GTypeInfo info = {
.class_size = sizeof(UnaryBaseClass),
.base_init = base_init,
.instance_size = sizeof(UnaryBase),
};
type = g_type_register_static(GST_TYPE_AUDIO_FILTER, "UnaryBase", &info, 0);
}
return type;
}
/*
* Copyright (C) 2010 Leo Singer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef __UNARY_BASE_H__
#define __UNARY_BASE_H__
#include <glib.h>
#include <gst/gst.h>
#include <gst/audio/gstaudiofilter.h>
G_BEGIN_DECLS
#define UNARY_BASE_TYPE \
(unary_base_get_type())
#define UNARY_BASE(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), UNARY_BASE_TYPE, UnaryBase))
#define UNARY_BASE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_CAST((klass), UNARY_BASE_TYPE, UnaryBaseClass))
#define GST_IS_UNARY_BASE(obj) \
(G_TYPE_CHECK_INSTANCE_TYPE((obj), UNARY_BASE_TYPE))
#define GST_IS_UNARY_BASE_CLASS(klass) \
(G_TYPE_CHECK_CLASS_TYPE((klass), UNARY_BASE_TYPE))
typedef struct {
GstAudioFilterClass parent_class;
} UnaryBaseClass;
typedef struct {
GstAudioFilter audiofilter;
} UnaryBase;
GType unary_base_get_type(void);
G_END_DECLS
#endif /* __UNARY_BASE_H__ */
/*
* Copyright (C) 2010 Leo Singer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <unary_base.h>
#include <math.h>
static GstFlowReturn transform_ip(GstBaseTransform *trans, GstBuffer *buf)
{
GstAudioFilter *audiofilter = GST_AUDIO_FILTER(trans);
GstBufferFormat format = audiofilter->format.format;
gpointer data = GST_BUFFER_DATA(buf);
gpointer data_end = GST_BUFFER_DATA(buf) + GST_BUFFER_SIZE(buf);
if (format >= GST_FLOAT64_LE)
{
double *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = exp(*ptr);
} else if (format >= GST_FLOAT32_LE) {
float *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = expf(*ptr);
} else {
g_assert_not_reached();
}
return GST_FLOW_OK;
}
/*
* ============================================================================
*
* Type Support
*
* ============================================================================
*/
static void base_init(gpointer class)
{
gst_element_class_set_details_simple(
GST_ELEMENT_CLASS(class),
"Natural exponent",
"Filter/Audio",
"Calculate natural exponent, y = e^x",
"Leo Singer <leo.singer@ligo.org>"
);
}
static void class_init(gpointer class, gpointer class_data)
{
GstBaseTransformClass *basetransform_class = GST_BASE_TRANSFORM_CLASS(class);
basetransform_class->transform_ip = GST_DEBUG_FUNCPTR(transform_ip);
}
GType unary_exp_get_type(void)
{
static GType type = 0;
if(!type) {
static const GTypeInfo info = {
.class_size = sizeof(UnaryBaseClass),
.base_init = base_init,
.class_init = class_init,
.instance_size = sizeof(UnaryBase),
};
type = g_type_register_static(UNARY_BASE_TYPE, "UnaryExp", &info, 0);
}
return type;
}
/*
* Copyright (C) 2010 Leo Singer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <unary_base.h>
#include <math.h>
static GstFlowReturn transform_ip(GstBaseTransform *trans, GstBuffer *buf)
{
GstAudioFilter *audiofilter = GST_AUDIO_FILTER(trans);
GstBufferFormat format = audiofilter->format.format;
gpointer data = GST_BUFFER_DATA(buf);
gpointer data_end = GST_BUFFER_DATA(buf) + GST_BUFFER_SIZE(buf);
if (format >= GST_FLOAT64_LE)
{
double *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = log(*ptr);
} else if (format >= GST_FLOAT32_LE) {
float *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = logf(*ptr);
} else {
g_assert_not_reached();
}
return GST_FLOW_OK;
}
/*
* ============================================================================
*
* Type Support
*
* ============================================================================
*/
static void base_init(gpointer class)
{
gst_element_class_set_details_simple(
GST_ELEMENT_CLASS(class),
"Natural logarithm",
"Filter/Audio",
"Calculate natural logarithm, y = ln x",
"Leo Singer <leo.singer@ligo.org>"
);
}
static void class_init(gpointer class, gpointer class_data)
{
GstBaseTransformClass *basetransform_class = GST_BASE_TRANSFORM_CLASS(class);
basetransform_class->transform_ip = GST_DEBUG_FUNCPTR(transform_ip);
}
GType unary_ln_get_type(void)
{
static GType type = 0;
if(!type) {
static const GTypeInfo info = {
.class_size = sizeof(UnaryBaseClass),
.base_init = base_init,
.class_init = class_init,
.instance_size = sizeof(UnaryBase),
};
type = g_type_register_static(UNARY_BASE_TYPE, "UnaryLn", &info, 0);
}
return type;
}
/*
* Copyright (C) 2010 Leo Singer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <unary_base.h>
#include <math.h>
GType unary_log_get_type(void);
#define UNARY_LOG_TYPE \
(unary_log_get_type())
#define UNARY_LOG(obj) \
(G_TYPE_CHECK_INSTANCE_CAST((obj), UNARY_LOG_TYPE, UnaryLog))
typedef struct {
GstAudioFilter audiofilter;
double base;
double invlogbase;
} UnaryLog;
static GstFlowReturn transform_ip(GstBaseTransform *trans, GstBuffer *buf)
{
UnaryLog *element = UNARY_LOG(trans);
GstAudioFilter *audiofilter = GST_AUDIO_FILTER(trans);
GstBufferFormat format = audiofilter->format.format;
gpointer data = GST_BUFFER_DATA(buf);
gpointer data_end = GST_BUFFER_DATA(buf) + GST_BUFFER_SIZE(buf);
const double n = element->invlogbase;
if (format >= GST_FLOAT64_LE)
{
double *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = log(*ptr) * n;
} else if (format >= GST_FLOAT32_LE) {
float *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = logf(*ptr) * n;
} else {
g_assert_not_reached();
}
return GST_FLOW_OK;
}
/*
* ============================================================================
*
* Type Support
*
* ============================================================================
*/
enum property {
PROP_BASE = 1,
};
static void set_property(GObject * object, enum property id, const GValue * value, GParamSpec * pspec)
{
UnaryLog *element = UNARY_LOG(object);
GST_OBJECT_LOCK(element);
switch (id) {
case PROP_BASE:
element->base = g_value_get_double(value);
element->invlogbase = 1. / log(element->base);
break;
}
GST_OBJECT_UNLOCK(element);
}
static void get_property(GObject * object, enum property id, GValue * value, GParamSpec * pspec)
{
UnaryLog *element = UNARY_LOG(object);
GST_OBJECT_LOCK(element);
switch (id) {
case PROP_BASE:
g_value_set_double(value, element->base);
break;
}
GST_OBJECT_UNLOCK(element);
}
static void base_init(gpointer class)
{
gst_element_class_set_details_simple(
GST_ELEMENT_CLASS(class),
"Natural logarithm",
"Filter/Audio",
"Calculate natural logarithm, y = log_k x",
"Leo Singer <leo.singer@ligo.org>"
);
}
static void class_init(gpointer class, gpointer class_data)
{
GObjectClass *gobject_class = G_OBJECT_CLASS(class);
GstBaseTransformClass *basetransform_class = GST_BASE_TRANSFORM_CLASS(class);
basetransform_class->transform_ip = GST_DEBUG_FUNCPTR(transform_ip);
gobject_class->get_property = GST_DEBUG_FUNCPTR(get_property);
gobject_class->set_property = GST_DEBUG_FUNCPTR(set_property);
g_object_class_install_property(
gobject_class,
PROP_BASE,
g_param_spec_double(
"base",
"Base",
"Base of logarithm",
G_MINDOUBLE, G_MAXDOUBLE, 10.,
G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS | G_PARAM_CONSTRUCT
)
);
}
GType unary_log_get_type(void)
{
static GType type = 0;
if(!type) {
static const GTypeInfo info = {
.class_size = sizeof(UnaryBaseClass),
.base_init = base_init,
.class_init = class_init,
.instance_size = sizeof(UnaryLog),
};
type = g_type_register_static(UNARY_BASE_TYPE, "UnaryLog", &info, 0);
}
return type;
}
/*
* Copyright (C) 2010 Leo Singer
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include <unary_base.h>
#include <math.h>
static GstFlowReturn transform_ip(GstBaseTransform *trans, GstBuffer *buf)
{
GstAudioFilter *audiofilter = GST_AUDIO_FILTER(trans);
GstBufferFormat format = audiofilter->format.format;
gpointer data = GST_BUFFER_DATA(buf);
gpointer data_end = GST_BUFFER_DATA(buf) + GST_BUFFER_SIZE(buf);
if (format >= GST_FLOAT64_LE)
{
double *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = log10(*ptr);
} else if (format >= GST_FLOAT32_LE) {
float *ptr, *end = data_end;
for (ptr = data; ptr < end; ptr++)
*ptr = log10f(*ptr);
} else {
g_assert_not_reached();
}