#define SAMPLE_RATE (44100) static paTestData data; ..... 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*/ if( err != paNoError ) goto error;
The data structure and callback are described in Writing a Callback Function.
The above example opens the stream for writing, which is sufficient for playback. It is also possible to open a stream for reading, to do recording, or both reading and writing, for simultaneous recording and playback or even real-time audio processing. If you plan to do playback and recording at the same time, open only one stream with valid input and output parameters.
There are some caveats to note about simultaneous read/write:
Previous: Initializing PortAudio | Next: Starting, Stopping and Aborting a Stream