2011-03-02 98 views
9

有沒有在C中的全雙工ALSA連接的例子?我讀過它支持,但我看到的所有介紹性示例都記錄或播放聲音樣本,但我希望有一個處理程序可以爲我的VoIP應用程序執行這兩個操作。ALSA:全雙工C示例?

大感謝您的幫助, 延

+2

1,因爲我想知道答案了。我也有興趣知道,如果你使用OSS api作爲ALSA設備,無論打開它'O_RDWR'是否足以獲得全雙工,或者如果你需要使用醜陋的舊式OSS全雙工設置' ioctl的東西,或者它甚至可以工作...... – 2011-03-03 00:57:43

回答

4

名叫小李有些傢伙已經公佈這個好(但舊)的教程,Full Duplex ALSA,這是寫在C.

2

您提供一個鏈接到兩個手柄和泵他們反過來。 這裏是阿蘭的代碼消除和評論。

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

然後配置並泵送它們。

一個mod mod可以完成這項工作:http://soundprogramming.net/programming_and_apis/creating_a_ring_buffer或者你可以使用上面列出的alans方式。

+1

帶有一些預定項目限制的FIFO堆棧比環形緩衝區更簡單和更安全。 – slashmais 2015-08-28 08:30:29

2

這是我第一次需要了解所有可用音頻設備功能和名稱的Linux/Unix VoIP項目。然後我需要使用這些設備來捕捉和播放音頻。

爲了大家的幫助,我製作了一個(.so)庫和一個示例應用程序,演示瞭如何在C++中使用此庫。

我的媒體庫的輸出是喜歡 -

[[email protected]~]# ./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