如何从 UPD paquet 打开流?
题
我想使用 PortAudio 库来播放音频数据。该音频数据来自 UDP 包。
我看到有 Pa_OpenDefaultStream() (和 Pa_OpenStream() 非常相似)函数来打开流:
PaStream *stream;
PaError err;
/* Open an audio I/O stream. */
err = Pa_OpenDefaultStream( &stream,
0, /* no input channels */
2, /* stereo output */
paFloat32, /* 32 bit floating point output */
SAMPLE_RATE,
256, /* frames per buffer, i.e. the number
of sample frames that PortAudio will
request from the callback. Many apps
may want to use
paFramesPerBufferUnspecified, which
tells PortAudio to pick the best,
possibly changing, buffer size.*/
patestCallback, /* this is your callback function */
&data ); /*This is a pointer that will be passed to
your callback*/
我想我必须用它来玩我的 paquets,但我不知道如何使用它:
- 第一个参数是什么?
- 为什么我必须定义回调函数?
以下是 PortAudio 文档的链接: http://www.portaudio.com/trac/
任何帮助将不胜感激 :)
谢谢。
解决方案
第一个参数是指向 PaStream 类型的输入/输出流的指针。音频数据将从该流读取/写入该流。
您需要编写一个回调函数,PortAudio 库需要在您的 PC 中读取或写入音频时调用该函数。您想要执行的任何其他音频处理(例如DSP)也将在这里完成。一个简单的回调函数只需将输入复制到输出,以实现流式 I/O。如果您在使用回调时遇到问题,请改用 Blocking API,它可能更容易理解。
编译并运行示例以获取详细信息(例如patest_read_record.c),那里有很多信息。
不隶属于 StackOverflow