Good morning mates.<br><br>I&#39;ve been working on this code over a month and I can&#39;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&#39;t have any sound comming from my microfone. <br>Its is strange &#39;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 &lt;string.h&gt;<br>#include &lt;stdlib.h&gt;<br>#include &lt;gst/gst.h&gt;<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-&gt;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, &quot;spectrum&quot;) == 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, &quot;endtime&quot;, &amp;endtime))<br>        endtime = GST_CLOCK_TIME_NONE;<br>
<br>      g_print (&quot;New spectrum message, endtime %&quot; GST_TIME_FORMAT &quot;\n&quot;,<br>          GST_TIME_ARGS (endtime));<br><br>      magnitudes = gst_structure_get_value (s, &quot;magnitude&quot;);<br>      phases = gst_structure_get_value (s, &quot;phase&quot;);<br>
<br>      for (i = 0; i &lt; 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 &amp;&amp; phase != NULL) {<br>          g_print (&quot;band %d (freq %g): magnitude %f dB phase %f\n&quot;, i, freq,<br>              g_value_get_float (mag), g_value_get_float (phase));<br>        }<br>
      }<br>      g_print (&quot;\n&quot;);<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 (&amp;argc, &amp;argv);<br><br>  bin = gst_pipeline_new (&quot;bin&quot;);<br><br>  src = gst_element_factory_make (&quot;audiotestsrc&quot;, &quot;src&quot;);<br><br>  spectrum = gst_element_factory_make (&quot;spectrum&quot;, &quot;spectrum&quot;);<br>
  g_object_set (G_OBJECT (spectrum), &quot;bands&quot;, spect_bands,<br>      &quot;message&quot;, TRUE, &quot;message-phase&quot;, TRUE, NULL);<br><br>  sink = gst_element_factory_make (&quot;fakesink&quot;, &quot;sink&quot;);<br>
  g_object_set (G_OBJECT (sink), &quot;sync&quot;, 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, &quot;can&#39;t link elements\n&quot;);<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>