0

我想使用 PortAudio 库来播放音频数据。此音频数据来自 UDP paquets。

我看到有 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/

任何帮助将不胜感激 :)

谢谢。

4

1 回答 1

1

第一个参数是指向PaStream 类型的输入/输出流的指针。音频数据将从该流中读取/写入。

您需要编写一个回调函数,当 PortAudio 库需要从您的 PC 读取或写入音频时,它将调用该回调函数。您想要进行的任何其他音频处理(例如 DSP)也将在此处完成。一个简单的回调函数只是将输入复制到输出,用于流式 I/O。如果您在使用回调时遇到问题,请改用 Blocking API,它可能更容易理解。

编译并运行示例以获取详细信息(例如 patest_read_record.c),那里有很多信息。

于 2010-11-22T03:45:13.610 回答