SDL School

API reference / Audio

SDL_OpenAudioDeviceStream

Function, SDL3

Opens an audio device and gives you a stream that is connected to it. A stream is a queue for samples that also converts their format.

Declaration

#include <SDL3/SDL.h>

SDL_AudioStream * SDL_OpenAudioDeviceStream(SDL_AudioDeviceID devid, const SDL_AudioSpec *spec, SDL_AudioStreamCallback callback, void *userdata);

Parameters

devidThe device. Use SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for the default output.
specThe format of your samples.
callbackA function that supplies data. Use NULL to add the data yourself.
userdataA pointer for your callback, or NULL.

Return value

A new stream, or NULL on failure.

Example

Play a sound
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK, &spec, NULL, NULL);

See this code run in Play a sound. Download the full program (.zip)

Notes

In SDL2

SDL2 has no streams for this. Use SDL_OpenAudioDevice.

See also