如何从 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/
任何非常感谢您的帮助:)
谢谢。
I would like to use PortAudio library to play audio data. This audio data comes from UDP paquets.
I saw there is Pa_OpenDefaultStream() (and Pa_OpenStream() which is pretty similar) function to open a stream :
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*/
I guess I have to use it to play my paquets but I don't know how to use it :
- What is the first parameter ?
- Why do I have to define a call-back function ?
Here is a link to the PortAudio documentation : http://www.portaudio.com/trac/
Any help would be greatly appreciated :)
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
第一个参数是指向 PaStream 类型的输入/输出流的指针。音频数据将从该流读取/写入该流。
您需要编写一个回调函数,PortAudio 库需要在您的 PC 中读取或写入音频时调用该函数。您想要执行的任何其他音频处理(例如 DSP)也将在此处完成。一个简单的回调函数只需将输入复制到输出,以实现流式 I/O。如果您在使用回调时遇到问题,请改用 Blocking API,它可能更容易理解。
编译并运行示例以获取详细信息(例如 patest_read_record.c),那里有很多信息。
The first parameter is a pointer to an input/output stream, of type PaStream. The audio data will be read from / written to this stream.
You need to write a callback function that the PortAudio library will call when it needs to read or write audio to / from your PC. Any other audio processing you want to do (e.g. DSP) will be done here also. A simple callback function would just copy the input to the output, for streaming I/O. If you're having trouble using callbacks, use the Blocking API instead, it may be easier to understand.
Compile and run the examples for details (e.g. patest_read_record.c), theres lots of info there.