c - how can I parse audio raw data recorder with gstreamer? -


i'm writing c application uses gstreamer record audio microphone. want able parse audio , show visualization of audio.

i have following code:

#include <gst/gst.h> #include <glib.h>   static gboolean bus_call (gstbus     *bus,       gstmessage *msg,       gpointer    data) { gmainloop *loop = (gmainloop *) data;  switch (gst_message_type (msg)) {  case gst_message_eos:   g_print ("end of stream\n");   g_main_loop_quit (loop);   break;  case gst_message_error: {   gchar  *debug;   gerror *error;    gst_message_parse_error (msg, &error, &debug);   g_free (debug);    g_printerr ("error: %s\n", error->message);   g_error_free (error);    g_main_loop_quit (loop);   break; } default:   break; }  return true; }   void create_loop() { gmainloop *loop;  gstelement *pipeline, *source, *sink; gstbus *bus; guint bus_watch_id;   /* initialisation */  loop = g_main_loop_new (null, false);    /* create gstreamer elements */ pipeline = gst_pipeline_new ("audio-player"); source   = gst_element_factory_make ("alsasrc",       "alsa-source"); sink     = gst_element_factory_make ("autoaudiosink", "audio-output");  if (!pipeline || !source  || !sink) {  g_printerr ("one element not created. exiting.\n");  return; }  g_object_set (g_object(source),"device","hw:3,0",null);  /* add message handler */ bus = gst_pipeline_get_bus (gst_pipeline (pipeline)); bus_watch_id = gst_bus_add_watch (bus, bus_call, loop); gst_object_unref (bus);  gst_bin_add_many (gst_bin (pipeline),                 source,  sink, null);  gst_element_link (source, sink); gst_element_set_state (pipeline, gst_state_playing);   /* iterate */ g_print ("running...\n"); g_main_loop_run (loop);   /* out of main loop, clean nicely */ g_print ("returned, stopping playback\n"); gst_element_set_state (pipeline, gst_state_null);  g_print ("deleting pipeline\n"); gst_object_unref (gst_object (pipeline)); g_source_remove (bus_watch_id); g_main_loop_unref (loop);  }  int main(int argc, char** argv) {   gst_init(&argc,&argv);   create_loop();   return 0; } 

as can see in code create alsasrc , autoaudiosink. tested , can listen device.

how can write in middle parses data in order create visualization.

any information regarding issue appreciated.

appsink element allows data pipeline.

you have 3 options:

i think third option easiest , more efficient.

so, replace autoaudiosink appsink, register callback , handle data in it.

you can read bit appsrc , appsink in manual.


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -