home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue4 / SDL / gcc346 / !SDL / man / SDL_ConvertAudio.3 < prev    next >
Encoding:
Text File  |  2006-09-20  |  4.0 KB  |  118 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_ConvertAudio"("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_ConvertAudio- Convert audio data to a desired audio format. 
  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_ConvertAudio</b></b>(<b>SDL_AudioCVT *cvt</b>); 
  18. <h2><a name='sect2' href='#toc2'>Description</a></h2>
  19. <p>
  20. <b>SDL_ConvertAudio</b>
  21. takes one parameter, <b>cvt</b>, which was previously initilized. Initilizing a
  22. <i><b>SDL_AudioCVT</b></i> is a two step process. First of all, the structure must be
  23. passed to <i><b>SDL_BuildAudioCVT</b></i> along with source and destination format parameters.
  24. Secondly, the <b>cvt</b>-><b>buf</b> and <b>cvt</b>-><b>len</b> fields must be setup. <b>cvt</b>-><b>buf</b> should point
  25. to the audio data and <b>cvt</b>-><b>len</b> should be set to the length of the audio data
  26. in bytes. Remember, the length of the buffer pointed to by <b>buf</b> show be <b>len</b>*<b>len_mult</b>
  27. bytes in length. <p>
  28. Once the <b>SDL_AudioCVT</b>structure is initilized then we can
  29. pass it to <b>SDL_ConvertAudio</b>, which will convert the audio data pointer
  30. to by <b>cvt</b>-><b>buf</b>. If <b>SDL_ConvertAudio</b> returned <b>0</b> then the conversion was completed
  31. successfully, otherwise <b>-1</b> is returned. <p>
  32. If the conversion completed successfully
  33. then the converted audio data can be read from <b>cvt</b>-><b>buf</b>. The amount of valid,
  34. converted, audio data in the buffer is equal to <b>cvt</b>-><b>len</b>*<b>cvt</b>-><b>len_ratio</b>. 
  35. <h2><a name='sect3' href='#toc3'>Examples</a></h2>
  36. <p>
  37. <br>
  38. <pre>CW/* Converting some WAV data to hardware format */
  39. void my_audio_callback(void *userdata, Uint8 *stream, int len);
  40. SDL_AudioSpec *desired, *obtained;
  41. SDL_AudioSpec wav_spec;
  42. SDL_AudioCVT  wav_cvt;
  43. Uint32 wav_len;
  44. Uint8 *wav_buf;
  45. int ret;
  46. /* Allocated audio specs */
  47. desired=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
  48. obtained=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
  49. /* Set desired format */
  50. desired->freq=22050;
  51. desired->format=AUDIO_S16LSB;
  52. desired->samples=8192;
  53. desired->callback=my_audio_callback;
  54. desired->userdata=NULL;
  55. /* Open the audio device */
  56. if ( SDL_OpenAudio(desired, obtained) < 0 ){
  57.   fprintf(stderr, "Couldn't open audio: %s
  58. ", SDL_GetError());
  59.   exit(-1);
  60. }
  61.         
  62. free(desired);
  63. /* Load the test.wav */
  64. if( SDL_LoadWAV("test.wav", &wav_spec, &wav_buf, &wav_len) == NULL ){
  65.   fprintf(stderr, "Could not open test.wav: %s
  66. ", SDL_GetError());
  67.   SDL_CloseAudio();
  68.   free(obtained);
  69.   exit(-1);
  70. }
  71.                                             
  72. /* Build AudioCVT */
  73. ret = SDL_BuildAudioCVT(&wav_cvt,
  74.                         wav_spec.format, wav_spec.channels, wav_spec.freq,
  75.                         obtained->format, obtained->channels, obtained->freq);
  76. /* Check that the convert was built */
  77. if(ret==-1){
  78.   fprintf(stderr, "Couldn't build converter!
  79. ");
  80.   SDL_CloseAudio();
  81.   free(obtained);
  82.   SDL_FreeWAV(wav_buf);
  83. }
  84. /* Setup for conversion */
  85. wav_cvt.buf=(Uint8 *)malloc(wav_len*wav_cvt.len_mult);
  86. wav_cvt.len=wav_len;
  87. memcpy(wav_cvt.buf, wav_buf, wav_len);
  88. /* We can delete to original WAV data now */
  89. SDL_FreeWAV(wav_buf);
  90. /* And now we're ready to convert */
  91. SDL_ConvertAudio(&wav_cvt);
  92. /* do whatever */
  93. .
  94. .
  95. .
  96. .
  97.  
  98. </pre><p>
  99.  
  100. <h2><a name='sect4' href='#toc4'>See Also</a></h2>
  101. <p>
  102. <i><b>SDL_BuildAudioCVT</b></i>, <i><b>SDL_AudioCVT</b></i> 
  103. <!--
  104.   
  105.  <p>
  106.  
  107. <hr><p>
  108. <a name='toc'><b>Table of Contents</b></a><p>
  109. <ul>
  110. <li><a name='toc0' href='#sect0'>Name</a></li>
  111. <li><a name='toc1' href='#sect1'>Synopsis</a></li>
  112. <li><a name='toc2' href='#sect2'>Description</a></li>
  113. <li><a name='toc3' href='#sect3'>Examples</a></li>
  114. <li><a name='toc4' href='#sect4'>See Also</a></li>
  115. </ul>
  116. </body>
  117. </html>
  118.