PINK: Preload sounds to avoid race condition.

Since we were reading directly from the ORB file, during video playback
we were reading both sound and video which often was leading to
the incorrect reads
This commit is contained in:
Eugene Sandulenko 2021-05-10 16:01:23 +02:00
parent dc94b96a95
commit a2b1164fe9
No known key found for this signature in database
GPG Key ID: 014D387312D34F08

View File

@ -21,6 +21,8 @@
*/
#include "common/debug.h"
#include "common/memstream.h"
#include "common/substream.h"
#include "pink/archive.h"
#include "pink/pink.h"
@ -60,7 +62,16 @@ void ActionSound::start() {
} else
_actor->endAction();
_sound.play(page->getResourceStream(_fileName), soundType, _volume, 0, _isLoop);
Common::SafeSeekableSubReadStream *stream = page->getResourceStream(_fileName);
byte *data = (byte *)malloc(stream->size());
stream->read(data, stream->size());
Common::MemoryReadStream *memstream = new Common::MemoryReadStream(data, stream->size(), DisposeAfterUse::YES);
delete stream;
Common::SafeSeekableSubReadStream *stream2 = new Common::SafeSeekableSubReadStream(memstream, 0, memstream->size(), DisposeAfterUse::YES);
_sound.play(stream2, soundType, _volume, 0, _isLoop);
debugC(6, kPinkDebugActions, "Actor %s has now ActionSound %s", _actor->getName().c_str(), _name.c_str());
}