Add the ability to opt-out of default output device initialization;

This commit is contained in:
bjorn 2021-02-05 04:48:18 -07:00 committed by Bjorn
parent 782c22448e
commit e3e7b265a3
3 changed files with 14 additions and 2 deletions

View File

@ -163,6 +163,7 @@ int luaopen_lovr_audio(lua_State* L) {
luax_register(L, lovrAudio);
luax_registertype(L, Source);
bool start = true;
const char *spatializer = NULL;
luax_pushconf(L);
lua_getfield(L, -1, "audio");
@ -170,13 +171,19 @@ int luaopen_lovr_audio(lua_State* L) {
lua_getfield(L, -1, "spatializer");
spatializer = lua_tostring(L, -1);
lua_pop(L, 1);
lua_getfield(L, -1, "start");
start = lua_isnil(L, -1) || lua_toboolean(L, -1);
lua_pop(L, 1);
}
lua_pop(L, 2);
if (lovrAudioInit(spatializer)) {
lovrAudioSetDevice(AUDIO_PLAYBACK, NULL, 0, PLAYBACK_SAMPLE_RATE, SAMPLE_F32);
lovrAudioStart(AUDIO_PLAYBACK);
luax_atexit(L, lovrAudioDestroy);
if (start) {
lovrAudioSetDevice(AUDIO_PLAYBACK, NULL, 0, PLAYBACK_SAMPLE_RATE, SAMPLE_F32);
lovrAudioStart(AUDIO_PLAYBACK);
}
}
return 1;

View File

@ -267,6 +267,7 @@ bool lovrAudioSetDevice(AudioType type, void* id, size_t size, uint32_t sampleRa
ma_device_config config;
if (type == AUDIO_PLAYBACK) {
sampleRate = sampleRate ? sampleRate : PLAYBACK_SAMPLE_RATE;
lovrAssert(sampleRate == PLAYBACK_SAMPLE_RATE, "Playback sample rate must be %d", PLAYBACK_SAMPLE_RATE);
lovrAssert(format == SAMPLE_F32, "Playback format must be f32");
config = ma_device_config_init(ma_device_type_playback);

View File

@ -112,6 +112,10 @@ function lovr.boot()
thread = true,
timer = true
},
audio = {
start = true,
spatializer = 'simple'
},
graphics = {
debug = false
},