This is new wiki software and old wiki content. It's a work in progress!
Here's the explanation.
Be gentle, report bugs, leave feedback on pages, or just edit them yourself! Thanks!

SDL Wiki


This function is a legacy means of opening the audio device.


int SDL_OpenAudio(SDL_AudioSpec * desired,
                  SDL_AudioSpec * obtained);

Function Parameters


an SDL_AudioSpec structure representing the desired output format. Please refer to the SDL_OpenAudioDevice documentation for details on how to prepare this structure.


an SDL_AudioSpec structure filled in with the actual parameters, or NULL.

Return Value

Returns This function opens the audio device with the desired parameters, and returns 0 if successful, placing the actual hardware parameters in the structure pointed to by obtained.


This function remains for compatibility with SDL 1.2, but also because it's slightly easier to use than the new functions in SDL 2.0. The new, more powerful, and preferred way to do this is SDL_OpenAudioDevice().

This function is roughly equivalent to:

[[SDL_OpenAudioDevice]](NULL, 0, desired, obtained, [[SDL_AUDIO_ALLOW_ANY_CHANGE]]);

With two notable exceptions:

Code Examples

SDL_AudioSpec want, have;

SDL_memset(&want, 0, sizeof(want)); /* or SDL_zero(want) */
want.freq = 48000;
want.format = AUDIO_F32;
want.channels = 2;
want.samples = 4096;
want.callback = MyAudioCallback; /* you wrote this function elsewhere -- see SDL_AudioSpec for details */

if (SDL_OpenAudio(&want, &have) < 0) {
    SDL_Log("Failed to open audio: %s", SDL_GetError());
} else {
    if (have.format != want.format) {
        SDL_Log("We didn't get Float32 audio format.");
    SDL_PauseAudio(0); /* start audio playing. */
    SDL_Delay(5000); /* let the audio callback play some sound for 5 seconds. */

CategoryAPI, CategoryAudio

[ edit | delete | history | feedback | raw ]

[ front page | index | search | recent changes | git repo | offline html ]

All wiki content is licensed under Creative Commons Attribution 4.0 International (CC BY 4.0).
Wiki powered by ghwikipp.