gearmulator

Emulation of classic VA synths of the late 90s/2000s that are based on Motorola 56300 family DSPs
Log | Files | Refs | Submodules | README | LICENSE

start_stop_abort.dox (2589B)


      1 /** @page start_stop_abort Starting, Stopping and Aborting a Stream
      2 @ingroup tutorial
      3 
      4 @section tut_startstop1 Starting, Stopping and Aborting a Stream
      5 
      6 PortAudio will not start playing back audio until you start the stream. After calling Pa_StartStream(), PortAudio will start calling your callback function to perform the audio processing.
      7 
      8 @code
      9     err = Pa_StartStream( stream );
     10     if( err != paNoError ) goto error;
     11 @endcode
     12 
     13 You can communicate with your callback routine through the data structure you passed in on the open call, or through global variables, or using other interprocess communication techniques, but 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, and avoid using locks such as mutexs as this may cause your callback function to block and therefore drop audio. Such techniques may even cause deadlock on some platforms.
     14 
     15 PortAudio will continue to call your callback and process audio until you stop the stream. This can be done in one of several ways, but, before we do so, we'll want to see that some of our audio gets processed by sleeping for a few seconds. This is easy to do with Pa_Sleep(), which is used by many of the examples in the patests/ directory for exactly this purpose. Note that, for a variety of reasons, you can not rely on this function for accurate scheduling, so your stream may not run for exactly the same amount of time as you expect, but it's good enough for our example.
     16 
     17 @code
     18     /* Sleep for several seconds. */
     19     Pa_Sleep(NUM_SECONDS*1000);
     20 @endcode
     21 
     22 Now we need to stop playback. There are several ways to do this, the simplest of which is to call Pa_StopStream():
     23 
     24 @code
     25     err = Pa_StopStream( stream );
     26     if( err != paNoError ) goto error;
     27 @endcode
     28 
     29 Pa_StopStream() is designed to make sure that the buffers you've processed in your callback are all played, which may cause some delay. Alternatively, you could call Pa_AbortStream(). On some platforms, aborting the stream is much faster and may cause some data processed by your callback not to be played.
     30 
     31 Another way to stop the stream is to return either paComplete, or paAbort from your callback. paComplete ensures that the last buffer is played whereas paAbort stops the stream as soon as possible. If you stop the stream using this technique, you will need to call Pa_StopStream() before starting the stream again.
     32 
     33 Previous: \ref open_default_stream | Next: \ref terminating_portaudio
     34 
     35 */