diff options
author | Stefan Kost <ensonic@users.sf.net> | 2011-06-04 15:52:44 +0300 |
---|---|---|
committer | Stefan Kost <ensonic@users.sf.net> | 2011-06-06 15:25:14 +0300 |
commit | 0a41b9084e0bd32d74fa074eb967f7ce7cb8d496 (patch) | |
tree | 937a47c39385e33b4d367abdffb95c4de96d9baa /gst/audiovisualizers | |
parent | 9936332f0ad7c6b9945ff2f2313453ffd4749d22 (diff) | |
download | gstreamer-plugins-bad-0a41b9084e0bd32d74fa074eb967f7ce7cb8d496.tar.gz |
audiovisualizers: add a spacescope element
Add another element that maps left/right channel to x,y coordinates.
Diffstat (limited to 'gst/audiovisualizers')
-rw-r--r-- | gst/audiovisualizers/Makefile.am | 3 | ||||
-rw-r--r-- | gst/audiovisualizers/gstspacescope.c | 131 | ||||
-rw-r--r-- | gst/audiovisualizers/gstspacescope.h | 50 | ||||
-rw-r--r-- | gst/audiovisualizers/plugin.c | 2 |
4 files changed, 185 insertions, 1 deletions
diff --git a/gst/audiovisualizers/Makefile.am b/gst/audiovisualizers/Makefile.am index a7bd6000e..811c7d831 100644 --- a/gst/audiovisualizers/Makefile.am +++ b/gst/audiovisualizers/Makefile.am @@ -2,6 +2,7 @@ plugin_LTLIBRARIES = libgstaudiovisualizers.la libgstaudiovisualizers_la_SOURCES = plugin.c \ gstbaseaudiovisualizer.c gstbaseaudiovisualizer.h \ + gstspacescope.c gstspacescope.h \ gstspectrascope.c gstspectrascope.h \ gstsynaescope.c gstsynaescope.h \ gstwavescope.c gstwavescope.h @@ -17,7 +18,7 @@ libgstaudiovisualizers_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS) libgstaudiovisualizers_la_LIBTOOLFLAGS = --tag=disable-static noinst_HEADERS = gstbaseaudiovisualizer.h \ - gstspectrascope.h gstsynaescope.h gstwavescope.h + gstspacescope.h gstspectrascope.h gstsynaescope.h gstwavescope.h Android.mk: Makefile.am $(BUILT_SOURCES) androgenizer \ diff --git a/gst/audiovisualizers/gstspacescope.c b/gst/audiovisualizers/gstspacescope.c new file mode 100644 index 000000000..b1405e5fe --- /dev/null +++ b/gst/audiovisualizers/gstspacescope.c @@ -0,0 +1,131 @@ +/* GStreamer + * Copyright (C) <2011> Stefan Kost <ensonic@users.sf.net> + * + * gstspacescope.c: simple stereo visualizer + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ +/** + * SECTION:element-spacescope + * @see_also: goom + * + * Spacescope is a simple audio visualisation element. It maps the left and + * right channel to x and y coordinates. + * + * <refsect2> + * <title>Example launch line</title> + * |[ + * gst-launch audiotestsrc ! audioconvert ! spacescope ! ximagesink + * ]| + * </refsect2> + */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "gstspacescope.h" + +static GstStaticPadTemplate gst_space_scope_src_template = +GST_STATIC_PAD_TEMPLATE ("src", + GST_PAD_SRC, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_VIDEO_CAPS_xRGB_HOST_ENDIAN) + ); + +static GstStaticPadTemplate gst_space_scope_sink_template = +GST_STATIC_PAD_TEMPLATE ("sink", + GST_PAD_SINK, + GST_PAD_ALWAYS, + GST_STATIC_CAPS (GST_AUDIO_INT_STANDARD_PAD_TEMPLATE_CAPS) + ); + + +GST_DEBUG_CATEGORY_STATIC (space_scope_debug); +#define GST_CAT_DEFAULT space_scope_debug + +static gboolean gst_space_scope_setup (GstBaseAudioVisualizer * scope); +static gboolean gst_space_scope_render (GstBaseAudioVisualizer * scope, + GstBuffer * audio, GstBuffer * video); + + +GST_BOILERPLATE (GstSpaceScope, gst_space_scope, GstBaseAudioVisualizer, + GST_TYPE_BASE_AUDIO_VISUALIZER); + +static void +gst_space_scope_base_init (gpointer g_class) +{ + GstElementClass *element_class = GST_ELEMENT_CLASS (g_class); + + gst_element_class_set_details_simple (element_class, "Stereo visualizer", + "Visualization", + "Simple stereo visualizer", "Stefan Kost <ensonic@users.sf.net>"); + + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_space_scope_src_template)); + gst_element_class_add_pad_template (element_class, + gst_static_pad_template_get (&gst_space_scope_sink_template)); +} + +static void +gst_space_scope_class_init (GstSpaceScopeClass * g_class) +{ + /*GObjectClass *gobject_class = (GObjectClass *) g_class; */ + GstBaseAudioVisualizerClass *scope_class = + (GstBaseAudioVisualizerClass *) g_class; + + scope_class->render = GST_DEBUG_FUNCPTR (gst_space_scope_render); +} + +static void +gst_space_scope_init (GstSpaceScope * scope, GstSpaceScopeClass * g_class) +{ + /* do nothing */ +} + +static gboolean +gst_space_scope_render (GstBaseAudioVisualizer * scope, GstBuffer * audio, + GstBuffer * video) +{ + guint32 *vdata = (guint32 *) GST_BUFFER_DATA (video); + gint16 *adata = (gint16 *) GST_BUFFER_DATA (audio); + guint i, s, x, y, off, ox, oy; + guint num_samples; + gfloat dx, dy; + guint w = scope->width; + + /* draw dots 1st channel x, 2nd channel y */ + num_samples = GST_BUFFER_SIZE (audio) / (scope->channels * sizeof (gint16)); + dx = scope->width / 65536.0; + ox = scope->width / 2; + dy = scope->height / 65536.0; + oy = scope->height / 2; + s = 0; + for (i = 0; i < num_samples; i++) { + x = (guint) (ox + (gfloat) adata[s++] * dx); + y = (guint) (oy + (gfloat) adata[s++] * dy); + off = (y * w) + x; + vdata[off] = 0x00FFFFFF; + } + return TRUE; +} + +gboolean +gst_space_scope_plugin_init (GstPlugin * plugin) +{ + GST_DEBUG_CATEGORY_INIT (space_scope_debug, "spacescope", 0, "spacescope"); + + return gst_element_register (plugin, "spacescope", GST_RANK_NONE, + GST_TYPE_SPACE_SCOPE); +} diff --git a/gst/audiovisualizers/gstspacescope.h b/gst/audiovisualizers/gstspacescope.h new file mode 100644 index 000000000..0beae5a1f --- /dev/null +++ b/gst/audiovisualizers/gstspacescope.h @@ -0,0 +1,50 @@ +/* GStreamer + * Copyright (C) <2011> Stefan Kost <ensonic@users.sf.net> + * + * gstspacescope.h: simple stereo visualizer + * + * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + +#ifndef __GST_SPACE_SCOPE_H__ +#define __GST_SPACE_SCOPE_H__ + +#include "gstbaseaudiovisualizer.h" + +G_BEGIN_DECLS +#define GST_TYPE_SPACE_SCOPE (gst_space_scope_get_type()) +#define GST_SPACE_SCOPE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_SPACE_SCOPE,GstSpaceScope)) +#define GST_SPACE_SCOPE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_SPACE_SCOPE,GstSpaceScopeClass)) +#define GST_IS_SPACE_SCOPE(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_SPACE_SCOPE)) +#define GST_IS_SPACE_SCOPE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_SPACE_SCOPE)) +typedef struct _GstSpaceScope GstSpaceScope; +typedef struct _GstSpaceScopeClass GstSpaceScopeClass; + +struct _GstSpaceScope +{ + GstBaseAudioVisualizer parent; +}; + +struct _GstSpaceScopeClass +{ + GstBaseAudioVisualizerClass parent_class; +}; + +GType gst_space_scope_get_type (void); +gboolean gst_space_scope_plugin_init (GstPlugin * plugin); + +G_END_DECLS +#endif /* __GST_SPACE_SCOPE_H__ */
\ No newline at end of file diff --git a/gst/audiovisualizers/plugin.c b/gst/audiovisualizers/plugin.c index 42ac8a1b7..4130f9725 100644 --- a/gst/audiovisualizers/plugin.c +++ b/gst/audiovisualizers/plugin.c @@ -24,6 +24,7 @@ #include <gst/gst.h> #include <gst/controller/gstcontroller.h> +#include "gstspacescope.h" #include "gstspectrascope.h" #include "gstsynaescope.h" #include "gstwavescope.h" @@ -36,6 +37,7 @@ plugin_init (GstPlugin * plugin) /* initialize gst controller library */ gst_controller_init (NULL, NULL); + res &= gst_space_scope_plugin_init (plugin); res &= gst_spectra_scope_plugin_init (plugin); res &= gst_synae_scope_plugin_init (plugin); res &= gst_wave_scope_plugin_init (plugin); |