pa_impl_guide.html 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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.79 [en] (Windows NT 5.0; 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. <a href="http://www.portaudio.com">PortAudio</a> Implementation Guide</h1></center>
  19. </td>
  20. </tr>
  21. </table></center>
  22. <p>This document describes how to implement the PortAudio API on a new
  23. computer platform. Implementing PortAudio on a new platform, makes it possible
  24. to port many existing audio applications to that platform.
  25. <p>By Phil Burk
  26. <br>Copyright 2000 Phil Burk and Ross Bencina
  27. <p>Note that the license says: <b>"Any person wishing to distribute modifications
  28. to the Software is requested to send the modifications to the original
  29. developer so that they can be incorporated into the canonical version."</b>.
  30. So when you have finished a new implementation, please send it back to
  31. us at&nbsp; "<a href="http://www.portaudio.com">http://www.portaudio.com</a>"
  32. so that we can make it available for other users. Thank you!
  33. <h2>
  34. Download the Latest PortAudio Implementation</h2>
  35. Always start with the latest implementation available at "<a href="http://www.portaudio.com">http://www.portaudio.com</a>".
  36. Look for the nightly snapshot under the CVS section.
  37. <h2>
  38. Select an Existing Implementation as a Basis</h2>
  39. The fastest way to get started is to take an existing implementation and
  40. translate it for your new platform. Choose an implementation whose architecture
  41. is as close as possible to your target.
  42. <ul>
  43. <li>
  44. DirectSound Implementation - pa_win_ds - Uses a timer callback for the
  45. background "thread". Polls a circular buffer and writes blocks of data
  46. to keep it full.</li>
  47. <li>
  48. Windows MME - pa_win_wmme - Spawns an actual Win32 thread. Writes blocks
  49. of data to the HW device and waits for events that signal buffer completion.</li>
  50. <li>
  51. Linux OSS - pa_linux - Spawns a real thread that writes to the "/dev/dsp"
  52. stream using blocking I/O calls.</li>
  53. </ul>
  54. When you write a new implementation, you will be using some code that is
  55. in common with all implementations. This code is in the folder "pa_common".
  56. It provides various functions such as parameter checking, error code to
  57. text conversion, sample format conversion, clipping and dithering, etc.
  58. <p>The code that you write will go into a separate folder called "pa_{os}_{api}".
  59. For example, code specific to the DirectSound interface for Windows goes
  60. in "pa_win_ds".
  61. <h2>
  62. Read Docs and Code</h2>
  63. Famialiarize yourself with the system by reading the documentation provided.
  64. here is a suggested order:
  65. <ol>
  66. <li>
  67. User Programming <a href="pa_tutorial.html">Tutorial</a></li>
  68. <li>
  69. Header file "pa_common/portaudio.h" which defines API.</li>
  70. <li>
  71. Header file "pa_common/pa_host.h" for host dependant code. This definces
  72. the routine you will need to provide.</li>
  73. <li>
  74. Shared code in "pa_common/pa_lib.c".</li>
  75. <li>
  76. Docs on Implementation of <a href="pa_impl_startstop.html">Start/Stop</a>
  77. code.</li>
  78. </ol>
  79. <h2>
  80. Implement&nbsp; Output to Default Device</h2>
  81. Now we are ready to crank some code. For instant gratification, let's try
  82. to play a sine wave.
  83. <ol>
  84. <li>
  85. Link the test program "pa_tests/patest_sine.c" with the file "pa_lib.c"
  86. and the implementation specific file you are creating.</li>
  87. <li>
  88. For now, just stub out the device query code and the audio input code.</li>
  89. <li>
  90. Modify PaHost_OpenStream() to open your default target device and get everything
  91. setup.</li>
  92. <li>
  93. Modify PaHost_StartOutput() to start playing audio.</li>
  94. <li>
  95. Modify PaHost_StopOutput() to stop audio.</li>
  96. <li>
  97. Modify PaHost_CloseStream() to clean up. Free all memory that you allocated
  98. in PaHost_OpenStream().</li>
  99. <li>
  100. Keep cranking until you can play a sine wave using "patest_sine.c".</li>
  101. <li>
  102. Once that works, try "patest_pink.c", "patest_clip.c", "patest_sine8.c".</li>
  103. <li>
  104. To test your Open and Close code, try "patest_many.c".</li>
  105. <li>
  106. Now test to make sure that the three modes of stopping are properly supported
  107. by running "patest_stop.c".</li>
  108. <li>
  109. Test your implementation of time stamping with "patest_sync.c".</li>
  110. </ol>
  111. <h2>
  112. Implement Device Queries</h2>
  113. Now that output is working, lets implement the code for querying what devices
  114. are available to the user. Run "pa_tests/pa_devs.c". It should print all
  115. of the devices available and their characteristics.
  116. <h2>
  117. Implement Input</h2>
  118. Implement audio input and test it with:
  119. <ol>
  120. <li>
  121. patest_record.c - record in half duplex, play back as recorded.</li>
  122. <li>
  123. patest_wire.c - full duplex, copies input to output. Note that some HW
  124. may not support full duplex.</li>
  125. <li>
  126. patest_fuzz.c - plug in your guitar and get a feel for why latency is an
  127. important issue in computer music.</li>
  128. <li>
  129. paqa_devs.c - try to open every device and use it with every possible format</li>
  130. </ol>
  131. <h2>
  132. Debugging Tools</h2>
  133. You generally cannot use printf() calls to debug real-time processes because
  134. they disturb the timing. Also calling printf() from your background thread
  135. or interrupt could crash the machine. So PA includes a tool for capturing
  136. events and storing the information while it is running. It then prints
  137. the events when Pa_Terminate() is called.
  138. <ol>
  139. <li>
  140. To enable trace mode, change TRACE_REALTIME_EVENTS in "pa_common/pa_trace.h"
  141. from a (0) to a (1).</li>
  142. <li>
  143. Link with "pa_common/pa_trace.c".</li>
  144. <li>
  145. Add trace messages to your code by calling:</li>
  146. <br><tt>&nbsp;&nbsp; void AddTraceMessage( char *msg, int data );</tt>
  147. <br><tt>for example</tt>
  148. <br><tt>&nbsp;&nbsp; AddTraceMessage("Pa_TimeSlice: past_NumCallbacks ",
  149. past->past_NumCallbacks );</tt>
  150. <li>
  151. Run your program. You will get a dump of events at the end.</li>
  152. <li>
  153. You can leave the trace messages in your code. They will turn to NOOPs
  154. when you change TRACE_REALTIME_EVENTS back to (0).</li>
  155. </ol>
  156. <h2>
  157. Delivery</h2>
  158. Please send your new code along with notes on the implementation back to
  159. us at "<a href="http://www.portaudio.com">http://www.portaudio.com</a>".
  160. We will review the implementation and post it with your name. If you had
  161. to make any modifications to the code in "pa_common" or "pa_tests" <b>please</b>
  162. send us those modifications and your notes. We will try to merge your changes
  163. so that the "pa_common" code works with <b>all</b> implementations.
  164. <p>If you have suggestions for how to make future implementations easier,
  165. please let us know.
  166. <br>THANKS!
  167. <br>&nbsp;
  168. </body>
  169. </html>
粤ICP备19079148号