PortAudio Tutorial

Starting and Stopping a Stream

The stream will not start running until you call Pa_StartStream(). Then it will start calling your callback function to perform the audio processing.
err = Pa_StartStream( stream );
if( err != paNoError ) goto error;
At this point, audio is being generated. You can communicate to your callback routine through the data structure you passed in on the open call, or through global variables, or using other interprocess communication techniques. Please be aware that your callback function may be called at interrupt time when your foreground process is least expecting it. So avoid sharing complex data structures that are easily corrupted like double linked lists.

In many of the tests we simply sleep for a few seconds so we can hear the sound. This is easy to do with Pa_Sleep() which will sleep for some number of milliseconds. Do not rely on this function for accurate scheduling. it is mostly for writing examples.

/* Sleep for several seconds. */
Pa_Sleep(NUM_SECONDS*1000);
When you are through, you can stop the stream from the foreground.
err = Pa_StopStream( stream );
if( err != paNoError ) goto error;
You can also stop the stream by returning 1 from your custom callback function.
home | contents | previousnext