From a2997c7b735a6c5a70e92c5ae7a9d4d84df217e8 Mon Sep 17 00:00:00 2001 From: walkawayy <81546780+walkawayy@users.noreply.github.com> Date: Mon, 31 Jul 2023 21:59:24 -0400 Subject: [PATCH] add S_Audio_StreamSoundClear --- src/specific/s_audio_stream.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/specific/s_audio_stream.c b/src/specific/s_audio_stream.c index f3fca8ed7..63c134282 100644 --- a/src/specific/s_audio_stream.c +++ b/src/specific/s_audio_stream.c @@ -59,6 +59,7 @@ static bool S_Audio_StreamSoundDecodeFrame(AUDIO_STREAM_SOUND *stream); static bool S_Audio_StreamSoundEnqueueFrame(AUDIO_STREAM_SOUND *stream); static bool S_Audio_StreamSoundInitialiseFromPath( int sound_id, const char *file_path); +static void S_Audio_StreamSoundClear(AUDIO_STREAM_SOUND *stream); static bool S_Audio_StreamSoundDecodeFrame(AUDIO_STREAM_SOUND *stream) { @@ -272,17 +273,23 @@ static bool S_Audio_StreamSoundInitialiseFromPath( return ret; } +static void S_Audio_StreamSoundClear(AUDIO_STREAM_SOUND *stream) +{ + stream->is_used = false; + stream->is_playing = false; + stream->is_looped = false; + stream->is_read_done = true; + stream->volume = 0.0f; + stream->timestamp = 0; + stream->sdl.stream = NULL; + stream->finish_callback = NULL; +} + void S_Audio_StreamSoundInit(void) { for (int sound_id = 0; sound_id < AUDIO_MAX_ACTIVE_STREAMS; sound_id++) { AUDIO_STREAM_SOUND *stream = &m_StreamSounds[sound_id]; - stream->is_used = false; - stream->is_playing = false; - stream->is_read_done = true; - stream->volume = 0.0f; - stream->timestamp = 0; - stream->sdl.stream = NULL; - stream->finish_callback = NULL; + S_Audio_StreamSoundClear(stream); } } @@ -386,21 +393,16 @@ bool S_Audio_StreamSoundClose(int sound_id) if (stream->sdl.stream) { SDL_FreeAudioStream(stream->sdl.stream); - stream->sdl.stream = NULL; } - stream->is_read_done = true; - stream->is_used = false; - stream->is_playing = false; - stream->is_looped = false; - stream->volume = 0.0f; - stream->timestamp = 0; - SDL_UnlockAudioDevice(g_AudioDeviceID); - if (stream->finish_callback) { stream->finish_callback(sound_id, stream->finish_callback_user_data); } + S_Audio_StreamSoundClear(stream); + + SDL_UnlockAudioDevice(g_AudioDeviceID); + return true; }