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_AUDIOSRC "alsasrc"
31 GtkWidget *lblFrequency;
34 on_window_destroy (GtkObject * object, gpointer user_data)
39 /* update frequency label */
41 update_frequency (gint frequency)
46 g_snprintf (freq, 5, "%d", frequency);
47 buffer = g_strconcat ("Frequency is ", freq, NULL);
48 gtk_label_set_text (GTK_LABEL (lblFrequency), buffer);
52 /* receive spectral data from element message */
54 message_handler (GstBus * bus, GstMessage * message, gpointer data)
56 if (message->type == GST_MESSAGE_ELEMENT) {
57 const GstStructure *s = gst_message_get_structure (message);
58 const gchar *name = gst_structure_get_name (s);
60 if (strcmp (name, "kissfft") == 0) {
63 frequency = g_value_get_int (gst_structure_get_value (s, "frequency"));
64 update_frequency (frequency);
67 /* we handled the message we want, and ignored the ones we didn't want.
68 * so the core can unref the message for us */
73 main (int argc, char *argv[])
76 GstElement *src, *kissfft, *sink;
78 GtkWidget *appwindow, *vbox;
80 gst_init (&argc, &argv);
81 gtk_init (&argc, &argv);
83 bin = gst_pipeline_new ("bin");
85 src = gst_element_factory_make (DEFAULT_AUDIOSRC, "src");
87 kissfft = gst_element_factory_make ("kissfft", "kissfft");
88 g_object_set (G_OBJECT (kissfft), "nfft", 16000, "message", TRUE, "minfreq",
89 220, "maxfreq", 1500, NULL);
91 sink = gst_element_factory_make ("fakesink", "sink");
92 g_object_set (G_OBJECT (sink), "silent", 1, NULL);
94 gst_bin_add_many (GST_BIN (bin), src, kissfft, sink, NULL);
95 if (!gst_element_link_many (src, kissfft, sink, NULL)) {
96 fprintf (stderr, "cant link elements\n");
100 bus = gst_element_get_bus (bin);
101 gst_bus_add_watch (bus, message_handler, NULL);
102 gst_object_unref (bus);
104 appwindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
105 g_signal_connect (G_OBJECT (appwindow), "destroy",
106 G_CALLBACK (on_window_destroy), NULL);
107 vbox = gtk_vbox_new (FALSE, 6);
109 lblFrequency = gtk_label_new ("Frequency is ");
110 gtk_widget_set_size_request (lblFrequency, 300, -1);
111 gtk_container_add (GTK_CONTAINER (vbox), lblFrequency);
113 gtk_container_add (GTK_CONTAINER (appwindow), vbox);
114 gtk_widget_show_all (appwindow);
116 gst_element_set_state (bin, GST_STATE_PLAYING);
118 gst_element_set_state (bin, GST_STATE_NULL);
120 gst_object_unref (bin);