From 78354cbdafa796ee35130f4f6410285356eacd59 Mon Sep 17 00:00:00 2001 From: Nunuhara Cabbage Date: Mon, 11 Apr 2022 21:25:31 -0700 Subject: [PATCH] audio: seek to 0 when stopping stream Fix issue in Rance VI where BGM would resume playing from the previous position instead of restarting after a stream was stopped. Also fix an issue where a stale sample could be played when starting a stream after it had been stopped. --- src/audio_mixer.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/audio_mixer.c b/src/audio_mixer.c index 87ad287..f8939cb 100644 --- a/src/audio_mixer.c +++ b/src/audio_mixer.c @@ -236,6 +236,7 @@ static int refill_stream(sts_mixer_sample_t *sample, void *data) if (ch->frame >= ch->fade.end_pos) { ch->fade.fading = false; if (ch->fade.stop) { + cb_seek(ch, 0); r = STS_STREAM_COMPLETE; } } @@ -266,6 +267,7 @@ int channel_play(struct channel *ch) SDL_UnlockAudioDevice(audio_device); return 1; } + memset(ch->data, 0, sizeof(ch->data)); ch->voice = sts_mixer_play_stream(&mixers[ch->mixer_no].mixer, &ch->stream, 1.0f); SDL_UnlockAudioDevice(audio_device); return 1; @@ -278,6 +280,7 @@ int channel_stop(struct channel *ch) SDL_UnlockAudioDevice(audio_device); return 1; } + cb_seek(ch, 0); sts_mixer_stop_voice(&mixers[ch->mixer_no].mixer, ch->voice); ch->voice = -1; SDL_UnlockAudioDevice(audio_device);