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
devid | The device. Use SDL_AUDIO_DEVICE_DEFAULT_PLAYBACK for the default output. |
spec | The format of your samples. |
callback | A function that supplies data. Use NULL to add the data yourself. |
userdata | A pointer for your callback, or NULL. |
Return value
A new stream, or NULL on failure.
Example
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
- The device starts paused. Call
SDL_ResumeAudioStreamDevice.
In SDL2
SDL2 has no streams for this. Use SDL_OpenAudioDevice.