我正在寫一個C應用程序,它使用gstreamer從麥克風錄製音頻。 我希望能夠解析該音頻並顯示該音頻的可視化效果。我如何使用gstreamer解析音頻原始數據記錄器?
我有以下代碼:
#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 could not be created. Exiting.\n");
return;
}
g_object_set (G_OBJECT(source),"device","hw:3,0",NULL);
/* we add a 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 the main loop, clean up 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;
}
,你可以在我的代碼中看到我創建一個alsasrc和autoaudiosink。我測試過,我可以 正確聽取該設備。
我該如何寫一些東西來解析數據以創建可視化。
有關問題的任何信息,將不勝感激。