pa_impl_startstop.html 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <!doctype html public "-//w3c//dtd html 4.0 transitional//en">
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  5. <meta name="GENERATOR" content="Mozilla/4.75 [en]C-gatewaynet (Win98; U) [Netscape]">
  6. <meta name="Author" content="Phil Burk">
  7. <meta name="Description" content="Internal docs. How a stream is started or stopped.">
  8. <meta name="KeyWords" content="audio, tutorial, library, portable, open-source, DirectSound,sound, music, JSyn, synthesis,">
  9. <title>PortAudio Implementation - Start/Stop</title>
  10. </head>
  11. <body>
  12. &nbsp;
  13. <center><table COLS=1 WIDTH="100%" BGCOLOR="#FADA7A" >
  14. <tr>
  15. <td>
  16. <center>
  17. <h1>
  18. PortAudio Implementation</h1></center>
  19. </td>
  20. </tr>
  21. </table></center>
  22. <h2>
  23. Starting and Stopping Streams</h2>
  24. PortAudio is generally executed in two "threads". The foreground thread
  25. is the application thread. The background "thread" may be implemented as
  26. an actual thread, an interrupt handler, or a callback from a timer thread.
  27. <p>There are three ways that PortAudio can stop a stream. In each case
  28. we look at the sequence of events and the messages sent between the two
  29. threads. The following variables are contained in the internalPortAudioStream.
  30. <blockquote><tt>int&nbsp;&nbsp; past_IsActive;&nbsp;&nbsp;&nbsp;&nbsp;
  31. /* Background is still playing. */</tt>
  32. <br><tt>int&nbsp;&nbsp; past_StopSoon;&nbsp;&nbsp;&nbsp;&nbsp; /* Stop
  33. when last buffer done. */</tt>
  34. <br><tt>int&nbsp;&nbsp; past_StopNow;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; /*
  35. Stop IMMEDIATELY. */</tt></blockquote>
  36. <h3>
  37. Pa_AbortStream()</h3>
  38. This function causes the background thread to terminate as soon as possible
  39. and audio I/O to stop abruptly.
  40. <br>&nbsp;
  41. <table BORDER COLS=2 WIDTH="60%" >
  42. <tr>
  43. <td><b>Foreground Thread</b></td>
  44. <td><b>Background Thread</b></td>
  45. </tr>
  46. <tr>
  47. <td>sets <tt>StopNow</tt></td>
  48. <td></td>
  49. </tr>
  50. <tr>
  51. <td></td>
  52. <td>sees <tt>StopNow</tt>,&nbsp;</td>
  53. </tr>
  54. <tr>
  55. <td></td>
  56. <td>clears IsActive, stops thread</td>
  57. </tr>
  58. <tr>
  59. <td>waits for thread to exit</td>
  60. <td></td>
  61. </tr>
  62. <tr>
  63. <td>turns off audio I/O</td>
  64. <td></td>
  65. </tr>
  66. </table>
  67. <h3>
  68. Pa_StopStream()</h3>
  69. This function stops the user callback function from being called and then
  70. waits for all audio data written to the output buffer to be played. In
  71. a system with very low latency, you may not hear any difference between
  72. <br>&nbsp;
  73. <table BORDER COLS=2 WIDTH="60%" >
  74. <tr>
  75. <td><b>Foreground Thread</b></td>
  76. <td><b>Background Thread</b></td>
  77. </tr>
  78. <tr>
  79. <td>sets StopSoon</td>
  80. <td></td>
  81. </tr>
  82. <tr>
  83. <td></td>
  84. <td>stops calling user callback</td>
  85. </tr>
  86. <tr>
  87. <td></td>
  88. <td>continues until output buffer empty</td>
  89. </tr>
  90. <tr>
  91. <td></td>
  92. <td>clears IsActive, stops thread</td>
  93. </tr>
  94. <tr>
  95. <td>waits for thread to exit</td>
  96. <td></td>
  97. </tr>
  98. <tr>
  99. <td>turns off audio I/O</td>
  100. <td></td>
  101. </tr>
  102. </table>
  103. <h3>
  104. User callback returns one.</h3>
  105. If the user callback returns one then the user callback function will no
  106. longer be called. Audio output will continue until all audio data written
  107. to the output buffer has been played. Then the audio I/O is stopped, the
  108. background thread terminates, and the stream becomes inactive.
  109. <br>&nbsp;
  110. <table BORDER COLS=2 WIDTH="60%" >
  111. <tr>
  112. <td><b>Foreground Thread</b></td>
  113. <td><b>Background Thread</b></td>
  114. </tr>
  115. <tr>
  116. <td></td>
  117. <td>callback returns 1</td>
  118. </tr>
  119. <tr>
  120. <td></td>
  121. <td>sets StopSoon</td>
  122. </tr>
  123. <tr>
  124. <td></td>
  125. <td>stops calling user callback</td>
  126. </tr>
  127. <tr>
  128. <td></td>
  129. <td>continues until output buffer empty</td>
  130. </tr>
  131. <tr>
  132. <td></td>
  133. <td>clears IsActive, stops thread</td>
  134. </tr>
  135. <tr>
  136. <td>waits for thread to exit</td>
  137. <td></td>
  138. </tr>
  139. <tr>
  140. <td>turns off audio I/O</td>
  141. <td></td>
  142. </tr>
  143. </table>
  144. <br>&nbsp;
  145. </body>
  146. </html>
粤ICP备19079148号