home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !SDL / man / SDL_OpenAudio.3 < prev    next >
Encoding:
Text File  |  2006-09-20  |  5.0 KB  |  148 lines

  1. <!-- manual page source format generated by PolyglotMan v3.0.8+X.Org, -->
  2. <!-- available at http://polyglotman.sourceforge.net/ -->
  3.  
  4. <html>
  5. <head>
  6. <title>"SDL_OpenAudio"("3") manual page</title>
  7. </head>
  8. <body bgcolor='#efefef' text='black' link='blue' vlink='#551A8B' alink='red'>
  9. <a href='#toc'>Table of Contents</a><p>
  10.  
  11. <h2><a name='sect0' href='#toc0'>Name</a></h2>
  12. SDL_OpenAudio- Opens the audio device with the desired parameters. 
  13. <h2><a name='sect1' href='#toc1'>Synopsis</a></h2>
  14. <p>
  15. <b>#include
  16. "SDL.h" <p>
  17. </b><b>int <b>SDL_OpenAudio</b></b>(<b>SDL_AudioSpec *desired, SDL_AudioSpec *obtained</b>);
  18.  
  19. <h2><a name='sect2' href='#toc2'>Description</a></h2>
  20. <p>
  21. This function opens the audio device with the <b>desired</b> parameters,
  22. and returns 0 if successful, placing the actual hardware parameters in
  23. the structure pointed to by <b>obtained</b>. If <b>obtained</b> is NULL, the audio data
  24. passed to the callback function will be guaranteed to be in the requested
  25. format, and will be automatically converted to the hardware audio format
  26. if necessary. This function returns -1 if it failed to open the audio device,
  27. or couldn't set up the audio thread. <p>
  28. To open the audio device a <b>desired</b> <i><b>SDL_AudioSpec</b></i>
  29. must be created.  <p>
  30. <br>
  31. <pre>CWSDL_AudioSpec *desired;
  32. .
  33. .
  34. desired=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
  35. </pre><p>
  36.  You must then fill this structure with your desired audio specifications.<br>
  37.  
  38. <dl>
  39.  
  40. <dt><b>desired</b>-><b>freq</b></dt>
  41. <dd></dd>
  42.  
  43. <dt><b>desired</b>-><b>format</b></dt>
  44. <dd></dd>
  45.  
  46. <dt><b>desired</b>-><b>samples</b></dt>
  47. <dd></dd>
  48.  
  49. <dt><b>desired</b>-><b>callback</b></dt>
  50. <dd></dd>
  51. </dl>
  52. <p>
  53. <br>
  54. <pre>CWvoid callback(void *userdata, Uint8 *stream, int len);
  55. </pre><p>
  56.  <b>userdata</b> is the pointer stored in <b>userdata</b> field of the <b>SDL_AudioSpec</b>.
  57. <b>stream</b> is a pointer to the audio buffer you want to fill with information
  58. and <b>len</b> is the length of the audio buffer in bytes.<br>
  59.  
  60. <dl>
  61.  
  62. <dt><b>desired</b>-><b>userdata</b></dt>
  63. <dd></dd>
  64. </dl>
  65. <p>
  66. <b>SDL_OpenAudio</b> reads these fields from the <b>desired</b> <b>SDL_AudioSpec</b>
  67. structure pass to the function and attempts to find an audio configuration
  68. matching your <b>desired</b>. As mentioned above, if the <b>obtained</b> parameter is
  69. <b>NULL</b> then SDL with convert from your <b>desired</b> audio settings to the hardware
  70. settings as it plays. <p>
  71. If <b>obtained</b> is <b>NULL</b> then the <b>desired</b> <b>SDL_AudioSpec</b>
  72. is your working specification, otherwise the <b>obtained</b> <b>SDL_AudioSpec</b> becomes
  73. the working specification and the <b>desirec</b> specification can be deleted.
  74. The data in the working specification is used when building <b>SDL_AudioCVT</b>'s
  75. for converting loaded data to the hardware format. <p>
  76. <b>SDL_OpenAudio</b> calculates
  77. the <b>size</b> and <b>silence</b> fields for both the <b>desired</b> and <b>obtained</b> specifications.
  78. The <b>size</b> field stores the total size of the audio buffer in bytes, while
  79. the <b>silence</b> stores the value used to represent silence in the audio buffer
  80. <p>
  81. The audio device starts out playing <b>silence</b> when it's opened, and should
  82. be enabled for playing by calling <i><b>SDL_PauseAudio</b></i>(<b>0</b>) when you are ready
  83. for your audio <b>callback</b> function to be called. Since the audio driver may
  84. modify the requested <b>size</b> of the audio buffer, you should allocate any
  85. local mixing buffers after you open the audio device. 
  86. <h2><a name='sect3' href='#toc3'>Examples</a></h2>
  87. <p>
  88. <br>
  89. <pre>CW/* Prototype of our callback function */
  90. void my_audio_callback(void *userdata, Uint8 *stream, int len);
  91. /* Open the audio device */
  92. SDL_AudioSpec *desired, *obtained;
  93. SDL_AudioSpec *hardware_spec;
  94. /* Allocate a desired SDL_AudioSpec */
  95. desired=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
  96. /* Allocate space for the obtained SDL_AudioSpec */
  97. obtained=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
  98. /* 22050Hz - FM Radio quality */
  99. desired->freq=22050;
  100. /* 16-bit signed audio */
  101. desired->format=AUDIO_S16LSB;
  102. /* Mono */
  103. desired->channels=0;
  104. /* Large audio buffer reduces risk of dropouts but increases response time
  105. */
  106. desired->samples=8192;
  107. /* Our callback function */
  108. desired->callback=my_audio_callback;
  109. desired->userdata=NULL;
  110. /* Open the audio device */
  111. if ( SDL_OpenAudio(desired, obtained) < 0 ){
  112.   fprintf(stderr, "Couldn't open audio: %s
  113. ", SDL_GetError());
  114.   exit(-1);
  115. }
  116. /* desired spec is no longer needed */
  117. free(desired);
  118. hardware_spec=obtained;
  119. .
  120. .
  121. /* Prepare callback for playing */
  122. .
  123. .
  124. .
  125. /* Start playing */
  126. SDL_PauseAudio(0);
  127. </pre><p>
  128.  
  129. <h2><a name='sect4' href='#toc4'>See Also</a></h2>
  130. <p>
  131. <i><b>SDL_AudioSpec</b></i>, <i><b>SDL_LockAudio</b></i>, <i><b>SDL_UnlockAudio</b></i>, <i><b>SDL_PauseAudio</b></i> 
  132. <!--
  133.   
  134.  
  135. <p>
  136.  
  137. <hr><p>
  138. <a name='toc'><b>Table of Contents</b></a><p>
  139. <ul>
  140. <li><a name='toc0' href='#sect0'>Name</a></li>
  141. <li><a name='toc1' href='#sect1'>Synopsis</a></li>
  142. <li><a name='toc2' href='#sect2'>Description</a></li>
  143. <li><a name='toc3' href='#sect3'>Examples</a></li>
  144. <li><a name='toc4' href='#sect4'>See Also</a></li>
  145. </ul>
  146. </body>
  147. </html>
  148.