sdlOpenAudio function

int sdlOpenAudio(
  1. Pointer<SdlAudioSpec> desired,
  2. Pointer<SdlAudioSpec> obtained
)

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

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:

  • If obtained is NULL, we use desired (and allow no changes), which means desired will be modified to have the correct values for silence, etc, and SDL will convert any differences between your app's specific request and the hardware behind the scenes.
  • The return value is always success or failure, and not a device ID, which means you can only have one device open at a time with this function.

\param desired an SDL_AudioSpec structure representing the desired output format. Please refer to the SDL_OpenAudioDevice documentation for details on how to prepare this structure. \param obtained an SDL_AudioSpec structure filled in with the actual parameters, or NULL. \returns 0 if successful, placing the actual hardware parameters in the structure pointed to by obtained.

If obtained 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 actual hardware audio format if necessary. If obtained is NULL, desired will have fields modified.

This function returns a negative error code on failure to open the audio device or failure to set up the audio thread; call SDL_GetError() for more information.

\since This function is available since SDL 2.0.0.

\sa SDL_CloseAudio \sa SDL_LockAudio \sa SDL_PauseAudio \sa SDL_UnlockAudio

extern DECLSPEC int SDLCALL SDL_OpenAudio(SDL_AudioSpec * desired, SDL_AudioSpec * obtained)

Implementation

int sdlOpenAudio(
    Pointer<SdlAudioSpec> desired, Pointer<SdlAudioSpec> obtained) {
  final sdlOpenAudioLookupFunction = libSdl2.lookupFunction<
      Int32 Function(
          Pointer<SdlAudioSpec> desired, Pointer<SdlAudioSpec> obtained),
      int Function(Pointer<SdlAudioSpec> desired,
          Pointer<SdlAudioSpec> obtained)>('SDL_OpenAudio');
  return sdlOpenAudioLookupFunction(desired, obtained);
}