From: Thomas V. S. <tho...@us...> - 2003-09-26 18:47:20
|
CVS Root: /cvsroot/gstreamer Module: gst-plugins Changes by: thomasvs Date: Fri Sep 26 2003 09:45:17 PDT Log message: added second example with plotting fixed some aesthetics Modified files: gst/level : Makefile.am README demo.c gstlevel-marshal.list gstlevel.c gstlevel.h Added files: gst/level : plot.c Links: http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/gst/level/Makefile.am.diff?r1=1.10&r2=1.11 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/gst/level/README.diff?r1=1.2&r2=1.3 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/gst/level/demo.c.diff?r1=1.1&r2=1.2 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/gst/level/gstlevel-marshal.list.diff?r1=1.1&r2=1.2 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/gst/level/gstlevel.c.diff?r1=1.19&r2=1.20 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/gst/level/gstlevel.h.diff?r1=1.4&r2=1.5 http://cvs.sf.net/cgi-bin/viewcvs.cgi/gstreamer/gst-plugins/gst/level/plot.c?rev=1.1&content-type=text/vnd.viewcvs-markup ====Begin Diffs==== Index: Makefile.am =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/gst/level/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -u -d -r1.10 -r1.11 --- Makefile.am 21 Sep 2003 13:24:13 -0000 1.10 +++ Makefile.am 26 Sep 2003 16:45:04 -0000 1.11 @@ -9,10 +9,13 @@ noinst_HEADERS = gstlevel.h filter.func if HAVE_GTK -noinst_PROGRAMS = demo +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 EXTRA_libgstlevel_la_SOURCES = gstlevel-marshal.list Index: README =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/gst/level/README,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- README 21 Sep 2003 12:21:49 -0000 1.2 +++ README 26 Sep 2003 16:45:04 -0000 1.3 @@ -1,6 +1,7 @@ level plugin by thomas <th...@ap...> this plugin signals: + - running time since last EOS/start - channel - RMS level - peak level @@ -17,5 +18,22 @@ 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 Index: demo.c =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/gst/level/demo.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- demo.c 21 Sep 2003 13:24:13 -0000 1.1 +++ demo.c 26 Sep 2003 16:45:04 -0000 1.2 @@ -28,7 +28,7 @@ GtkWidget *scale[2][3]; static void -level_callback (GstElement *element, gint channel, +level_callback (GstElement *element, gdouble time, gint channel, gdouble rms, gdouble peak, gdouble decay) { gtk_range_set_value (GTK_RANGE (scale[channel][0]), rms); @@ -41,7 +41,10 @@ { GstElement *pipeline = GST_ELEMENT (data); g_print ("+"); - return gst_bin_iterate (GST_BIN (pipeline)); + if (gst_bin_iterate (GST_BIN (pipeline))) + return TRUE; + gtk_main_quit (); + return FALSE; } static void Index: gstlevel-marshal.list =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/gst/level/gstlevel-marshal.list,v retrieving revision 1.1 retrieving revision 1.2 diff -u -d -r1.1 -r1.2 --- gstlevel-marshal.list 21 Sep 2003 12:21:49 -0000 1.1 +++ gstlevel-marshal.list 26 Sep 2003 16:45:04 -0000 1.2 @@ -1 +1 @@ -VOID:INT,DOUBLE,DOUBLE,DOUBLE +VOID:DOUBLE,INT,DOUBLE,DOUBLE,DOUBLE Index: gstlevel.c =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/gst/level/gstlevel.c,v retrieving revision 1.19 retrieving revision 1.20 diff -u -d -r1.19 -r1.20 --- gstlevel.c 21 Sep 2003 13:08:29 -0000 1.19 +++ gstlevel.c 26 Sep 2003 16:45:04 -0000 1.20 @@ -214,7 +214,7 @@ for (i = 0; i < filter->channels; ++i) filter->CS[i] = filter->peak[i] = filter->MS[i] = filter->RMS_dB[i] = 0.0; - in_data = (gint16 *) GST_BUFFER_DATA(buf); + in_data = (gint16 *) GST_BUFFER_DATA (buf); num_samples = GST_BUFFER_SIZE (buf) / (filter->width / 8); if (num_samples % filter->channels != 0) @@ -288,14 +288,18 @@ { if (filter->signal) { - gdouble RMS, peak; + gdouble RMS, peak, endtime; for (i = 0; i < filter->channels; ++i) { RMS = sqrt (filter->CS[i] / (filter->num_samples / filter->channels)); peak = filter->last_peak[i]; + num_samples = GST_BUFFER_SIZE (buf) / (filter->width / 8); + endtime = (double) GST_BUFFER_TIMESTAMP (buf) / GST_SECOND + + (double) num_samples / (double) filter->rate; g_signal_emit (G_OBJECT (filter), gst_filter_signals[SIGNAL_LEVEL], 0, - i, 20 * log10 (RMS), 20 * log10 (filter->last_peak[i]), + endtime, i, + 20 * log10 (RMS), 20 * log10 (filter->last_peak[i]), 20 * log10 (filter->decay_peak[i])); /* we emitted, so reset cumulative and normal peak */ filter->CS[i] = 0.0; @@ -397,9 +401,10 @@ gst_filter_signals[SIGNAL_LEVEL] = g_signal_new ("level", G_TYPE_FROM_CLASS(klass), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (GstLevelClass, level), NULL, NULL, - gstlevel_cclosure_marshal_VOID__INT_DOUBLE_DOUBLE_DOUBLE, - G_TYPE_NONE, 4, - G_TYPE_INT, G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE); + gstlevel_cclosure_marshal_VOID__DOUBLE_INT_DOUBLE_DOUBLE_DOUBLE, + G_TYPE_NONE, 5, + G_TYPE_DOUBLE, G_TYPE_INT, + G_TYPE_DOUBLE, G_TYPE_DOUBLE, G_TYPE_DOUBLE); } static void Index: gstlevel.h =================================================================== RCS file: /cvsroot/gstreamer/gst-plugins/gst/level/gstlevel.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- gstlevel.h 21 Sep 2003 12:21:49 -0000 1.4 +++ gstlevel.h 26 Sep 2003 16:45:04 -0000 1.5 @@ -77,7 +77,7 @@ struct _GstLevelClass { GstElementClass parent_class; - void (*level) (GstElement *element, gint channel, + void (*level) (GstElement *element, gdouble time, gint channel, gdouble RMS_dB, gdouble peak_dB, gdouble decay_peak_dB); }; --- NEW FILE: plot.c --- /* GStreamer * Copyright (C) <1999> Erik Walthinsen <om...@cs...> * * 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. */ #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 ! osssink\n"); 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; } |