make audio device init delayed until first use
This commit is contained in:
@ -247,6 +247,35 @@ void audio_play(const char *path,
|
||||
float volume,
|
||||
float panning)
|
||||
{
|
||||
if (!ctx.audio_initialized) {
|
||||
profile_start("audio initialization");
|
||||
|
||||
SDL_AudioSpec request, got;
|
||||
SDL_zero(request);
|
||||
|
||||
request.freq = AUDIO_FREQUENCY;
|
||||
request.format = AUDIO_F32;
|
||||
request.channels = 2;
|
||||
#ifndef TWN_FEATURE_PUSH_AUDIO
|
||||
request.callback = audio_callback;
|
||||
#endif
|
||||
/* TODO: check for errors */
|
||||
ctx.audio_device = SDL_OpenAudioDevice(NULL, 0, &request, &got, 0);
|
||||
ctx.audio_stream_format = got.format;
|
||||
ctx.audio_stream_frequency = got.freq;
|
||||
ctx.audio_stream_channel_count = got.channels;
|
||||
/* TODO: relax this */
|
||||
SDL_assert_always(got.freq == AUDIO_FREQUENCY);
|
||||
SDL_assert_always(got.format == AUDIO_F32);
|
||||
SDL_assert_always(got.channels == 2);
|
||||
|
||||
SDL_PauseAudioDevice(ctx.audio_device, 0);
|
||||
|
||||
profile_end("audio initialization");
|
||||
|
||||
ctx.audio_initialized = true;
|
||||
}
|
||||
|
||||
if (channel) {
|
||||
AudioChannelItem *pair = shgetp_null(ctx.audio_channels, channel);
|
||||
|
||||
|
Reference in New Issue
Block a user