C での全二重 ALSA 接続の例はありますか? サポートされていることを読みましたが、私が見たすべての紹介例はサウンド サンプルの録音または再生のいずれかでしたが、VoIP アプリで両方を実行できる 1 つのハンドラーが必要です。
助けてくれてありがとう、イェンス
Alan という名前の人が、C で書かれたこの優れた (しかし古い) チュートリアル、 Full Duplex ALSAを公開しています。
両方のハンドルへのリンクを提供し、それらを順番にポンピングします。これは alan のコードを省略してコメントしたものです。
// 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 は、仕事を行うことができます: http://soundprogramming.net/programming_and_apis/creating_a_ring_bufferまたは、上で概説した alans の方法を使用できます。
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で公開されました