From 946d778b96e21b160f922b155d5467b4f3b1093d Mon Sep 17 00:00:00 2001 From: Jonas Kulla Date: Sun, 8 Dec 2013 12:58:39 +0100 Subject: [PATCH] Audio: Fix BGM not starting after ME has ended A previous commit prevented the MeWatch from starting a BGM stream that was in stopped state. However, when a new BGM is loaded while the ME is still playing, the BGM stream will be stopped even though we want it to start after the ME finishes. Also add some comments trying to explain members of 'AudioStream' a bit better. --- src/audio.cpp | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/audio.cpp b/src/audio.cpp index bffbcaf..fd7059f 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -1132,12 +1132,34 @@ struct AudioStream /* Volume set by external threads, * such as for fade-in/out. * Multiplied with intVolume for final - * playback volume */ + * playback volume. + * fadeVolume: used by fade-out thread. + * extVolume: used by MeWatch. */ float fadeVolume; float extVolume; + /* Note that 'extPaused' and 'noResumeStop' are + * effectively only used with the AudioStream + * instance representing the BGM */ + + /* Flag indicating that the MeWatch paused this + * (BGM) stream because a ME started playing. + * While this flag is set, calls to 'play()' + * might open another file, but will not start + * the playback stream (the MeWatch will start + * it as soon as the ME finished playing). */ bool extPaused; + /* Flag indicating that this stream shouldn't be + * started by the MeWatch when it is in stopped + * state (eg. because the BGM stream was explicitly + * stopped by the user script while the ME was playing. + * When a new BGM is started (via 'play()') while an ME + * is playing, the file will be loaded without starting + * the stream, but we want the MeWatch to start it as + * soon as the ME ends, so we unset this flag. */ + bool noResumeStop; + ALStream stream; SDL_mutex *streamMut; @@ -1169,6 +1191,7 @@ struct AudioStream fadeVolume(1.0), extVolume(1.0), extPaused(false), + noResumeStop(false), stream(loopMode) { current.volume = 1.0; @@ -1261,6 +1284,8 @@ struct AudioStream if (!extPaused) stream.play(offset); + else + noResumeStop = false; unlockStream(); } @@ -1271,6 +1296,8 @@ struct AudioStream lockStream(); + noResumeStop = true; + stream.stop(); unlockStream(); @@ -1554,6 +1581,10 @@ struct AudioPrivate { /* BGM is stopped. -> MeNotPlaying */ bgm.setExtVolume1(1.0); + + if (!bgm.noResumeStop) + bgm.stream.play(); + meWatch.state = MeNotPlaying; }