Re: Gstreamermm parsing question

On Tue, 2010-06-15 at 18:06 +0200, José Tomás Tocino García wrote: 
> Hi,
> I'm new to gstreamer; I'm developing a C++ game and I need to apply a
> FFT to the microphone input in order to get the pitch. Previously I
> was using Portaudio and a separate fft library, but now that I'm
> trying to switch to GStreamer looks like the "spectrum" element could
> do the job. I've managed to set up an example that creates a small
> program that links a pulsesrc with a spectrum and the to pulsesink,
> but I don't know how to parse the messages that spectrum sends.

To parse the messages, it is necessary to get the bus of the pipeline
and either add a watch using Gst::Bus::add_watch() to get the messages
or use Gst::Bus::add_signal_watch() and connect to the
Gst::signal_message().  Your slot (callback) can handle the messages
which will contain a Gst::Structure with the information.

Unfortunately, the spectrum plugin is part of the GStreamer good
plug-ins and we've not been able to wrap that module yet, so you'll have
to use the generic way of accessing its properties and probably use some
C for other things.  The gstreamermm module has an example that shows
how to use plug-ins "generically":

> In the spectrum reference [1], it says that the structure has an
> attribute called "magnitudes", which is a "GstValueList of gfloat",
> but I don't know how to parse it, because Gst::Structure [2] hasn't
> got any appropiate get_field method. However, there's the method
> called get_field_type, but I don't know what to do with the GType it
> returns.

GstValueList is not really a type, it's really a GValue that contains a
list of GValues.  The GStreamer API has convenience methods for working
with these but I didn't see the need to add those (until now) so to get
to the list, it will be necessary to use a combination of C++ and C:

Glib::ValueBase magnitudes;
structure->get_field("magnitude", magnitudes);
Glib::Value<float> magnitudeVal;
magnitudeVal.init(g_value_list_get_value(magnitudes.gobj(), index);
float magnitude = magnitudeVal.get();

There is a C example in the spectrum docs that might be used as a

> As a side question, would it be possible to get the raw stream for me
> to manually parse it?

I think so, but I think that asking on the gstreamer-devel list might
give better information than I could.


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]