Commit 77a7c4c8 authored by Andy Wingo's avatar Andy Wingo

examples/level/: Examples moved out of the source dir. Not updated tho.

Original commit message from CVS:
2005-07-04  Andy Wingo  <wingo@pobox.com>

* examples/level/:
* examples/level/Makefile.am:
* examples/level/README:
* examples/level/demo.c:
* examples/level/plot.c: Examples moved out of the source dir. Not
updated tho.

* configure.ac: Add level to the build.

* gst/level/Makefile.am:
* gst/level/gstlevel.h:
* gst/level/gstlevel.c: Cleaned up, ported to 0.9.
parent d0516df7
......@@ -5,6 +5,19 @@
2005-07-04 Andy Wingo <wingo@pobox.com>
* examples/level/:
* examples/level/Makefile.am:
* examples/level/README:
* examples/level/demo.c:
* examples/level/plot.c: Examples moved out of the source dir. Not
updated tho.
* configure.ac: Add level to the build.
* gst/level/Makefile.am:
* gst/level/gstlevel.h:
* gst/level/gstlevel.c: Cleaned up, ported to 0.9.
* ext/aalib/gstaasink.c (gst_aasink_fixate): Update for newer
fixate prototype.
......
......@@ -297,15 +297,17 @@ dnl these are all the gst plug-ins, compilable without additional libs
GST_PLUGINS_ALL="\
alpha \
avi \
videofilter \
effectv \
goom \
law \
level \
realmedia \
rtp \
rtsp \
smpte \
udp"
udp \
videofilter \
"
dnl see if we can build C++ plug-ins
if test "x$HAVE_CXX" = "xyes"; then
......@@ -489,6 +491,7 @@ gst/avi/Makefile
gst/effectv/Makefile
gst/goom/Makefile
gst/law/Makefile
gst/level/Makefile
gst/realmedia/Makefile
gst/rtp/Makefile
gst/rtsp/Makefile
......
......@@ -5,7 +5,7 @@ FT2_SUBDIRS=
endif
if HAVE_GTK
GTK_SUBDIRS=dynparams $(FT2_SUBDIRS)
GTK_SUBDIRS=dynparams level $(FT2_SUBDIRS)
else
GTK_SUBDIRS=
endif
......@@ -17,4 +17,4 @@ GCONF_SUBDIRS=
endif
SUBDIRS=$(GTK_SUBDIRS) $(GCONF_SUBDIRS) switch
DIST_SUBDIRS=capsfilter dynparams seeking indexing gstplay switch
DIST_SUBDIRS=capsfilter dynparams seeking indexing gstplay switch level
noinst_PROGRAMS = demo plot
demo_SOURCES = demo.c
demo_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS)
demo_LDFLAGS = $(GTK_LIBS) $(GST_LIBS)
plot_SOURCES = plot.c
plot_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS)
plot_LDFLAGS = $(GTK_LIBS) $(GST_LIBS)
EXTRA_DIST = README
plugin_LTLIBRARIES = libgstlevel.la
# variables used for enum/marshal generation
glib_enum_define = GST_LEVEL
glib_enum_prefix = gst_level
include $(top_srcdir)/common/glib-gen.mak
built_sources = gstlevel-marshal.c
built_headers = gstlevel-marshal.h
BUILT_SOURCES = $(built_sources) $(built_headers)
libgstlevel_la_SOURCES = gstlevel.c
nodist_libgstlevel_la_SOURCES = $(built_sources)
libgstlevel_la_CFLAGS = $(GST_CFLAGS)
libgstlevel_la_LIBADD =
libgstlevel_la_LIBADD = $(GST_BASE_LIBS)
libgstlevel_la_LDFLAGS = $(GST_PLUGIN_LDFLAGS)
noinst_HEADERS = gstlevel.h filter.func
if HAVE_GTK
noinst_PROGRAMS = demo plot
demo_SOURCES = demo.c
demo_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS)
demo_LDFLAGS = $(GTK_LIBS) $(GST_LIBS)
plot_SOURCES = plot.c
plot_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS)
plot_LDFLAGS = $(GTK_LIBS) $(GST_LIBS)
endif
CLEANFILES = $(BUILT_SOURCES)
EXTRA_DIST = README gstlevel-marshal.list
noinst_HEADERS = gstlevel.h
/*
static void inline
gst_level_fast_16bit_chain (gint16 * in, guint num, gint channels,
gint resolution, double *CS, double *peak)
*/
/* process one (interleaved) channel of incoming samples
* calculate square sum of samples
* normalize and return normalized Cumulative Square
* caller must assure num is a multiple of channels
* this filter only accepts signed audio data, so mid level is always 0
*/
{
register int j;
double squaresum = 0.0; /* square sum of the integer samples */
register double square = 0.0; /* Square */
register double PSS = 0.0; /* Peak Square Sample */
gdouble normalizer;
*CS = 0.0; /* Cumulative Square for this block */
normalizer = (double) (1 << resolution);
/*
* process data here
* input sample data enters in *in_data as 8 or 16 bit data
* samples for left and right channel are interleaved
* returns the Mean Square of the samples as a double between 0 and 1
*/
for (j = 0; j < num; j += channels)
{
//g_print ("ch %d -> smp %d\n", j, in[j]);
square = (double) (in[j] * in[j]);
if (square > PSS) PSS = square;
squaresum += square;
}
*peak = PSS / ((double) normalizer * (double) normalizer);
/* return normalized cumulative square */
*CS = squaresum / ((double) normalizer * (double) normalizer);
}
VOID:DOUBLE,INT,DOUBLE,DOUBLE,DOUBLE
This diff is collapsed.
......@@ -27,12 +27,10 @@
#include <gst/gst.h>
#include <gst/base/gstbasetransform.h>
#include "gstlevel-marshal.h"
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
G_BEGIN_DECLS
#define GST_TYPE_LEVEL \
......@@ -46,13 +44,14 @@ extern "C" {
#define GST_IS_LEVEL_CLASS(obj) \
(G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_LEVEL))
typedef struct _GstLevel GstLevel;
typedef struct _GstLevelClass GstLevelClass;
struct _GstLevel {
GstElement element;
GstBaseTransform element;
GstPad *sinkpad, *srcpad;
gboolean signal; /* whether or not to emit signals */
gdouble interval; /* how many seconds between emits */
......@@ -75,16 +74,14 @@ struct _GstLevel {
};
struct _GstLevelClass {
GstElementClass parent_class;
void (*level) (GstElement *element, gdouble time, gint channel,
gdouble RMS_dB, gdouble peak_dB, gdouble decay_peak_dB);
GstBaseTransformClass parent_class;
};
GType gst_level_get_type(void);
#ifdef __cplusplus
}
#endif /* __cplusplus */
G_END_DECLS
#endif /* __GST_STEREO_H__ */
#endif /* __GST_LEVEL_H__ */
......@@ -5,7 +5,7 @@ FT2_SUBDIRS=
endif
if HAVE_GTK
GTK_SUBDIRS=dynparams $(FT2_SUBDIRS)
GTK_SUBDIRS=dynparams level $(FT2_SUBDIRS)
else
GTK_SUBDIRS=
endif
......@@ -17,4 +17,4 @@ GCONF_SUBDIRS=
endif
SUBDIRS=$(GTK_SUBDIRS) $(GCONF_SUBDIRS) switch
DIST_SUBDIRS=capsfilter dynparams seeking indexing gstplay switch
DIST_SUBDIRS=capsfilter dynparams seeking indexing gstplay switch level
noinst_PROGRAMS = demo plot
demo_SOURCES = demo.c
demo_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS)
demo_LDFLAGS = $(GTK_LIBS) $(GST_LIBS)
plot_SOURCES = plot.c
plot_CFLAGS = $(GTK_CFLAGS) $(GST_CFLAGS)
plot_LDFLAGS = $(GTK_LIBS) $(GST_LIBS)
EXTRA_DIST = README
level plugin by thomas <thomas@apestaart.org>
this plugin signals:
- running time since last EOS/start
- channel
- RMS level
- peak level
- decaying peak level
over the given interval.
This is useful for a VU meter display and for plotting out the signal graph.
The VU meter can either display RMS, or display immediate peak level and
have the falloff decaying peak level displayed as a line.
The interval for signal emission, ttl of decay peak, and falloff of decay peak
can all be set.
The element only takes unsigned data in; it could be extended to signed as
well, if separate fast chain functions are made that displaces the incoming
data to its midpoint (ie, 0,65535 should be mapped to -32768, 32767)
There are two demo apps, apps and plot. apps will create some GTK sliders
to display the volume. plot will output data readable by gnuplot.
Here is a sample plot script to plot output of the plot command that was
stored to plot.dat
set xlabel "Seconds"
set ylabel "dB"
set yrange [-60:0]
plot 'plot.dat' using 1:2 title 'L RMS' with lines, \
'plot.dat' using 1:3 title 'L peak' with lines, \
'plot.dat' using 1:4 title 'L decay' with lines
plot 'plot.dat' using 1:5 title 'R RMS' with lines, \
'plot.dat' using 1:6 title 'R peak' with lines, \
'plot.dat' using 1:7 title 'R decay' with lines
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* demo.c: sample application to display VU meter-like output of level
* Copyright (C) 2003
* Thomas Vander Stichele <thomas at apestaart dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gtk/gtk.h>
/* global array for the scale widgets, we'll assume stereo */
GtkWidget *elapsed;
GtkWidget *scale[2][3];
static void
level_callback (GstElement * element, gdouble time, gint channel,
gdouble rms, gdouble peak, gdouble decay)
{
gchar *label;
label = g_strdup_printf ("%.3f", time);
gtk_label_set (GTK_LABEL (elapsed), label);
g_free (label);
gtk_range_set_value (GTK_RANGE (scale[channel][0]), rms);
gtk_range_set_value (GTK_RANGE (scale[channel][1]), peak);
gtk_range_set_value (GTK_RANGE (scale[channel][2]), decay);
}
static gboolean
idler (gpointer data)
{
GstElement *pipeline = GST_ELEMENT (data);
g_print ("+");
if (gst_bin_iterate (GST_BIN (pipeline)))
return TRUE;
gtk_main_quit ();
return FALSE;
}
static void
setup_gui ()
{
GtkWidget *window;
GtkWidget *vbox;
GtkWidget *label, *hbox;
int c;
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy", gtk_main_quit, NULL);
vbox = gtk_vbox_new (TRUE, 0);
gtk_container_add (GTK_CONTAINER (window), vbox);
/* elapsed widget */
hbox = gtk_hbox_new (TRUE, 0);
label = gtk_label_new ("Elapsed");
elapsed = gtk_label_new ("0.000");
gtk_container_add (GTK_CONTAINER (hbox), label);
gtk_container_add (GTK_CONTAINER (hbox), elapsed);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
for (c = 0; c < 2; ++c) {
/* RMS */
hbox = gtk_hbox_new (TRUE, 0);
label = gtk_label_new ("RMS");
gtk_container_add (GTK_CONTAINER (hbox), label);
scale[c][0] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2);
gtk_widget_set_size_request (scale[c][0], 100, -1);
gtk_container_add (GTK_CONTAINER (hbox), scale[c][0]);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
/* peak */
hbox = gtk_hbox_new (TRUE, 0);
label = gtk_label_new ("peak");
gtk_container_add (GTK_CONTAINER (hbox), label);
scale[c][1] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2);
gtk_widget_set_size_request (scale[c][1], 100, -1);
gtk_container_add (GTK_CONTAINER (hbox), scale[c][1]);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
/* decay */
hbox = gtk_hbox_new (TRUE, 0);
label = gtk_label_new ("decaying peek");
gtk_container_add (GTK_CONTAINER (hbox), label);
scale[c][2] = gtk_hscale_new_with_range (-90.0, 0.0, 0.2);
gtk_widget_set_size_request (scale[c][2], 100, -1);
gtk_container_add (GTK_CONTAINER (hbox), scale[c][2]);
gtk_container_add (GTK_CONTAINER (vbox), hbox);
}
gtk_widget_show_all (GTK_WIDGET (window));
}
int
main (int argc, char *argv[])
{
GstElement *pipeline = NULL;
GError *error = NULL;
GstElement *level;
gst_init (&argc, &argv);
gtk_init (&argc, &argv);
pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error);
if (error) {
g_print ("pipeline could not be constructed: %s\n", error->message);
g_print ("Please give a complete pipeline with a 'level' element.\n");
g_print ("Example: sinesrc ! level ! %s\n", DEFAULT_AUDIOSINK);
g_error_free (error);
return 1;
}
level = gst_bin_get_by_name (GST_BIN (pipeline), "level0");
if (level == NULL) {
g_print ("Please give a pipeline with a 'level' element in it\n");
return 1;
}
g_object_set (level, "signal", TRUE, NULL);
g_signal_connect (level, "level", G_CALLBACK (level_callback), NULL);
/* setup GUI */
setup_gui ();
/* connect level signal */
/* go to main loop */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
g_idle_add (idler, pipeline);
gtk_main ();
return 0;
}
/* GStreamer
* Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
*
* plot.c: output data points to be graphed with gnuplot
* Copyright (C) 2003
* Thomas Vander Stichele <thomas at apestaart dot org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <gst/gst.h>
#include <gtk/gtk.h>
gboolean got_channel[2] = { FALSE, FALSE }; /* to see if we got the signal for this one yet */
gint channels = 0; /* guess at how many channels there are */
gdouble last_time = 0.0; /* time of last signal */
gdouble values[2][3]; /* array of levels from which to print */
static void
level_callback (GstElement * element, gdouble time, gint channel,
gdouble rms, gdouble peak, gdouble decay)
{
int i = 0, j = 0;
gboolean got_all = FALSE;
if (channel + 1 > channels)
channels = channel + 1;
/* reset got_channel if this is a new time point */
if (time > last_time) {
for (i = 0; i < channels; ++i)
got_channel[i] = FALSE;
last_time = time;
}
/* store values */
got_channel[channel] = TRUE;
values[channel][0] = rms;
values[channel][1] = peak;
values[channel][2] = decay;
/* check if we have all channels, and output if we do */
/* FIXME: this fails on the first, no ? */
got_all = TRUE;
for (i = 0; i < channels; ++i)
if (!got_channel[i])
got_all = FALSE;
if (got_all) {
g_print ("%f ", time);
for (i = 0; i < channels; ++i)
for (j = 0; j < 3; ++j)
g_print ("%f ", values[i][j]);
g_print ("\n");
}
}
static gboolean
idler (gpointer data)
{
GstElement *pipeline = GST_ELEMENT (data);
if (gst_bin_iterate (GST_BIN (pipeline)))
return TRUE;
gtk_main_quit ();
return FALSE;
}
int
main (int argc, char *argv[])
{
GstElement *pipeline = NULL;
GError *error = NULL;
GstElement *level;
gst_init (&argc, &argv);
gtk_init (&argc, &argv);
pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error);
if (error) {
g_print ("pipeline could not be constructed: %s\n", error->message);
g_print ("Please give a complete pipeline with a 'level' element.\n");
g_print ("Example: sinesrc ! level ! %s\n", DEFAULT_AUDIOSINK);
g_error_free (error);
return 1;
}
level = gst_bin_get_by_name (GST_BIN (pipeline), "level0");
if (level == NULL) {
g_print ("Please give a pipeline with a 'level' element in it\n");
return 1;
}
g_object_set (level, "signal", TRUE, NULL);
g_signal_connect (level, "level", G_CALLBACK (level_callback), NULL);
/* go to main loop */
gst_element_set_state (pipeline, GST_STATE_PLAYING);
g_idle_add (idler, pipeline);
gtk_main ();
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment