2 * Copyright (C) 2006 Josep Torra <j.torra@telefonica.net>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
29 #define DEFAULT_AUDIOSINK "alsasink"
31 GtkWidget *lblFrequency;
34 on_window_destroy (GtkObject * object, gpointer user_data)
39 /* control audiotestsrc frequency */
41 on_frequency_changed (GtkRange * range, gpointer user_data)
43 GstElement *machine = GST_ELEMENT (user_data);
44 gdouble value = gtk_range_get_value (range);
46 g_object_set (machine, "freq", value, NULL);
49 /* control audiotestsrc frequency */
51 update_frequency (gint frequency)
56 g_snprintf (freq, 5, "%d", frequency);
57 buffer = g_strconcat ("Frequency is ", freq, NULL);
58 gtk_label_set_text (GTK_LABEL (lblFrequency), buffer);
62 /* receive spectral data from element message */
64 message_handler (GstBus * bus, GstMessage * message, gpointer data)
66 if (message->type == GST_MESSAGE_ELEMENT) {
67 const GstStructure *s = gst_message_get_structure (message);
68 const gchar *name = gst_structure_get_name (s);
70 if (strcmp (name, "kissfft") == 0) {
73 frequency = g_value_get_int (gst_structure_get_value (s, "frequency"));
74 update_frequency (frequency);
77 /* we handled the message we want, and ignored the ones we didn't want.
78 * so the core can unref the message for us */
83 main (int argc, char *argv[])
86 GstElement *src, *kissfft, *sink;
88 GtkWidget *appwindow, *vbox, *widget;
90 gst_init (&argc, &argv);
91 gtk_init (&argc, &argv);
93 bin = gst_pipeline_new ("bin");
95 src = gst_element_factory_make ("audiotestsrc", "src");
97 kissfft = gst_element_factory_make ("kissfft", "kissfft");
98 g_object_set (G_OBJECT (kissfft), "nfft", 1024, "message", TRUE, "minfreq",
99 220, "maxfreq", 1500, NULL);
101 sink = gst_element_factory_make (DEFAULT_AUDIOSINK, "sink");
103 gst_bin_add_many (GST_BIN (bin), src, kissfft, sink, NULL);
104 if (!gst_element_link_many (src, kissfft, sink, NULL)) {
105 fprintf (stderr, "cant link elements\n");
109 bus = gst_element_get_bus (bin);
110 gst_bus_add_watch (bus, message_handler, NULL);
111 gst_object_unref (bus);
113 appwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
114 g_signal_connect (G_OBJECT (appwindow), "destroy",
115 G_CALLBACK (on_window_destroy), NULL);
116 vbox = gtk_vbox_new (FALSE, 6);
118 widget = gtk_hscale_new_with_range (50.0, 2000.0, 10);
119 gtk_widget_set_size_request (widget, 300, -1);
120 gtk_scale_set_draw_value (GTK_SCALE (widget), TRUE);
121 gtk_scale_set_value_pos (GTK_SCALE (widget), GTK_POS_TOP);
122 gtk_range_set_value (GTK_RANGE (widget), 440.0);
123 g_signal_connect (G_OBJECT (widget), "value-changed",
124 G_CALLBACK (on_frequency_changed), (gpointer) src);
125 gtk_container_add (GTK_CONTAINER (vbox), widget);
127 lblFrequency = gtk_label_new ("Frequency is ");
128 gtk_container_add (GTK_CONTAINER (vbox), lblFrequency);
130 gtk_container_add (GTK_CONTAINER (appwindow), vbox);
131 gtk_widget_show_all (appwindow);
133 gst_element_set_state (bin, GST_STATE_PLAYING);
135 gst_element_set_state (bin, GST_STATE_NULL);
137 gst_object_unref (bin);