ALSA:全双工 C 示例?

发布于 2024-10-20 13:38:45 字数 120 浏览 1 评论 0原文

C 语言中有全双工 ALSA 连接的示例吗?我读到它是受支持的,但我看到的所有介绍性示例都要么录制要么播放声音样本,但我希望有一个处理程序可以为我的 VoIP 应用程序执行这两种操作。

非常感谢您的帮助, 延斯

is there an example of a full-duplex ALSA connection in C? 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.

Big thanks for help,
Jens

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

‘画卷フ 2024-10-27 13:38:45

一些名叫 Alan 的人发布了这个很好的(但旧的)教程, 全双工 ALSA,用 C 编写。

Some guy named Alan has published this good (but old) tutorial, Full Duplex ALSA, which is written in C.

满地尘埃落定 2024-10-27 13:38:45

您提供两个手柄的链接并依次泵送它们。
这是艾伦的代码,已被删除和注释。

// 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);
}

然后配置并泵送它们。

环形模组可以完成这项工作: http://soundprogramming.net/programming_and_apis/creating_a_ring_buffer 或者你可以使用上面概述的艾伦方式。

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.

心头的小情儿 2024-10-27 13:38:45

这是我对 Linux/Unix VoIP 项目的第一个要求,我需要了解所有可用的音频设备的功能和名称。然后我需要使用这些设备来捕获和播放音频。

为了大家的帮助,我制作了一个 (.so) 库和一个示例应用程序,演示了在 C++ 中如何使用该库。

我的库的输出就像 -

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

该库提供捕获和播放实时音频数据的功能。

带有文档的完整源代码可在 带有 Duplex Alsa Audio 的 IdeaAudio 库中找到

库源代码现已在 github.com 开放

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. 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++.

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

Library source is now open at github.com

挽心 2024-10-27 13:38:45

另请参阅latency.c,包含在alsa-lib源代码中;在 ALSA wiki 上:

See also latency.c, included in alsa-lib source; on the ALSA wiki:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文