我怎么能解析在GStreamer音频原始数据记录仪? [英] how can I parse audio raw data recorder with gstreamer?

查看:889
本文介绍了我怎么能解析在GStreamer音频原始数据记录仪?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个使用GStreamer的录制从麦克风音频C应用程序。
我希望能够解析音频和显示,音频的可视化。

I'm writing a C application that uses gstreamer to record audio from a microphone. I want to be able to parse that audio and show a visualization of that audio.

我有以下的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 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;
}

,你可以在我的code看到我创建一个alsasrc和autoaudiosink。我测试,我可以
正确地收听到该设备。

as you can see in my code i create an alsasrc and autoaudiosink. I tested and I can listen properly to that device.

我怎么能写在解析,以创建可视化的数据中间的东西。

how can I write something in the middle that parses the data in order to create visualization.

有关问题的任何信息,将大大AP preciated。

any information regarding the issue would be greatly appreciated.

推荐答案

<一个href=\"http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-appsink.html\"相对=nofollow> appsink 元素,可以从管道中获取数据。

appsink element allows you to get data from the pipeline.

您有三个选项:


  • :启动管道,然后得到样品<一个href=\"http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-appsink.html#gst-app-sink-pull-sample\"相对=nofollow> gst_app_sink_pull_sample

  • 推带信号:启用新样本信号发射<一个href=\"http://gstreamer.freedesktop.org/data/doc/gstreamer/head/gst-plugins-base-libs/html/gst-plugins-base-libs-appsink.html#gst-app-sink-get-emit-signals\"相对=nofollow> gst_app_src_set_emit_signals 和订阅该信号

  • 一推回调:在注册新示例回调 gst_app_sink_set_callbacks

  • pull: start pipeline, then get samples with gst_app_sink_pull_sample
  • push with signals: enable new-sample signal emission with gst_app_src_set_emit_signals, and subscribe to that signals
  • push with callbacks: register callback on new-sample with gst_app_sink_set_callbacks

我认为第三个选项是最简单和更高效。

I think that the third option is the easiest and more efficient.

因此​​,只需更换 autoaudiosink appsink ,注册回调并在它处理你的数据。

So, just replace autoaudiosink with appsink, register callback and handle your data in it.

您可以阅读一些关于 appsrc appsink 中的手动

You can read a bit about appsrc and appsink in the manual.

这篇关于我怎么能解析在GStreamer音频原始数据记录仪?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆