mirror of
https://github.com/libsdl-org/SDL.git
synced 2025-06-04 02:47:39 +00:00
audio: Replace SDL_CreateAndBindAudioStream with SDL_OpenAudioDeviceStream.
This is meant to offer a simplified API for people that are either migrating directly from SDL2 with minimal effort or just want to make noise without any of the fancy new API features. Users of this API can just deal with a single SDL_AudioStream as their only object/handle into the audio subsystem. They are still allowed to open multiple devices (or open the same device multiple times), but cannot change stream bindings on logical devices opened through this function. Destroying the single audio stream will also close the logical device behind the scenes.
This commit is contained in:
parent
bd088c2f99
commit
1e775e0eef
13 changed files with 164 additions and 137 deletions
|
@ -34,7 +34,6 @@ static struct
|
|||
Uint32 soundpos;
|
||||
} wave;
|
||||
|
||||
static SDL_AudioDeviceID device;
|
||||
static SDL_AudioStream *stream;
|
||||
|
||||
static void fillerup(void)
|
||||
|
@ -58,30 +57,22 @@ quit(int rc)
|
|||
static void
|
||||
close_audio(void)
|
||||
{
|
||||
if (device != 0) {
|
||||
if (stream) {
|
||||
SDL_DestroyAudioStream(stream);
|
||||
stream = NULL;
|
||||
SDL_CloseAudioDevice(device);
|
||||
device = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
open_audio(void)
|
||||
{
|
||||
device = SDL_OpenAudioDevice(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec);
|
||||
if (!device) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't open audio: %s\n", SDL_GetError());
|
||||
SDL_free(wave.sound);
|
||||
quit(2);
|
||||
}
|
||||
stream = SDL_CreateAndBindAudioStream(device, &wave.spec);
|
||||
stream = SDL_OpenAudioDeviceStream(SDL_AUDIO_DEVICE_DEFAULT_OUTPUT, &wave.spec, NULL, NULL);
|
||||
if (!stream) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create audio stream: %s\n", SDL_GetError());
|
||||
SDL_CloseAudioDevice(device);
|
||||
SDL_free(wave.sound);
|
||||
quit(2);
|
||||
}
|
||||
SDL_ResumeAudioDevice(SDL_GetAudioStreamBinding(stream));
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue