add config vars for audio thread runahead and sleep

This commit is contained in:
fgsfds 2024-05-22 10:31:11 +02:00
parent a02075edc3
commit e93a2bc14e
3 changed files with 9 additions and 2 deletions

View File

@ -54,6 +54,8 @@ unsigned int configMasterVolume = MAX_VOLUME; // 0 - MAX_VOLUME
unsigned int configMusicVolume = MAX_VOLUME;
unsigned int configSfxVolume = MAX_VOLUME;
unsigned int configEnvVolume = MAX_VOLUME;
float configAudioRunahead = 0.f;
float configAudioSleep = 1.f;
// Keyboard mappings (VK_ values, by default keyboard/gamepad/mouse)
unsigned int configKeyA[MAX_BINDS] = { 0x0026, 0x1000, 0x1103 };
@ -106,6 +108,8 @@ static const struct ConfigOption options[] = {
{.name = "music_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configMusicVolume},
{.name = "sfx_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configSfxVolume},
{.name = "env_volume", .type = CONFIG_TYPE_UINT, .uintValue = &configEnvVolume},
{.name = "audio_sleep", .type = CONFIG_TYPE_FLOAT, .floatValue = &configAudioSleep},
{.name = "audio_runahead", .type = CONFIG_TYPE_FLOAT, .floatValue = &configAudioRunahead},
{.name = "key_a", .type = CONFIG_TYPE_BIND, .uintValue = configKeyA},
{.name = "key_b", .type = CONFIG_TYPE_BIND, .uintValue = configKeyB},
{.name = "key_start", .type = CONFIG_TYPE_BIND, .uintValue = configKeyStart},

View File

@ -23,6 +23,8 @@ extern unsigned int configMasterVolume;
extern unsigned int configMusicVolume;
extern unsigned int configSfxVolume;
extern unsigned int configEnvVolume;
extern float configAudioRunahead;
extern float configAudioSleep;
extern unsigned int configKeyA[];
extern unsigned int configKeyB[];
extern unsigned int configKeyStart[];

View File

@ -163,7 +163,8 @@ void* audio_thread() {
set_sequence_player_volume(SEQ_PLAYER_SFX, (f32)configSfxVolume / 127.0f * master_mod);
set_sequence_player_volume(SEQ_PLAYER_ENV, (f32)configEnvVolume / 127.0f * master_mod);
int samples_left = audio_api->buffered();
int samples_left = audio_api->buffered() - (audio_api->get_desired_buffered() * configAudioRunahead);
if (samples_left < 0) samples_left = 0;
u32 num_audio_samples = samples_left < audio_api->get_desired_buffered() ? SAMPLES_HIGH : SAMPLES_LOW;
// printf("Audio samples: %d %u\n", samples_left, num_audio_samples);
s16 audio_buffer[SAMPLES_HIGH * 2];
@ -191,7 +192,7 @@ void* audio_thread() {
end_time = sys_profile_time();
// Sleep for the remaining time
f64 nap_time = frametime_micro - (end_time - start_time);
f64 nap_time = (frametime_micro - (end_time - start_time)) * configAudioSleep;
// printf("Audio thread nap time: %f\n", nap_time);
if (nap_time > 0.0) sys_sleep(nap_time);