diff options
author | Juan J. Martinez <jjm@usebox.net> | 2023-08-10 12:09:06 +0100 |
---|---|---|
committer | Juan J. Martinez <jjm@usebox.net> | 2023-08-10 12:09:06 +0100 |
commit | cd2296358a03ab9ca4d6c017262735eaa63b5fdb (patch) | |
tree | ae8f4c39e5936556a93a9468b98e4eb7eecdadca /src/sound.c | |
parent | b26a8cb5ba0c6d4e766ea0de3505fe39e542ee5e (diff) | |
download | gold-mine-run-cd2296358a03ab9ca4d6c017262735eaa63b5fdb.tar.gz gold-mine-run-cd2296358a03ab9ca4d6c017262735eaa63b5fdb.zip |
Don't use the "nos" driver1.1
This fixes:
- crash when exiting after running the game with the no sound (nos)
driver
- occasional "pauses" when running the game with no sound
Diffstat (limited to 'src/sound.c')
-rw-r--r-- | src/sound.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/src/sound.c b/src/sound.c index a3f38b8..bf0c7be 100644 --- a/src/sound.c +++ b/src/sound.c @@ -26,18 +26,16 @@ static Efx efx[EFX_CNT] = { NULL, (const char *)binary_death_efx_start, (size_t)&binary_death_efx_size}, }; +static uint8_t has_sound = 0; static uint8_t cur = 0; static uint32_t voice = 0; - static MODULE *music = NULL; -uint8_t sound_init(uint8_t nosound) +uint8_t sound_init() { MikMod_InitThreads(); - if (!nosound) - MikMod_RegisterDriver(&drv_sb); - MikMod_RegisterDriver(&drv_nos); + MikMod_RegisterDriver(&drv_sb); MikMod_RegisterLoader(&load_it); md_mode |= DMODE_SOFT_SNDFX | DMODE_SOFT_MUSIC; @@ -47,7 +45,8 @@ uint8_t sound_init(uint8_t nosound) md_mixfreq = 22050; if (MikMod_Init(NULL)) - return 0; + /* has_sound is 0 */ + return 1; for (uint8_t i = 0; i < EFX_CNT; i++) { @@ -67,6 +66,7 @@ uint8_t sound_init(uint8_t nosound) Player_Start(music); MikMod_EnableOutput(); + has_sound = 1; return 1; } @@ -76,6 +76,10 @@ volatile static uint8_t divider = 0; * counter and updating 1 in 20 interrupts */ void sound_update() { + /* we shouldn't call this anyway */ + if (!has_sound) + return; + if (++divider == 20) { divider = 0; @@ -85,17 +89,23 @@ void sound_update() void sound_mute() { - MikMod_DisableOutput(); + if (has_sound) + MikMod_DisableOutput(); } void sound_unmute() { - MikMod_EnableOutput(); + if (has_sound) + MikMod_EnableOutput(); } void sound_free() { - MikMod_DisableOutput(); + if (!has_sound) + return; + + if (MikMod_Active()) + MikMod_DisableOutput(); if (music) Player_Free(music); @@ -109,11 +119,15 @@ void sound_free() void sound_music_pattern(uint16_t pat) { - Player_SetPosition(pat); + if (has_sound) + Player_SetPosition(pat); } void sound_play_efx(uint8_t efxno) { + if (!has_sound) + return; + if (cur > efxno && !Voice_Stopped(voice)) return; |