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.
This commit is contained in:
Jonas Kulla 2013-12-08 12:58:39 +01:00
parent bf712f3738
commit 946d778b96
1 changed files with 32 additions and 1 deletions

View File

@ -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;
}