| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190 |
- <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
- <meta name="GENERATOR" content="Mozilla/4.75 [en]C-gatewaynet (Win98; U) [Netscape]">
- <meta name="Author" content="Phil Burk">
- <meta name="Description" content="Internal docs. How a stream is started or stopped.">
- <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,">
- <title>PortAudio Implementation - Start/Stop</title>
- </head>
- <body>
-
- <center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" >
- <tr>
- <td>
- <center>
- <h1>
- PortAudio Implementation</h1></center>
- </td>
- </tr>
- </table></center>
- <h2>
- Starting and Stopping Streams</h2>
- PortAudio is generally executed in two "threads". The foreground thread
- is the application thread. The background "thread" may be implemented as
- an actual thread, an interrupt handler, or a callback from a timer thread.
- <p>There are three ways that PortAudio can stop a stream. In each case
- we look at the sequence of events and the messages sent between the two
- threads. The following variables are contained in the internalPortAudioStream.
- <blockquote><tt>int past_IsActive;
- /* Background is still playing. */</tt>
- <br><tt>int past_StopSoon; /* Stop
- when last buffer done. */</tt>
- <br><tt>int past_StopNow; /*
- Stop IMMEDIATELY. */</tt></blockquote>
- <h3>
- Pa_AbortStream()</h3>
- This function causes the background thread to terminate as soon as possible
- and audio I/O to stop abruptly.
- <br>
- <table BORDER COLS=2 WIDTH="60%" >
- <tr>
- <td><b>Foreground Thread</b></td>
- <td><b>Background Thread</b></td>
- </tr>
- <tr>
- <td>sets <tt>StopNow</tt></td>
- <td></td>
- </tr>
- <tr>
- <td></td>
- <td>sees <tt>StopNow</tt>, </td>
- </tr>
- <tr>
- <td></td>
- <td>clears IsActive, stops thread</td>
- </tr>
- <tr>
- <td>waits for thread to exit</td>
- <td></td>
- </tr>
- <tr>
- <td>turns off audio I/O</td>
- <td></td>
- </tr>
- </table>
- <h3>
- Pa_StopStream()</h3>
- This function stops the user callback function from being called and then
- waits for all audio data written to the output buffer to be played. In
- a system with very low latency, you may not hear any difference between
- <br>
- <table BORDER COLS=2 WIDTH="60%" >
- <tr>
- <td><b>Foreground Thread</b></td>
- <td><b>Background Thread</b></td>
- </tr>
- <tr>
- <td>sets StopSoon</td>
- <td></td>
- </tr>
- <tr>
- <td></td>
- <td>stops calling user callback</td>
- </tr>
- <tr>
- <td></td>
- <td>continues until output buffer empty</td>
- </tr>
- <tr>
- <td></td>
- <td>clears IsActive, stops thread</td>
- </tr>
- <tr>
- <td>waits for thread to exit</td>
- <td></td>
- </tr>
- <tr>
- <td>turns off audio I/O</td>
- <td></td>
- </tr>
- </table>
- <h3>
- User callback returns one.</h3>
- If the user callback returns one then the user callback function will no
- longer be called. Audio output will continue until all audio data written
- to the output buffer has been played. Then the audio I/O is stopped, the
- background thread terminates, and the stream becomes inactive.
- <br>
- <table BORDER COLS=2 WIDTH="60%" >
- <tr>
- <td><b>Foreground Thread</b></td>
- <td><b>Background Thread</b></td>
- </tr>
- <tr>
- <td></td>
- <td>callback returns 1</td>
- </tr>
- <tr>
- <td></td>
- <td>sets StopSoon</td>
- </tr>
- <tr>
- <td></td>
- <td>stops calling user callback</td>
- </tr>
- <tr>
- <td></td>
- <td>continues until output buffer empty</td>
- </tr>
- <tr>
- <td></td>
- <td>clears IsActive, stops thread</td>
- </tr>
- <tr>
- <td>waits for thread to exit</td>
- <td></td>
- </tr>
- <tr>
- <td>turns off audio I/O</td>
- <td></td>
- </tr>
- </table>
- <br>
- </body>
- </html>
|