简体   繁体   English

ALSA:全双工C的例子?

[英]ALSA: Full duplex C example?

is there an example of a full-duplex ALSA connection in C? 在C中有一个全双工ALSA连接的例子吗? I've read that it is supported, but all the introductory examples I saw did either record or play a sound sample, but I'd like to have one handler that can do both for my VoIP-app. 我已经读过它支持了,但是我看到的所有介绍性示例都记录或播放了一个声音样本,但我希望有一个处理程序可以同时为我的VoIP应用程序执行。

Big thanks for help, Jens 非常感谢你的帮助,Jens

一些名叫艾伦的人发表了这篇很好(但很旧)的教程, 全双工ALSA ,用C写的。

You provide a link to both handles and pump them in turn. 您提供两个手柄的链接并依次泵送它们。 Here's alan's code elided and commented. 这是艾伦的代码省略和评论。

// the device plughw handle dynamic sample rate and type conversion.
// there are a range of alternate devices defined in your alsa.conf
// try: 
// locate alsa.conf
// and check out what devices you have in there
//  
// The following device is PLUG:HW:Device:0:Subdevice:0
// Often simply plug, plughw, plughw:0, will have the same effect 
//
char           *snd_device_in  = "plughw:0,0";
char           *snd_device_out = "plughw:0,0";

// handle constructs to populate with our links
snd_pcm_t      *playback_handle;
snd_pcm_t      *capture_handle;

//this is the usual construct... If not fail BLAH
if ((err = snd_pcm_open(&playback_handle, snd_device_out, SND_PCM_STREAM_PLAYBACK, 0)) < 0) {
fprintf(stderr, "cannot open output audio device %s: %s\n", snd_device_in, snd_strerror(err));
exit(1);
}

// And now the CAPTURE
if ((err = snd_pcm_open(&capture_handle, snd_device_in, SND_PCM_STREAM_CAPTURE, 0)) < 0) {
fprintf(stderr, "cannot open input audio device %s: %s\n", snd_device_out, snd_strerror(err));
exit(1);
}

then config and pump them. 然后配置并泵送它们。

A ring mod could do the job: http://soundprogramming.net/programming_and_apis/creating_a_ring_buffer or you could use alans way outlined above. 一个环mod可以完成这项工作: http ://soundprogramming.net/programming_and_apis/creating_a_ring_buffer或者你可以使用上面概述的alans方式。

It was my first requirements to a Linux/Unix VoIP projects where I need to know about all of the available audio devices capability and name. 这是我对Linux / Unix VoIP项目的第一个要求,我需要了解所有可用的音频设备功能和名称。 Then I need to use these devices to capture and playback the audio. 然后我需要使用这些设备来捕获和播放音频。

For everyone's help I have made a (.so) library and a sample Application demonstrating the use of this library in c++. 为了大家的帮助,我创建了一个(.so)库和一个示例应用程序,演示了如何在c ++中使用这个库。

The output of my library is like- 我的图书馆的输出像 -

[root@~]# ./IdeaAudioEngineTest
HDA Intel plughw:0,0
HDA Intel plughw:0,2
USB Audio Device plughw:1,0

The library provides functionality to capture and playback real-time audio data. 该库提供捕获和回放实时音频数据的功能。

Full source with documentation is available in IdeaAudio library with Duplex Alsa Audio 带有Duplex Alsa Audio的IdeaAudio库中提供了完整的文档源代码

Library source is now open at github.com 库源现已在github.com上开放

See also latency.c , included in alsa-lib source; 另请参见latency.c alsa-lib源中包含的alsa-lib ; on the ALSA wiki: 在ALSA wiki上:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM