Skip to content

Commit

Permalink
add S_Audio_StreamSoundClear
Browse files Browse the repository at this point in the history
  • Loading branch information
walkawayy committed Aug 1, 2023
1 parent 798990f commit a2997c7
Showing 1 changed file with 18 additions and 16 deletions.
34 changes: 18 additions & 16 deletions src/specific/s_audio_stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit a2997c7

Please sign in to comment.