2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * plot.c: output data points to be graphed with gnuplot
6 * Thomas Vander Stichele <thomas at apestaart dot org>
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
18 * You should have received a copy of the GNU Library General Public
19 * License along with this library; if not, write to the
20 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 * Boston, MA 02111-1307, USA.
31 gboolean got_channel[2] = { FALSE, FALSE }; /* to see if we got the signal for this one yet */
32 gint channels = 0; /* guess at how many channels there are */
33 gdouble last_time = 0.0; /* time of last signal */
34 gdouble values[2][3]; /* array of levels from which to print */
37 level_callback (GstElement * element, gdouble time, gint channel,
38 gdouble rms, gdouble peak, gdouble decay)
41 gboolean got_all = FALSE;
43 if (channel + 1 > channels)
44 channels = channel + 1;
46 /* reset got_channel if this is a new time point */
47 if (time > last_time) {
48 for (i = 0; i < channels; ++i)
49 got_channel[i] = FALSE;
54 got_channel[channel] = TRUE;
55 values[channel][0] = rms;
56 values[channel][1] = peak;
57 values[channel][2] = decay;
59 /* check if we have all channels, and output if we do */
60 /* FIXME: this fails on the first, no ? */
62 for (i = 0; i < channels; ++i)
66 g_print ("%f ", time);
67 for (i = 0; i < channels; ++i)
68 for (j = 0; j < 3; ++j)
69 g_print ("%f ", values[i][j]);
77 GstElement *pipeline = GST_ELEMENT (data);
79 if (gst_bin_iterate (GST_BIN (pipeline)))
87 main (int argc, char *argv[])
90 GstElement *pipeline = NULL;
94 gst_init (&argc, &argv);
95 gtk_init (&argc, &argv);
97 pipeline = gst_parse_launchv ((const gchar **) &argv[1], &error);
99 g_print ("pipeline could not be constructed: %s\n", error->message);
100 g_print ("Please give a complete pipeline with a 'level' element.\n");
101 g_print ("Example: sinesrc ! level ! osssink\n");
102 g_error_free (error);
106 level = gst_bin_get_by_name (GST_BIN (pipeline), "level0");
108 g_print ("Please give a pipeline with a 'level' element in it\n");
112 g_object_set (level, "signal", TRUE, NULL);
113 g_signal_connect (level, "level", G_CALLBACK (level_callback), NULL);
116 /* go to main loop */
117 gst_element_set_state (pipeline, GST_STATE_PLAYING);
118 g_idle_add (idler, pipeline);