[Scummvm-git-logs] scummvm master -> 29487ad7e6007b0c1fb045e623f96522e1031d1e

yuv422 yuv422 at users.noreply.github.com
Fri Sep 4 05:58:26 UTC 2020


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:
29487ad7e6 DRAGONS: Fixed incorrect sfx pitch. Trac#11638


Commit: 29487ad7e6007b0c1fb045e623f96522e1031d1e
    https://github.com/scummvm/scummvm/commit/29487ad7e6007b0c1fb045e623f96522e1031d1e
Author: Eric Fry (yuv422 at users.noreply.github.com)
Date: 2020-09-04T15:54:28+10:00

Commit Message:
DRAGONS: Fixed incorrect sfx pitch. Trac#11638

Changed paths:
    engines/dragons/scene.cpp
    engines/dragons/sound.cpp
    engines/dragons/vabsound.cpp
    engines/dragons/vabsound.h


diff --git a/engines/dragons/scene.cpp b/engines/dragons/scene.cpp
index ba3a15e05a..26e68acd95 100644
--- a/engines/dragons/scene.cpp
+++ b/engines/dragons/scene.cpp
@@ -115,7 +115,7 @@ void Scene::loadSceneData(uint32 sceneId, uint32 cameraPointId) {
 	}
 
 	_actorManager->clearActorFlags(2);
-	//TODO sub_8003fadc(); might be fade related
+	//TODO stopAndCloseSceneVab()
 
 	_vm->_cursor->setActorFlag400();
 	_vm->_inventory->setActorFlag400();
diff --git a/engines/dragons/sound.cpp b/engines/dragons/sound.cpp
index 2bf6dc935e..8088325c66 100644
--- a/engines/dragons/sound.cpp
+++ b/engines/dragons/sound.cpp
@@ -437,13 +437,12 @@ void SoundManager::playSound(uint16 soundId, uint16 volumeId) {
 		stopVoicePlaying(soundId);
 	}
 
-	int16 vagID = vabSound->getVagID(program, key);
-	if (vagID >= 0) {
+	if (vabSound->hasSound(program, key)) {
 		Audio::SoundHandle *handle = getVoiceHandle(soundId);
 		if (handle) {
 			//TODO need to handle sfx where the requested key doesn't match the vag tone.
 			// We need to change pitch in this case.
-			_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, vabSound->getAudioStream(program, vagID), -1, _sfxVolume);
+			_vm->_mixer->playStream(Audio::Mixer::kSFXSoundType, handle, vabSound->getAudioStream(program, key), -1, _sfxVolume);
 		}
 	} else {
 		warning("Sound not found Program: %d, key %d", program, key);
diff --git a/engines/dragons/vabsound.cpp b/engines/dragons/vabsound.cpp
index 1589ac3dd8..3f6cb63c4c 100644
--- a/engines/dragons/vabsound.cpp
+++ b/engines/dragons/vabsound.cpp
@@ -19,6 +19,7 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  *
  */
+#include <cmath>
 #include "common/textconsole.h"
 #include "common/debug.h"
 #include "audio/decoders/xa.h"
@@ -101,11 +102,15 @@ VabSound::~VabSound() {
 	delete _vbData;
 }
 
-Audio::AudioStream *VabSound::getAudioStream(uint16 program, int16 vagID) {
-	debug(3, "Playing program %d, numTones: %d, vagID %d, vagOffset: %x, size: %x", program, _programAttrs[program].tones, vagID, _vagOffsets[vagID], _vagSizes[vagID]);
+Audio::AudioStream *VabSound::getAudioStream(uint16 program, uint16 key) {
+	int16 vagID = getVagID(program, key);
+	int16 baseKey = getBaseToneKey(program, key);
+	int sampleRate = getAdjustedSampleRate(key, baseKey);
+	debug(3, "Playing program %d, Key %d, numTones: %d, vagID %d, vagOffset: %x, size: %x adjustedSampleRate: %d",
+	   program, key, _programAttrs[program].tones, vagID, _vagOffsets[vagID], _vagSizes[vagID], sampleRate);
 	Audio::AudioStream *str = Audio::makeXAStream(
 			new Common::MemoryReadStream(&_vbData[_vagOffsets[vagID]], _vagSizes[vagID], DisposeAfterUse::NO),
-			11025,
+			sampleRate,
 			DisposeAfterUse::YES);
 	return str;
 }
@@ -159,10 +164,6 @@ int16 VabSound::getVagID(uint16 program, uint16 key) {
 	if (program < _header.numVAG) {
 		for (int i = 0; i < _programAttrs[program].tones; i++) {
 			if (_toneAttrs[i].prog == program && _toneAttrs[i].min <= key && _toneAttrs[i].max >= key) {
-				if (key != _toneAttrs[i].min) {
-					warning("Sfx key requested doesn't exactly match vab tone. TODO we need to change the playback pitch. key requested: %d tone match (min,max) (%d, %d)",
-						key, _toneAttrs[i].min, _toneAttrs[i].max);
-				}
 				return _toneAttrs[i].vag - 1;
 			}
 		}
@@ -173,4 +174,30 @@ int16 VabSound::getVagID(uint16 program, uint16 key) {
 	return -1;
 }
 
+int16 VabSound::getBaseToneKey(uint16 program, uint16 key) {
+	if (program < _header.numVAG) {
+		for (int i = 0; i < _programAttrs[program].tones; i++) {
+			if (_toneAttrs[i].prog == program && _toneAttrs[i].min <= key && _toneAttrs[i].max >= key) {
+				debug("tone key %d center %d mode %d shift %d min %d, max %d adsr 1 %d adsr 2 %d pbmin %d pbmax %d",
+		  			key, _toneAttrs[i].center, _toneAttrs[i].mode, _toneAttrs[i].shift, _toneAttrs[i].min, _toneAttrs[i].max,
+					  _toneAttrs[i].adsr1, _toneAttrs[i].adsr2, _toneAttrs[i].pbmin, _toneAttrs[i].pbmax);
+				return _toneAttrs[i].center;
+			}
+		}
+	}
+	return -1;
+}
+
+bool VabSound::hasSound(uint16 program, uint16 key) {
+	return getVagID(program, key) != -1;
+}
+
+int VabSound::getAdjustedSampleRate(int16 desiredKey, int16 baseToneKey) {
+	if (desiredKey == baseToneKey) {
+		return 44100;
+	}
+	float diff = pow(2, (float)(desiredKey - baseToneKey) / 12);
+	return (int)((float)44100 * diff);
+}
+
 } // End of namespace Dragons
diff --git a/engines/dragons/vabsound.h b/engines/dragons/vabsound.h
index 8406437f39..eaf422ec37 100644
--- a/engines/dragons/vabsound.h
+++ b/engines/dragons/vabsound.h
@@ -112,8 +112,8 @@ public:
 
 	~VabSound();
 
-	int16 getVagID(uint16 program, uint16 key);
-	Audio::AudioStream *getAudioStream(uint16 program, int16 vagID);
+	bool hasSound(uint16 program, uint16 key);
+	Audio::AudioStream *getAudioStream(uint16 program, uint16 key);
 
 private:
 	byte *_vbData;
@@ -128,6 +128,11 @@ private:
 	void loadHeader(Common::SeekableReadStream *vhData);
 	void loadProgramAttributes(Common::SeekableReadStream *vhData);
 	void loadToneAttributes(Common::SeekableReadStream *vhData);
+
+	int16 getVagID(uint16 program, uint16 key);
+	int16 getBaseToneKey(uint16 program, uint16 key);
+
+	int getAdjustedSampleRate(int16 desiredKey, int16 baseToneKey);
 };
 
 } // End of namespace Dragons




More information about the Scummvm-git-logs mailing list