Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ALSA:全双工C示例?_C_Linux_Alsa - Fatal编程技术网

ALSA:全双工C示例?

ALSA:全双工C示例?,c,linux,alsa,C,Linux,Alsa,C语言中是否有全双工ALSA连接的示例?我已经读到它是受支持的,但是我看到的所有介绍性示例都记录或播放了一个声音样本,但是我希望有一个处理程序可以为我的VoIP应用程序同时做这两件事 非常感谢你的帮助, Jens有个叫Alan的家伙出版了这本很好(但很旧)的教程,它是用C写的。你提供了一个链接,指向两个手柄,然后依次泵送它们。 这是艾伦的代码被删去并注释 // the device plughw handle dynamic sample rate and type conversion. //

C语言中是否有全双工ALSA连接的示例?我已经读到它是受支持的,但是我看到的所有介绍性示例都记录或播放了一个声音样本,但是我希望有一个处理程序可以为我的VoIP应用程序同时做这两件事

非常感谢你的帮助,
Jens

有个叫Alan的家伙出版了这本很好(但很旧)的教程,它是用C写的。

你提供了一个链接,指向两个手柄,然后依次泵送它们。 这是艾伦的代码被删去并注释

// 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);
}
//设备plughw处理动态采样率和类型转换。
//alsa.conf中定义了一系列备用设备
//尝试:
//找到alsa.conf
//看看里面有什么设备
//  
//以下设备是插件:HW:设备:0:子设备:0
//通常简单的plug,plughw,plughw:0也会有同样的效果
//
char*snd_device_in=“plughw:0,0”;
char*snd_device_out=“plughw:0,0”;
//处理构造以填充链接
snd_pcm_t*回放_手柄;
snd_pcm_t*捕获_手柄;
//这是通常的构造。。。如果不是失败,那就胡说八道
如果((err=snd\u pcm\u open(&playback\u handle,snd\u device\u out,snd\u pcm\u STREAM\u playback,0))<0){
fprintf(标准,“无法打开输出音频设备%s:%s\n”,snd_设备_in,snd_strerror(err));
出口(1);
}
//现在是抓捕
如果((err=snd\u pcm\u open(&capture\u handle,snd\u device\u in,snd\u pcm\u STREAM\u capture,0))<0){
fprintf(标准,“无法打开输入音频设备%s:%s\n”,snd_设备_out,snd_strerror(err));
出口(1);
}
然后配置并泵送它们


ring mod可以完成这项工作:或者您可以使用上面概述的alans方式。

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

对于每个人的帮助,我制作了一个.so库,并演示了一个在C++中使用这个库的示例应用程序。 我的库的输出如下-

[root@~]# ./IdeaAudioEngineTest
HDA Intel plughw:0,0
HDA Intel plughw:0,2
USB Audio Device plughw:1,0
该库提供捕获和回放实时音频数据的功能

完整的源代码和文档可在


库源现在在

打开,另请参见
latency.c
,包含在
alsa库
源中;在ALSA wiki上:


  • 因为我也想知道答案。我还想知道,如果你在ALSA设备上使用OSS api,打开它是否足以实现全双工,或者你是否需要使用丑陋的老式OSS全双工设置
    ioctl
    之类的东西,或者,如果它真的能工作的话……我将在以下位置回答这个问题:尝试提供全双工alsa。具有预定项限制的FIFO堆栈将比环形缓冲区更简单、更安全。不理解下行表决-您链接的示例应根据其文档使用全双工