[Scummvm-git-logs] scummvm master -> cdb924151b6354eb2f185fbc1a988a30957850a1

AndywinXp noreply at scummvm.org
Fri Aug 25 22:38:37 UTC 2023


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

Summary:
cdb924151b SCUMM: HE (Sound): Reimplement 3DO music support


Commit: cdb924151b6354eb2f185fbc1a988a30957850a1
    https://github.com/scummvm/scummvm/commit/cdb924151b6354eb2f185fbc1a988a30957850a1
Author: AndywinXp (andywinxp at gmail.com)
Date: 2023-08-26T00:38:30+02:00

Commit Message:
SCUMM: HE (Sound): Reimplement 3DO music support

Heh, I forgot to do that :-)

Changed paths:
    engines/scumm/he/mixer_he.cpp
    engines/scumm/he/mixer_he.h
    engines/scumm/he/sound_he.cpp
    engines/scumm/he/sound_he.h


diff --git a/engines/scumm/he/mixer_he.cpp b/engines/scumm/he/mixer_he.cpp
index b1deb5c7db1..98090f8a365 100644
--- a/engines/scumm/he/mixer_he.cpp
+++ b/engines/scumm/he/mixer_he.cpp
@@ -474,6 +474,7 @@ bool HEMixer::mixerStartChannel(
 	int sampleLen, int frequency, int volume, int callbackID, uint32 flags, ...) {
 
 	va_list params;
+	bool is3DOMusic = false;
 
 	if ((channel < 0) || (channel >= MIXER_MAX_CHANNELS))
 		return false;
@@ -563,6 +564,10 @@ bool HEMixer::mixerStartChannel(
 	if (flags != CHANNEL_EMPTY_FLAGS) {
 		byte *ptr = _vm->getResourceAddress((ResType)globType, globNum);
 
+		if (READ_BE_UINT32(ptr) == MKTAG('M', 'R', 'A', 'W')) {
+			is3DOMusic = true;
+		}
+
 		if (READ_BE_UINT32(ptr) == MKTAG('W', 'S', 'O', 'U')) {
 			ptr += 8;
 		}
@@ -595,16 +600,35 @@ bool HEMixer::mixerStartChannel(
 			// Fade-in to avoid possible sound popping...
 			byte *dataTmp = data;
 			int rampUpSampleCount = 64;
-			for (int i = 0; i < rampUpSampleCount; i++) {
-				*dataTmp = 128 + (((*dataTmp - 128) * i) / rampUpSampleCount);
-				dataTmp++;
+			if (!is3DOMusic) {
+				for (int i = 0; i < rampUpSampleCount; i++) {
+					*dataTmp = 128 + (((*dataTmp - 128) * i) / rampUpSampleCount);
+					dataTmp++;
+				}
+			} else {
+				// We can't just ramp volume as done above, we have to take
+				// into account the fact that 3DO music is 8-bit -> signed <-
+				rampUpSampleCount = 128;
+				for (int i = 0; i < rampUpSampleCount; i++) {
+					int8 signedSample = (int8)(*dataTmp);
+					signedSample = (signedSample * i) / rampUpSampleCount;
+					*dataTmp = (byte)signedSample;
+					dataTmp++;
+				}
 			}
 		}
 
 		_mixerChannels[channel].stream = Audio::makeQueuingAudioStream(MIXER_DEFAULT_SAMPLE_RATE, false);
 
+		Audio::Mixer::SoundType soundType =
+			globNum == HSND_TALKIE_SLOT ?
+			Audio::Mixer::kSpeechSoundType : Audio::Mixer::kSFXSoundType;
+
+		if (is3DOMusic)
+			soundType = Audio::Mixer::kMusicSoundType;
+
 		_mixer->playStream(
-			globNum == HSND_TALKIE_SLOT ? Audio::Mixer::kSpeechSoundType : Audio::Mixer::kSFXSoundType,
+			soundType,
 			&_mixerChannels[channel].handle,
 			_mixerChannels[channel].stream,
 			-1,
@@ -619,7 +643,7 @@ bool HEMixer::mixerStartChannel(
 				ptr,
 				_mixerChannels[channel].sampleLen,
 				MIXER_DEFAULT_SAMPLE_RATE,
-				mixerGetOutputFlags(),
+				mixerGetOutputFlags(is3DOMusic),
 				DisposeAfterUse::NO);
 
 			_mixerChannels[channel].stream->queueAudioStream(Audio::makeLoopingAudioStream(stream, 0), DisposeAfterUse::YES);
@@ -629,7 +653,7 @@ bool HEMixer::mixerStartChannel(
 				data,
 				_mixerChannels[channel].sampleLen,
 				DisposeAfterUse::YES,
-				mixerGetOutputFlags());
+				mixerGetOutputFlags(is3DOMusic));
 		}
 
 		if (hasCallbackData && !(_mixerChannels[channel].flags & CHANNEL_LOOPING)) {
@@ -637,7 +661,7 @@ bool HEMixer::mixerStartChannel(
 				_mixerChannels[channel].residualData,
 				_mixerChannels[channel].endSampleAdjustment,
 				DisposeAfterUse::YES,
-				mixerGetOutputFlags());
+				mixerGetOutputFlags(is3DOMusic));
 		}
 
 	} else {
@@ -759,11 +783,13 @@ bool HEMixer::mixerStartSpoolingChannel(
 	return true;
 }
 
-byte HEMixer::mixerGetOutputFlags() {
+byte HEMixer::mixerGetOutputFlags(bool is3DOMusic) {
 	// Just plain mono 8-bit sound...
 
 	byte streamFlags = 0;
-	streamFlags |= Audio::FLAG_UNSIGNED;
+
+	if (!is3DOMusic)
+		streamFlags |= Audio::FLAG_UNSIGNED;
 
 #ifdef SCUMM_LITTLE_ENDIAN
 	streamFlags |= Audio::FLAG_LITTLE_ENDIAN;
diff --git a/engines/scumm/he/mixer_he.h b/engines/scumm/he/mixer_he.h
index 3be7dda740e..93a43e00bb9 100644
--- a/engines/scumm/he/mixer_he.h
+++ b/engines/scumm/he/mixer_he.h
@@ -210,7 +210,7 @@ public:
 	bool mixerStartSpoolingChannel(
 		int channel, int song, Common::File &sampleFileIOHandle, int sampleLen, int frequency,
 		int volume, int callbackID, uint32 flags);
-	byte mixerGetOutputFlags();
+	byte mixerGetOutputFlags(bool is3DOMusic = false);
 };
 
 } // End of namespace Scumm
diff --git a/engines/scumm/he/sound_he.cpp b/engines/scumm/he/sound_he.cpp
index 2064d15b902..e913f610256 100644
--- a/engines/scumm/he/sound_he.cpp
+++ b/engines/scumm/he/sound_he.cpp
@@ -199,8 +199,14 @@ int SoundHE::isSoundRunning(int sound) const {
 			}
 		} else if (sound == -1) {
 			sound = _currentMusic;
-			if (_vm->_musicEngine && _vm->_musicEngine->getSoundStatus(sound))
+
+			if (_vm->_musicEngine && _vm->_musicEngine->getSoundStatus(sound)) {
 				return sound;
+			}
+
+			if (is3DOSound(sound) && hsFindSoundChannel(sound) != -1) {
+				return sound;
+			}
 		} else if (sound > 0) {
 			if (hsFindSoundChannel(sound) != -1) {
 				return sound;
@@ -865,7 +871,9 @@ void SoundHE::triggerSound(int soundId, int heOffset, int heChannel, int heFlags
 
 	byte *soundAddr = (byte *)_vm->getResourceAddress(rtSound, soundId);
 
-	if ((READ_BE_UINT32(soundAddr) == MKTAG('D', 'I', 'G', 'I')) || (READ_BE_UINT32(soundAddr) == MKTAG('T', 'A', 'L', 'K'))) {
+	if ((READ_BE_UINT32(soundAddr) == MKTAG('D', 'I', 'G', 'I')) ||
+		(READ_BE_UINT32(soundAddr) == MKTAG('T', 'A', 'L', 'K')) ||
+		(READ_BE_UINT32(soundAddr) == MKTAG('M', 'R', 'A', 'W'))) {
 		triggerDigitalSound(soundId, heOffset, heChannel, heFlags);
 	} else if (READ_BE_UINT32(soundAddr) == MKTAG('M', 'I', 'D', 'I')) {
 		triggerMidiSound(soundId, heOffset);
@@ -1408,12 +1416,20 @@ void SoundHE::triggerDigitalSound(int sound, int offset, int channel, int flags)
 
 	debug(5, "SoundHE::triggerDigitalSound(sound=%d, offset=%d, channel=%d, flags=%08x)", sound, offset, channel, flags);
 
+	soundAddr = (byte *)_vm->getResourceAddress(rtSound, sound);
+
+	// Is this a MRAW music file from the 3DO games? Then update _currentMusic
+	// and throw the sound on the last channel, since otherwise speech will interrupt it...
+	if (READ_BE_UINT32(soundAddr) == MKTAG('M', 'R', 'A', 'W')) {
+		_currentMusic = sound;
+		channel = HSND_MAX_CHANNELS - 1;
+	}
+
 	// Don't let digital sounds interrupt speech...
 	if (_heChannel[channel].sound == HSND_TALKIE_SLOT && sound != HSND_TALKIE_SLOT) {
 		return;
 	}
 
-	soundAddr = (byte *)_vm->getResourceAddress(rtSound, sound);
 	soundPriority = soundAddr[HSND_RES_OFFSET_KILL_PRIO];
 
 	if (_vm->_game.heversion < 95 && _overrideFreq) {
@@ -1713,4 +1729,12 @@ int SoundHE::getCurrentSpeechOffset() {
 	return _heTalkOffset;
 }
 
+bool SoundHE::is3DOSound(int sound) const {
+	byte *soundAddr = _vm->getResourceAddress(rtSound, sound);
+	if (soundAddr == nullptr)
+		return false;
+
+	return READ_BE_UINT32(soundAddr) == MKTAG('M', 'R', 'A', 'W');
+}
+
 } // End of namespace Scumm
diff --git a/engines/scumm/he/sound_he.h b/engines/scumm/he/sound_he.h
index e24a99d50d4..2826f6b50e6 100644
--- a/engines/scumm/he/sound_he.h
+++ b/engines/scumm/he/sound_he.h
@@ -261,6 +261,7 @@ public:
 
 	const byte *findWavBlock(uint32 tag, const byte *block);
 	int getCurrentSpeechOffset();
+	bool is3DOSound(int sound) const;
 
 protected:
 	void processSoundQueues() override;




More information about the Scummvm-git-logs mailing list