如何从 UPD paquet 打开流?

发布于 2024-10-04 08:56:44 字数 1513 浏览 5 评论 0原文

我想使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦旅人picnic 2024-10-11 08:56:44

第一个参数是指向 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文