[Scummvm-git-logs] scummvm master -> 7778c065bc29d44ccf3ac582047da16cadb23a47

lephilousophe noreply at scummvm.org
Sun Oct 27 08:14:48 UTC 2024


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e5a7add410 TINSEL: Don't open file from mixing callback
7778c065bc SKY: Don't open file from mixing callback


Commit: e5a7add41016d4c422cddd06bf9dd8c567801665
    https://github.com/scummvm/scummvm/commit/e5a7add41016d4c422cddd06bf9dd8c567801665
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-10-27T09:14:44+01:00

Commit Message:
TINSEL: Don't open file from mixing callback

readSampleData is called indirectly by audio thread.
Android doesn't support opening file from it and it's not a good
behaviour anyway as IO calls may block.
The file is opened when it is changed.

Changed paths:
    engines/tinsel/music.cpp
    engines/tinsel/music.h


diff --git a/engines/tinsel/music.cpp b/engines/tinsel/music.cpp
index c833cd713eb..724f3158630 100644
--- a/engines/tinsel/music.cpp
+++ b/engines/tinsel/music.cpp
@@ -853,6 +853,8 @@ void PCMMusicPlayer::setMusicSceneDetails(SCNHANDLE hScript,
 	_hScript = hScript;
 	_hSegment = hSegment;
 	_filename = fileName;
+	_file.close();
+	_file.open(fileName);
 
 	// Start scene with music not dimmed
 	_dimmed = false;
@@ -968,9 +970,8 @@ void PCMMusicPlayer::fadeOutIteration() {
 	_vm->_mixer->setChannelVolume(_handle, _fadeOutVolume);
 }
 
-Common::MemoryReadStream *readSampleData(const Common::Path &filename, uint32 sampleOffset, uint32 sampleLength) {
-	Common::File file;
-	if (!file.open(filename))
+Common::MemoryReadStream *readSampleData(const Common::Path &filename, Common::File &file, uint32 sampleOffset, uint32 sampleLength) {
+	if (!file.isOpen())
 		error(CANNOT_FIND_FILE, filename.toString().c_str());
 
 	file.seek(sampleOffset);
@@ -1009,7 +1010,7 @@ void PCMMusicPlayer::loadADPCMMusicFromSegment(int segmentNum) {
 			"offset %d (script %d.%d)",
 			sampleCLength, sampleOffset, _scriptNum, _scriptIndex - 1);
 
-	Common::SeekableReadStream *sampleStream = readSampleData(_filename, sampleOffset, sampleCLength);
+	Common::SeekableReadStream *sampleStream = readSampleData(_filename, _file, sampleOffset, sampleCLength);
 
 	delete _curChunk;
 	_curChunk = new Tinsel8_ADPCMStream(sampleStream, DisposeAfterUse::YES, sampleCLength, 22050, 1, 32);
@@ -1024,7 +1025,7 @@ void PCMMusicPlayer::loadMP3MusicFromSegment(int segmentNum) {
 #ifdef USE_MAD
 	MusicSegmentNoir *musicSegments = (MusicSegmentNoir *)_vm->_handle->LockMem(_hSegment);
 
-	Common::SeekableReadStream *sampleStream = readSampleData(_filename, musicSegments[segmentNum].sampleOffset,
+	Common::SeekableReadStream *sampleStream = readSampleData(_filename, _file, musicSegments[segmentNum].sampleOffset,
 			musicSegments[segmentNum].sampleLength);
 
 	delete _curChunk;
diff --git a/engines/tinsel/music.h b/engines/tinsel/music.h
index ccb02b85d0b..27885cf47e3 100644
--- a/engines/tinsel/music.h
+++ b/engines/tinsel/music.h
@@ -178,6 +178,7 @@ protected:
 	SCNHANDLE _hScript;
 	SCNHANDLE _hSegment;
 	Common::Path _filename;
+	Common::File _file;
 
 	uint8 _volume;
 


Commit: 7778c065bc29d44ccf3ac582047da16cadb23a47
    https://github.com/scummvm/scummvm/commit/7778c065bc29d44ccf3ac582047da16cadb23a47
Author: Le Philousophe (lephilousophe at users.noreply.github.com)
Date: 2024-10-27T09:14:44+01:00

Commit Message:
SKY: Don't open file from mixing callback

loadNewMusic is called indirectly by audio thread.
Android doesn't support opening file from it and it's not a good
behaviour anyway as IO calls may block.
The file is opened when the music is started.

Changed paths:
    engines/sky/music/musicbase.cpp
    engines/sky/music/musicbase.h


diff --git a/engines/sky/music/musicbase.cpp b/engines/sky/music/musicbase.cpp
index 92cd8359d28..64cf0cd6e86 100644
--- a/engines/sky/music/musicbase.cpp
+++ b/engines/sky/music/musicbase.cpp
@@ -53,6 +53,7 @@ void MusicBase::loadSection(uint8 pSection) {
 	_musicTempo0 = 0x78; // init constants taken from idb file, area ~0x1060
 	_musicTempo1 = 0xC0;
 	_onNextPoll.musicToProcess = 0;
+	_onNextPoll.stream = nullptr;
 	_tempo = _aktTime = 0x10001;
 	_numberOfChannels = _currentMusic = 0;
 	setupPointers();
@@ -105,24 +106,14 @@ void MusicBase::loadNewMusic() {
 
 	// Try playing digital audio first (from the Music Enhancement Project).
 	// TODO: This always prefers digital music over the MIDI music types!
-	uint8 section = _currentSection;
-	uint8 song = _currentMusic;
-	// handle duplicates
-	if ((section == 2 && song == 1) || (section == 5 && song == 1)) {
-		section = 1;
-		song = 1;
-	} else if ((section == 2 && song == 4) || (section == 5 && song == 4)) {
-		section = 1;
-		song = 4;
-	} else if (section == 5 && song == 6) {
-		section = 4;
-		song = 4;
-	}
-	Common::Path trackName(Common::String::format("music_%d%02d", section, song));
-	Audio::SeekableAudioStream *stream = Audio::SeekableAudioStream::openStreamFile(trackName);
+	Audio::SeekableAudioStream *stream = _onNextPoll.stream;
 	if (stream) {
+		_onNextPoll.stream = nullptr;
+
 		// not all tracks should loop
 		bool loops = true;
+		uint8 section = _currentSection;
+		uint8 song = _currentMusic;
 		if ((section == 0 && song == 1)
 		 || (section == 1 && song == 1) || (section == 1 && song == 4)
 		 || (section == 2 && song == 1) || (section == 2 && song == 4)
@@ -167,7 +158,32 @@ void MusicBase::pollMusic() {
 }
 
 void MusicBase::startMusic(uint16 param) {
-	_onNextPoll.musicToProcess = param & 0xF;
+	uint8 song = param & 0xF;
+
+	_onNextPoll.musicToProcess = song;
+	delete _onNextPoll.stream;
+	_onNextPoll.stream = nullptr;
+
+	if (song == 0)
+		return;
+
+	// Load digital audio now if available
+	// This avoids doing it in the audio thread
+	uint8 section = _currentSection;
+	// handle duplicates
+	if ((section == 2 && song == 1) || (section == 5 && song == 1)) {
+		section = 1;
+		song = 1;
+	} else if ((section == 2 && song == 4) || (section == 5 && song == 4)) {
+		section = 1;
+		song = 4;
+	} else if (section == 5 && song == 6) {
+		section = 4;
+		song = 4;
+	}
+
+	Common::Path trackName(Common::String::format("music_%d%02d", section, song));
+	_onNextPoll.stream = Audio::SeekableAudioStream::openStreamFile(trackName);
 }
 
 uint8 MusicBase::giveVolume() {
diff --git a/engines/sky/music/musicbase.h b/engines/sky/music/musicbase.h
index e6882f27c12..0aa960ab984 100644
--- a/engines/sky/music/musicbase.h
+++ b/engines/sky/music/musicbase.h
@@ -28,6 +28,10 @@
 
 #include "audio/mixer.h"
 
+namespace Audio {
+class SeekableAudioStream;
+}
+
 namespace Sky {
 
 class Disk;
@@ -36,6 +40,7 @@ class Disk;
 
 typedef struct {
 	uint8 musicToProcess;
+	Audio::SeekableAudioStream *stream;
 } Actions;
 
 class ChannelBase {




More information about the Scummvm-git-logs mailing list