home *** CD-ROM | disk | FTP | other *** search
- <!-- manual page source format generated by PolyglotMan v3.0.8+X.Org, -->
- <!-- available at http://polyglotman.sourceforge.net/ -->
-
- <html>
- <head>
- <title>"SDL_ConvertAudio"("3") manual page</title>
- </head>
- <body bgcolor='#efefef' text='black' link='blue' vlink='#551A8B' alink='red'>
- <a href='#toc'>Table of Contents</a><p>
-
- <h2><a name='sect0' href='#toc0'>Name</a></h2>
- SDL_ConvertAudio- Convert audio data to a desired audio format.
- <h2><a name='sect1' href='#toc1'>Synopsis</a></h2>
- <p>
- <b>#include
- "SDL.h" <p>
- </b><b>int <b>SDL_ConvertAudio</b></b>(<b>SDL_AudioCVT *cvt</b>);
- <h2><a name='sect2' href='#toc2'>Description</a></h2>
- <p>
- <b>SDL_ConvertAudio</b>
- takes one parameter, <b>cvt</b>, which was previously initilized. Initilizing a
- <i><b>SDL_AudioCVT</b></i> is a two step process. First of all, the structure must be
- passed to <i><b>SDL_BuildAudioCVT</b></i> along with source and destination format parameters.
- 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
- to the audio data and <b>cvt</b>-><b>len</b> should be set to the length of the audio data
- in bytes. Remember, the length of the buffer pointed to by <b>buf</b> show be <b>len</b>*<b>len_mult</b>
- bytes in length. <p>
- Once the <b>SDL_AudioCVT</b>structure is initilized then we can
- pass it to <b>SDL_ConvertAudio</b>, which will convert the audio data pointer
- to by <b>cvt</b>-><b>buf</b>. If <b>SDL_ConvertAudio</b> returned <b>0</b> then the conversion was completed
- successfully, otherwise <b>-1</b> is returned. <p>
- If the conversion completed successfully
- then the converted audio data can be read from <b>cvt</b>-><b>buf</b>. The amount of valid,
- converted, audio data in the buffer is equal to <b>cvt</b>-><b>len</b>*<b>cvt</b>-><b>len_ratio</b>.
- <h2><a name='sect3' href='#toc3'>Examples</a></h2>
- <p>
- <br>
- <pre>CW/* Converting some WAV data to hardware format */
- void my_audio_callback(void *userdata, Uint8 *stream, int len);
- SDL_AudioSpec *desired, *obtained;
- SDL_AudioSpec wav_spec;
- SDL_AudioCVT wav_cvt;
- Uint32 wav_len;
- Uint8 *wav_buf;
- int ret;
- /* Allocated audio specs */
- desired=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
- obtained=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
- /* Set desired format */
- desired->freq=22050;
- desired->format=AUDIO_S16LSB;
- desired->samples=8192;
- desired->callback=my_audio_callback;
- desired->userdata=NULL;
- /* Open the audio device */
- if ( SDL_OpenAudio(desired, obtained) < 0 ){
- fprintf(stderr, "Couldn't open audio: %s
- ", SDL_GetError());
- exit(-1);
- }
-
- free(desired);
- /* Load the test.wav */
- if( SDL_LoadWAV("test.wav", &wav_spec, &wav_buf, &wav_len) == NULL ){
- fprintf(stderr, "Could not open test.wav: %s
- ", SDL_GetError());
- SDL_CloseAudio();
- free(obtained);
- exit(-1);
- }
-
- /* Build AudioCVT */
- ret = SDL_BuildAudioCVT(&wav_cvt,
- wav_spec.format, wav_spec.channels, wav_spec.freq,
- obtained->format, obtained->channels, obtained->freq);
- /* Check that the convert was built */
- if(ret==-1){
- fprintf(stderr, "Couldn't build converter!
- ");
- SDL_CloseAudio();
- free(obtained);
- SDL_FreeWAV(wav_buf);
- }
- /* Setup for conversion */
- wav_cvt.buf=(Uint8 *)malloc(wav_len*wav_cvt.len_mult);
- wav_cvt.len=wav_len;
- memcpy(wav_cvt.buf, wav_buf, wav_len);
- /* We can delete to original WAV data now */
- SDL_FreeWAV(wav_buf);
- /* And now we're ready to convert */
- SDL_ConvertAudio(&wav_cvt);
- /* do whatever */
- .
- .
- .
- .
-
- </pre><p>
-
- <h2><a name='sect4' href='#toc4'>See Also</a></h2>
- <p>
- <i><b>SDL_BuildAudioCVT</b></i>, <i><b>SDL_AudioCVT</b></i>
- <!--
-
- <p>
-
- <hr><p>
- <a name='toc'><b>Table of Contents</b></a><p>
- <ul>
- <li><a name='toc0' href='#sect0'>Name</a></li>
- <li><a name='toc1' href='#sect1'>Synopsis</a></li>
- <li><a name='toc2' href='#sect2'>Description</a></li>
- <li><a name='toc3' href='#sect3'>Examples</a></li>
- <li><a name='toc4' href='#sect4'>See Also</a></li>
- </ul>
- </body>
- </html>
-