From 3b7939347c780ecd6385d883cb6f1d451b0d1c00 Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 22 Mar 2026 15:03:20 -0400 Subject: [PATCH] Hacky System for efx reverb tail Since theres no direct way of getting this lets hack around it :D --- src/i_sound.h | 1 + src/p_enemy.c | 3 ++- src/s_sound.c | 21 ++++++++++++++++++++- src/s_sound.h | 5 +++++ src/sdl/al_sound.c | 25 +++++++++++++++++++++++++ 5 files changed, 53 insertions(+), 2 deletions(-) diff --git a/src/i_sound.h b/src/i_sound.h index 60d82f62f..c588d0bfb 100644 --- a/src/i_sound.h +++ b/src/i_sound.h @@ -287,6 +287,7 @@ boolean I_FadeOutStopSong(UINT32 ms); boolean I_FadeInPlaySong(UINT32 ms, boolean looping); efx_t *I_CreateEFX(efx_t *efx); +float I_GetEFXTail(efx_t *efx); void I_DeleteEFX(efx_t *efx); #ifdef __cplusplus diff --git a/src/p_enemy.c b/src/p_enemy.c index 59ffab2d3..ec9b66e64 100644 --- a/src/p_enemy.c +++ b/src/p_enemy.c @@ -3234,11 +3234,12 @@ void A_AttractChase(void *thing) actor->target->player->ringboost += K_GetKartRingPower(actor->target->player, true); actor->target->player->ringtime += K_GetKartRingPower(actor->target->player, true); -//#define EFXTEST +#define EFXTEST #ifdef EFXTEST efx_t efx; S_InitEFXArray(&efx); efx.type = EFFECT_REVERB; + efx.var5 = 5.9; S_StartSoundAtVolumeEx(actor->target, sfx_s1b5, actor->target->player->ringvolume, &efx); #else S_StartSoundAtVolume(actor->target, sfx_s1b5, actor->target->player->ringvolume); diff --git a/src/s_sound.c b/src/s_sound.c index 6c518c1ea..3032350b3 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -316,7 +316,10 @@ static void SetChannelsNum(void) for (i = 0; i < numofchannels; i++) { channels[i].sfxinfo = 0; + channels[i].duration = 0; + channels[i].endtime = 0; channels[i].origin = NULL; + channels[i].efxtail = 0; channels[i].efx = NULL; } @@ -735,6 +738,7 @@ void S_StartSoundAtVolumeEx(const void *origin_p, sfxenum_t sfx_id, INT32 volume if (efx != NULL && efx->type != EFFECT_NONE) { channels[cnum].efx = I_CreateEFX(efx); + channels[cnum].efxtail = I_GetEFXTail(efx); } else { @@ -890,9 +894,19 @@ notinlevel: // if channel is allocated but sound has stopped, free it if (!I_SoundIsPlaying(c->handle)) { - S_StopChannel(cnum); + c->endtime += 1; + if (c->efx == NULL || c->endtime > c->efxtail + c->duration) + { + CONS_Printf("endtime: %f efxtail: %f duration: %f \n", c->endtime, c->efxtail, c->duration); + S_StopChannel(cnum); + } continue; } + else + { + c->duration += 1; + c->endtime += 1; + } if (gamestate != GS_LEVEL || c->origin == NULL) continue; @@ -962,7 +976,9 @@ notinlevel: } if (audible) + { I_UpdateSoundParams(c->handle, S_GetSoundVolume(c->sfxinfo, volume), sep, pitch, c->efx); + } else S_StopChannel(cnum); } @@ -1031,8 +1047,11 @@ static void S_StopChannel(INT32 cnum) c->sfxinfo = 0; } + c->duration = 0; + c->endtime = 0; c->origin = NULL; I_DeleteEFX(c->efx); + c->efxtail = 0; c->efx = NULL; } diff --git a/src/s_sound.h b/src/s_sound.h index 2f471a19a..a5a911ff6 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -88,8 +88,13 @@ struct channel_t // handle of the sound being played INT32 handle; + // length sound has been playing + float duration; + float endtime; + // EFX efx_t *efx; + float efxtail; }; struct caption_t { diff --git a/src/sdl/al_sound.c b/src/sdl/al_sound.c index e71388abc..413c84e56 100644 --- a/src/sdl/al_sound.c +++ b/src/sdl/al_sound.c @@ -1971,6 +1971,31 @@ efx_t *I_CreateEFX(efx_t *efx) return NULL; } +float I_GetEFXTail(efx_t *efx) +{ + LOCKAUDIO; + + if (efx == NULL) + return 0; + + float tailtime = 0; + switch(efx->type) + { + case EFFECT_REVERB: + if (efx->var5 != 255) + tailtime = efx->var5; + else + tailtime = 1.49; + break; + + default: + tailtime = 0; + break; + } + + return tailtime*TICRATE; +} + void I_DeleteEFX(efx_t *efx) { LOCKAUDIO;