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_OpenAudio"("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_OpenAudio- Opens the audio device with the desired parameters.
- <h2><a name='sect1' href='#toc1'>Synopsis</a></h2>
- <p>
- <b>#include
- "SDL.h" <p>
- </b><b>int <b>SDL_OpenAudio</b></b>(<b>SDL_AudioSpec *desired, SDL_AudioSpec *obtained</b>);
-
- <h2><a name='sect2' href='#toc2'>Description</a></h2>
- <p>
- This function opens the audio device with the <b>desired</b> parameters,
- and returns 0 if successful, placing the actual hardware parameters in
- the structure pointed to by <b>obtained</b>. If <b>obtained</b> is NULL, the audio data
- passed to the callback function will be guaranteed to be in the requested
- format, and will be automatically converted to the hardware audio format
- if necessary. This function returns -1 if it failed to open the audio device,
- or couldn't set up the audio thread. <p>
- To open the audio device a <b>desired</b> <i><b>SDL_AudioSpec</b></i>
- must be created. <p>
- <br>
- <pre>CWSDL_AudioSpec *desired;
- .
- .
- desired=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
- </pre><p>
- You must then fill this structure with your desired audio specifications.<br>
-
- <dl>
-
- <dt><b>desired</b>-><b>freq</b></dt>
- <dd></dd>
-
- <dt><b>desired</b>-><b>format</b></dt>
- <dd></dd>
-
- <dt><b>desired</b>-><b>samples</b></dt>
- <dd></dd>
-
- <dt><b>desired</b>-><b>callback</b></dt>
- <dd></dd>
- </dl>
- <p>
- <br>
- <pre>CWvoid callback(void *userdata, Uint8 *stream, int len);
- </pre><p>
- <b>userdata</b> is the pointer stored in <b>userdata</b> field of the <b>SDL_AudioSpec</b>.
- <b>stream</b> is a pointer to the audio buffer you want to fill with information
- and <b>len</b> is the length of the audio buffer in bytes.<br>
-
- <dl>
-
- <dt><b>desired</b>-><b>userdata</b></dt>
- <dd></dd>
- </dl>
- <p>
- <b>SDL_OpenAudio</b> reads these fields from the <b>desired</b> <b>SDL_AudioSpec</b>
- structure pass to the function and attempts to find an audio configuration
- matching your <b>desired</b>. As mentioned above, if the <b>obtained</b> parameter is
- <b>NULL</b> then SDL with convert from your <b>desired</b> audio settings to the hardware
- settings as it plays. <p>
- If <b>obtained</b> is <b>NULL</b> then the <b>desired</b> <b>SDL_AudioSpec</b>
- is your working specification, otherwise the <b>obtained</b> <b>SDL_AudioSpec</b> becomes
- the working specification and the <b>desirec</b> specification can be deleted.
- The data in the working specification is used when building <b>SDL_AudioCVT</b>'s
- for converting loaded data to the hardware format. <p>
- <b>SDL_OpenAudio</b> calculates
- the <b>size</b> and <b>silence</b> fields for both the <b>desired</b> and <b>obtained</b> specifications.
- The <b>size</b> field stores the total size of the audio buffer in bytes, while
- the <b>silence</b> stores the value used to represent silence in the audio buffer
- <p>
- The audio device starts out playing <b>silence</b> when it's opened, and should
- be enabled for playing by calling <i><b>SDL_PauseAudio</b></i>(<b>0</b>) when you are ready
- for your audio <b>callback</b> function to be called. Since the audio driver may
- modify the requested <b>size</b> of the audio buffer, you should allocate any
- local mixing buffers after you open the audio device.
- <h2><a name='sect3' href='#toc3'>Examples</a></h2>
- <p>
- <br>
- <pre>CW/* Prototype of our callback function */
- void my_audio_callback(void *userdata, Uint8 *stream, int len);
- /* Open the audio device */
- SDL_AudioSpec *desired, *obtained;
- SDL_AudioSpec *hardware_spec;
- /* Allocate a desired SDL_AudioSpec */
- desired=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
- /* Allocate space for the obtained SDL_AudioSpec */
- obtained=(SDL_AudioSpec *)malloc(sizeof(SDL_AudioSpec));
- /* 22050Hz - FM Radio quality */
- desired->freq=22050;
- /* 16-bit signed audio */
- desired->format=AUDIO_S16LSB;
- /* Mono */
- desired->channels=0;
- /* Large audio buffer reduces risk of dropouts but increases response time
- */
- desired->samples=8192;
- /* Our callback function */
- 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);
- }
- /* desired spec is no longer needed */
- free(desired);
- hardware_spec=obtained;
- .
- .
- /* Prepare callback for playing */
- .
- .
- .
- /* Start playing */
- SDL_PauseAudio(0);
- </pre><p>
-
- <h2><a name='sect4' href='#toc4'>See Also</a></h2>
- <p>
- <i><b>SDL_AudioSpec</b></i>, <i><b>SDL_LockAudio</b></i>, <i><b>SDL_UnlockAudio</b></i>, <i><b>SDL_PauseAudio</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>
-