sdl_sound: attempt to fix sounds cutting off
i suck at explaining so just trust. :chonkbuncle: Game sound handling has no idea which sound it is playing/checking, so a sound that ended frees its slot and it might get occupied again without the game knowing so just encode the channel number into the sound so we can actually check
This commit is contained in:
1 parent
97ca034037
commit
ca8e811bd9
1 file changed
+24
-11
+24
-11
@@ -62,6 +62,7 @@ typedef struct sound_s
|
||||
size_t pos;
|
||||
float volume[2];
|
||||
float pitch;
|
||||
UINT32 channelId;
|
||||
} sound_t;
|
||||
|
||||
typedef struct sndlump_s
|
||||
@@ -996,7 +997,7 @@ void I_FreeSfx(sfxinfo_t *sfx)
|
||||
|
||||
INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, /*UINT8 pitch, UINT8 priority,*/ INT32 channel)
|
||||
{
|
||||
(void)channel; // ignore this - we do mixing ourselves so we don't need it
|
||||
//(void)channel; // ignore this - we do mixing ourselves so we don't need it
|
||||
//(void)priority; // priority and channel management is handled by SRB2...
|
||||
//(void)pitch; // TODO (we can do this now with SDL3)
|
||||
if (S_sfx[id].data == NULL)
|
||||
@@ -1021,13 +1022,16 @@ INT32 I_StartSound(sfxenum_t id, UINT8 vol, UINT8 sep, /*UINT8 pitch, UINT8 prio
|
||||
sound->pitch = 1.0f;
|
||||
sound->volume[0] = (float)vol / 255.0f;
|
||||
sound->volume[1] = (float)vol / 255.0f;
|
||||
|
||||
sound->channelId = channel;
|
||||
|
||||
if (sep >= 128)
|
||||
sound->volume[0] *= 1.0f - ((float)sep-128.0f) / 128.0f;
|
||||
else
|
||||
sound->volume[1] *= (float)sep / 128.0f;
|
||||
sounds[i] = sound;
|
||||
SDL_UnlockAudioStream(audio_stream);
|
||||
return i;
|
||||
return (sound->channelId << 8) | i;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1040,11 +1044,14 @@ void I_StopSound(INT32 handle)
|
||||
if (handle == -1)
|
||||
return;
|
||||
|
||||
size_t index = handle & 0xFF;
|
||||
UINT32 soundid = handle >> 8;
|
||||
|
||||
SDL_LockAudioStream(audio_stream);
|
||||
if (sounds[handle] != NULL)
|
||||
if (sounds[index] != NULL && sounds[index]->channelId == soundid)
|
||||
{
|
||||
free(sounds[handle]);
|
||||
sounds[handle] = NULL;
|
||||
free(sounds[index]);
|
||||
sounds[index] = NULL;
|
||||
}
|
||||
SDL_UnlockAudioStream(audio_stream);
|
||||
}
|
||||
@@ -1054,8 +1061,11 @@ boolean I_SoundIsPlaying(INT32 handle)
|
||||
if (handle == -1)
|
||||
return false;
|
||||
|
||||
size_t index = handle & 0xFF;
|
||||
UINT32 soundid = handle >> 8;
|
||||
|
||||
SDL_LockAudioStream(audio_stream);
|
||||
bool playing = sounds[handle] != NULL;
|
||||
bool playing = (sounds[index] != NULL && sounds[index]->channelId == soundid);
|
||||
SDL_UnlockAudioStream(audio_stream);
|
||||
return playing;
|
||||
}
|
||||
@@ -1066,8 +1076,11 @@ void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep/*, UINT8 pitch*/)
|
||||
if (handle == -1)
|
||||
return;
|
||||
|
||||
size_t index = handle & 0xFF;
|
||||
UINT32 soundid = handle >> 8;
|
||||
|
||||
SDL_LockAudioStream(audio_stream);
|
||||
if (sounds[handle] == NULL)
|
||||
if (sounds[index] == NULL || sounds[index]->channelId != soundid)
|
||||
{
|
||||
SDL_UnlockAudioStream(audio_stream);
|
||||
return;
|
||||
@@ -1078,12 +1091,12 @@ void I_UpdateSoundParams(INT32 handle, UINT8 vol, UINT8 sep/*, UINT8 pitch*/)
|
||||
if (virtual_spec.channels > 1)
|
||||
{
|
||||
if (sep >= 128)
|
||||
sounds[handle]->volume[0] *= 1.0f - ((float)sep-128.0f) / 128.0f;
|
||||
sounds[index]->volume[0] *= 1.0f - ((float)sep-128.0f) / 128.0f;
|
||||
else
|
||||
sounds[handle]->volume[1] *= (float)sep / 128.0f;
|
||||
sounds[index]->volume[1] *= (float)sep / 128.0f;
|
||||
}
|
||||
//sounds[handle]->pitch = pitch / 128.0f;
|
||||
sounds[handle]->pitch = 1.0f;
|
||||
//sounds[index]->pitch = pitch / 128.0f;
|
||||
sounds[index]->pitch = 1.0f;
|
||||
SDL_UnlockAudioStream(audio_stream);
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user