Good morning mates.<br><br>I've been working on this code over a month and I can't figure out what is wrong with it. <br><br>I am developing a spectrum analyser and as a first step the program is capturing sound from alsa and analysing the sound using the spectrum plug-in.<br>
<br>If I use audiotestsrc, I get the results on screen as expected, when I change to alsasrc, I still get the results on screen but without modification, as if I didn't have any sound comming from my microfone. <br>Its is strange 'cause my mic is working pretty well since I am able to record sound.<br>
<br>I was wondering if someone could gimme some help here.....!<br><br><br>Thanks in advanced...<br><br><br><br>#include <string.h><br>#include <stdlib.h><br>#include <gst/gst.h><br><br>static guint spect_bands = 20;<br>
<br>#define AUDIOFREQ 44100<br><br>/* receive spectral data from element message */<br>gboolean<br>message_handler (GstBus * bus, GstMessage * message, gpointer data)<br>{<br> if (message->type == GST_MESSAGE_ELEMENT) {<br>
const GstStructure *s = gst_message_get_structure (message);<br> const gchar *name = gst_structure_get_name (s);<br> GstClockTime endtime;<br><br> if (strcmp (name, "spectrum") == 0) {<br> const GValue *magnitudes;<br>
const GValue *phases;<br> const GValue *mag, *phase;<br> gdouble freq;<br> guint i;<br><br> if (!gst_structure_get_clock_time (s, "endtime", &endtime))<br> endtime = GST_CLOCK_TIME_NONE;<br>
<br> g_print ("New spectrum message, endtime %" GST_TIME_FORMAT "\n",<br> GST_TIME_ARGS (endtime));<br><br> magnitudes = gst_structure_get_value (s, "magnitude");<br> phases = gst_structure_get_value (s, "phase");<br>
<br> for (i = 0; i < spect_bands; ++i) {<br> freq = (gdouble) ((AUDIOFREQ / 2) * i + AUDIOFREQ / 4) / spect_bands;<br> mag = gst_value_list_get_value (magnitudes, i);<br> phase = gst_value_list_get_value (phases, i);<br>
<br> if (mag != NULL && phase != NULL) {<br> g_print ("band %d (freq %g): magnitude %f dB phase %f\n", i, freq,<br> g_value_get_float (mag), g_value_get_float (phase));<br> }<br>
}<br> g_print ("\n");<br> }<br> }<br> return TRUE;<br>}<br><br>int<br>main (int argc, char *argv[])<br>{<br> GstElement *bin;<br> GstElement *src, *spectrum, *sink;<br> GstBus *bus;<br> GMainLoop *loop;<br>
<br> gst_init (&argc, &argv);<br><br> bin = gst_pipeline_new ("bin");<br><br> src = gst_element_factory_make ("audiotestsrc", "src");<br><br> spectrum = gst_element_factory_make ("spectrum", "spectrum");<br>
g_object_set (G_OBJECT (spectrum), "bands", spect_bands,<br> "message", TRUE, "message-phase", TRUE, NULL);<br><br> sink = gst_element_factory_make ("fakesink", "sink");<br>
g_object_set (G_OBJECT (sink), "sync", TRUE, NULL);<br><br> gst_bin_add_many (GST_BIN (bin), src, spectrum, sink, NULL);<br><br><br> if (!gst_element_link (src, spectrum) ||<br> !gst_element_link (spectrum, sink)) {<br>
fprintf (stderr, "can't link elements\n");<br> exit (1);<br> }<br><br> <br> bus = gst_element_get_bus (bin);<br> gst_bus_add_watch (bus, message_handler, NULL);<br> gst_object_unref (bus);<br><br> gst_element_set_state (bin, GST_STATE_PLAYING);<br>
<br> /* we need to run a GLib main loop to get the messages */<br> loop = g_main_loop_new (NULL, FALSE);<br> g_main_loop_run (loop);<br><br> gst_element_set_state (bin, GST_STATE_NULL);<br><br> gst_object_unref (bin);<br>
<br> return 0;<br>}<br>-- <br>Guilherme Raymo Longo<br>Software Developer<br>Mob. 087 - 3179008<br>msn: <a href="mailto:grlongo.ireland@hotmail.com">grlongo.ireland@hotmail.com</a><br>skype: grlongo.ireland<br>