How to open a stream from UPD paquets?
Question
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.
Solution
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.