- properly pause streaming soundtracks of movies as well.

This is not relevant for any of the stock movies as they use separate sound files, we need to be aware of mods using the streaming sound capabilities of MVE and SMK.
This commit is contained in:
Christoph Oelckers 2021-04-16 22:14:11 +02:00
parent 1852c0b802
commit f28aa8f06c
3 changed files with 22 additions and 3 deletions

View file

@ -110,13 +110,18 @@ void S_SetMusicCallbacks(MusicCallbacks* cb)
//========================================================================== //==========================================================================
static std::unique_ptr<SoundStream> musicStream; static std::unique_ptr<SoundStream> musicStream;
static TArray<SoundStream*> customStreams;
SoundStream *S_CreateCustomStream(size_t size, int samplerate, int numchannels, StreamCallback cb, void *userdata) SoundStream *S_CreateCustomStream(size_t size, int samplerate, int numchannels, StreamCallback cb, void *userdata)
{ {
int flags = 0; int flags = 0;
if (numchannels < 2) flags |= SoundStream::Mono; if (numchannels < 2) flags |= SoundStream::Mono;
auto stream = GSnd->CreateStream(cb, int(size), flags, samplerate, userdata); auto stream = GSnd->CreateStream(cb, int(size), flags, samplerate, userdata);
if (stream) stream->Play(true, 1); if (stream)
{
stream->Play(true, 1);
customStreams.Push(stream);
}
return stream; return stream;
} }
@ -125,11 +130,19 @@ void S_StopCustomStream(SoundStream *stream)
if (stream) if (stream)
{ {
stream->Stop(); stream->Stop();
auto f = customStreams.Find(stream);
if (f < customStreams.Size()) customStreams.Delete(f);
delete stream; delete stream;
} }
} }
void S_PauseAllCustomStreams(bool on)
{
for (auto s : customStreams)
{
s->SetPaused(on);
}
}
static TArray<int16_t> convert; static TArray<int16_t> convert;
static bool FillStream(SoundStream* stream, void* buff, int len, void* userdata) static bool FillStream(SoundStream* stream, void* buff, int len, void* userdata)

View file

@ -14,6 +14,7 @@ class SoundStream;
typedef bool(*StreamCallback)(SoundStream* stream, void* buff, int len, void* userdata); typedef bool(*StreamCallback)(SoundStream* stream, void* buff, int len, void* userdata);
SoundStream *S_CreateCustomStream(size_t size, int samplerate, int numchannels, StreamCallback cb, void *userdata); SoundStream *S_CreateCustomStream(size_t size, int samplerate, int numchannels, StreamCallback cb, void *userdata);
void S_StopCustomStream(SoundStream* stream); void S_StopCustomStream(SoundStream* stream);
void S_PauseAllCustomStreams(bool on);
struct MusicCallbacks struct MusicCallbacks
{ {

View file

@ -998,7 +998,10 @@ void updatePauseStatus()
} }
} }
paused ? S_PauseSound(!pausedWithKey, !paused) : S_ResumeSound(paused); if (paused)
S_PauseSound(!pausedWithKey, !paused);
else
S_ResumeSound(paused);
} }
//========================================================================== //==========================================================================
@ -1106,6 +1109,7 @@ void S_PauseSound (bool notmusic, bool notsfx)
{ {
soundEngine->SetPaused(true); soundEngine->SetPaused(true);
GSnd->SetSfxPaused (true, 0); GSnd->SetSfxPaused (true, 0);
S_PauseAllCustomStreams(true);
} }
} }
@ -1124,6 +1128,7 @@ void S_ResumeSound (bool notsfx)
{ {
soundEngine->SetPaused(false); soundEngine->SetPaused(false);
GSnd->SetSfxPaused (false, 0); GSnd->SetSfxPaused (false, 0);
S_PauseAllCustomStreams(false);
} }
} }