有没有一个用C语言实现全双工ALSA连接的例子?我已经了解到它是被支持的,但是我看到的所有介绍性例子都只是录制或播放声音样本,而我想要一个可以处理我的VoIP应用程序中的录制和播放两个功能的处理器。
非常感谢帮助, Jens
有没有一个用C语言实现全双工ALSA连接的例子?我已经了解到它是被支持的,但是我看到的所有介绍性例子都只是录制或播放声音样本,而我想要一个可以处理我的VoIP应用程序中的录制和播放两个功能的处理器。
非常感谢帮助, Jens
// 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);
}
[root@~]# ./IdeaAudioEngineTest
HDA Intel plughw:0,0
HDA Intel plughw:0,2
USB Audio Device plughw:1,0
该库提供了捕获和播放实时音频数据的功能。
完整的源代码和文档可以在IdeaAudio library with Duplex Alsa Audio中找到。
该库的源代码现在已经在github.com开源。
请参考 alsa-lib
源码中包含的 latency.c
,以及 ALSA 维基页面: