16#include <SDL3/SDL_audio.h>
17#include <SDL3/SDL_init.h>
32void SDLCALL
FillAudioStream(
void *, SDL_AudioStream *stream,
int bytes_requested,
int)
34 if (bytes_requested <= 0)
return;
36 Uint8 *data = SDL_stack_alloc(Uint8, bytes_requested);
37 if (data ==
nullptr)
return;
39 MxMixSamples(data, bytes_requested / 4);
40 SDL_PutAudioStreamData(stream, data, bytes_requested);
48 if (!SDL_WasInit(SDL_INIT_VIDEO)) {
49 success = SDL_Init(SDL_INIT_AUDIO);
50 }
else if (!SDL_WasInit(SDL_INIT_AUDIO)) {
51 success = SDL_InitSubSystem(SDL_INIT_AUDIO);
53 if (!success)
return SDL_GetError();
55 const SDL_AudioSpec spec{ SDL_AUDIO_S16, 2,
GetDriverParamInt(parm,
"hz", 44100) };
60 MxInitialize(spec.freq);
62 if (!SDL_ResumeAudioDevice(SDL_GetAudioStreamDevice(
_sdl_audio_stream)))
return SDL_GetError();
74 SDL_QuitSubSystem(SDL_INIT_AUDIO);
75 if (!SDL_WasInit(SDL_INIT_VIDEO)) {
Factory for the SDL sound driver.
std::optional< std::string_view > Start(const StringList ¶m) override
Start this driver.
void Stop() override
Stop this driver.
int GetDriverParamInt(const StringList &parm, std::string_view name, int def)
Get an integer parameter the list of parameters.
Functions to mix sound samples.
A number of safeguards to prevent using unsafe methods.
static SDL_AudioStream * _sdl_audio_stream
SDL audio stream.
static FSoundDriver_SDL iFSoundDriver_SDL
Factory for the SDL sound driver.
void FillAudioStream(void *, SDL_AudioStream *stream, int bytes_requested, int)
Callback that fills the sound buffer.
Base for playing sound via SDL.
Definition of base types and functions in a cross-platform compatible way.
std::vector< std::string > StringList
Type for a list of strings.