[Scummvm-git-logs] scummvm master -> f42bd8cb2de8ecc064feb4bef08a1da8b7fd24c1
fracturehill
noreply at scummvm.org
Thu Feb 23 20:21:11 UTC 2023
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:
7a1cc19b91 NANCY: Add support for panning stereo effect
f42bd8cb2d NANCY: Automatically calculate channel panning
Commit: 7a1cc19b91ae9aa894c6317a27afa7e7c185fd6c
https://github.com/scummvm/scummvm/commit/7a1cc19b91ae9aa894c6317a27afa7e7c185fd6c
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2023-02-23T22:20:12+02:00
Commit Message:
NANCY: Add support for panning stereo effect
Added support for sounds that pan in 360-degree space, as used in
The Vampire Diaries.
Changed paths:
engines/nancy/sound.cpp
engines/nancy/state/scene.cpp
engines/nancy/state/scene.h
diff --git a/engines/nancy/sound.cpp b/engines/nancy/sound.cpp
index 52d5abe2695..3beb7259389 100644
--- a/engines/nancy/sound.cpp
+++ b/engines/nancy/sound.cpp
@@ -421,10 +421,43 @@ void SoundManager::calculatePanForAllSounds() {
case 180:
_mixer->setChannelBalance(chan.handle, CLIP<int32>((viewportFrameID - chan.panAnchorFrame) * sceneSummary.soundPanPerFrame * 364, -32768, 32767) / 256);
break;
- case 360:
- // TODO
- _mixer->setChannelBalance(chan.handle, 0);
+ case 360: {
+ int16 adjustedViewportFrame = viewportFrameID - chan.panAnchorFrame;
+ if (adjustedViewportFrame < 0) {
+ adjustedViewportFrame += sceneSummary.numberOfVideoFrames;
+ }
+
+ // Divide the virtual space into quarters
+ uint16 q1 = sceneSummary.numberOfVideoFrames / 4;
+ uint16 q2 = sceneSummary.numberOfVideoFrames / 2;
+ uint16 q3 = sceneSummary.numberOfVideoFrames * 3 / 4;
+
+ float balance;
+
+ if (adjustedViewportFrame < q1) {
+ balance = (float)adjustedViewportFrame / q1;
+ balance *= 32767;
+ balance = 32768 - balance;
+ } else if (adjustedViewportFrame < q2) {
+ balance = (float)(adjustedViewportFrame - q1) / q1;
+ balance *= 32767;
+ } else if (adjustedViewportFrame < q3) {
+ balance = (float)(adjustedViewportFrame - q2) / q1;
+ balance *= 32767;
+ balance += 32768;
+ } else {
+ balance = (float)(adjustedViewportFrame - q3) / q1;
+ balance *= 32767;
+ balance = 65535 - balance;
+ }
+
+ // The original engine's algorithm is broken and results in flipped
+ // stereo; the following line fixes this bug
+ balance = 65535 - balance;
+
+ _mixer->setChannelBalance(chan.handle, (balance - 32768) / 256);
break;
+ }
default:
_mixer->setChannelBalance(chan.handle, 0);
break;
diff --git a/engines/nancy/state/scene.cpp b/engines/nancy/state/scene.cpp
index a19b67602da..471107984ab 100644
--- a/engines/nancy/state/scene.cpp
+++ b/engines/nancy/state/scene.cpp
@@ -73,7 +73,7 @@ void Scene::SceneSummary::read(Common::SeekableReadStream &stream) {
ser.skip(6);
ser.syncAsUint16LE(dontWrap);
- ser.syncAsUint16LE(soundWrapAroundPan);
+ ser.syncAsUint16LE(numberOfVideoFrames);
ser.syncAsUint16LE(soundPanPerFrame);
ser.syncAsUint16LE(totalViewAngle);
ser.syncAsUint16LE(horizontalScrollDelta);
diff --git a/engines/nancy/state/scene.h b/engines/nancy/state/scene.h
index 2627492685d..41c40387c51 100644
--- a/engines/nancy/state/scene.h
+++ b/engines/nancy/state/scene.h
@@ -95,7 +95,7 @@ public:
SoundDescription sound;
//
NancyFlag dontWrap;
- uint16 soundWrapAroundPan;
+ uint16 numberOfVideoFrames;
uint16 soundPanPerFrame;
uint16 totalViewAngle;
uint16 horizontalScrollDelta;
Commit: f42bd8cb2de8ecc064feb4bef08a1da8b7fd24c1
https://github.com/scummvm/scummvm/commit/f42bd8cb2de8ecc064feb4bef08a1da8b7fd24c1
Author: Kaloyan Chehlarski (strahy at outlook.com)
Date: 2023-02-23T22:20:12+02:00
Commit Message:
NANCY: Automatically calculate channel panning
Added a per-channel function to calculate the panning of a sound channel,
and made sure to have it automatically called any time a sound is played.
Changed paths:
engines/nancy/action/recordtypes.cpp
engines/nancy/sound.cpp
engines/nancy/sound.h
diff --git a/engines/nancy/action/recordtypes.cpp b/engines/nancy/action/recordtypes.cpp
index 479b81f06b4..0fc8df7ce18 100644
--- a/engines/nancy/action/recordtypes.cpp
+++ b/engines/nancy/action/recordtypes.cpp
@@ -552,7 +552,6 @@ void PlaySoundPanFrameAnchorAndDie::readData(Common::SeekableReadStream &stream)
void PlaySoundPanFrameAnchorAndDie::execute() {
g_nancy->_sound->loadSound(_sound, true);
g_nancy->_sound->playSound(_sound);
- g_nancy->_sound->calculatePanForAllSounds();
_isDone = true;
}
diff --git a/engines/nancy/sound.cpp b/engines/nancy/sound.cpp
index 3beb7259389..6fa924ab87f 100644
--- a/engines/nancy/sound.cpp
+++ b/engines/nancy/sound.cpp
@@ -324,6 +324,10 @@ void SoundManager::playSound(uint16 channelID) {
channelID,
chan.volume * 255 / 100,
0, DisposeAfterUse::NO);
+
+ if (chan.isPanning) {
+ calculatePan(channelID);
+ }
}
void SoundManager::playSound(const SoundDescription &description) {
@@ -411,61 +415,71 @@ void SoundManager::stopAllSounds() {
}
}
-void SoundManager::calculatePanForAllSounds() {
+void SoundManager::calculatePan(uint16 channelID) {
uint16 viewportFrameID = NancySceneState.getSceneInfo().frameID;
const State::Scene::SceneSummary &sceneSummary = NancySceneState.getSceneSummary();
- for (uint i = 0; i < 31; ++i) {
- Channel &chan = _channels[i];
- if (chan.isPanning) {
- switch (sceneSummary.totalViewAngle) {
- case 180:
- _mixer->setChannelBalance(chan.handle, CLIP<int32>((viewportFrameID - chan.panAnchorFrame) * sceneSummary.soundPanPerFrame * 364, -32768, 32767) / 256);
- break;
- case 360: {
- int16 adjustedViewportFrame = viewportFrameID - chan.panAnchorFrame;
- if (adjustedViewportFrame < 0) {
- adjustedViewportFrame += sceneSummary.numberOfVideoFrames;
- }
-
- // Divide the virtual space into quarters
- uint16 q1 = sceneSummary.numberOfVideoFrames / 4;
- uint16 q2 = sceneSummary.numberOfVideoFrames / 2;
- uint16 q3 = sceneSummary.numberOfVideoFrames * 3 / 4;
-
- float balance;
-
- if (adjustedViewportFrame < q1) {
- balance = (float)adjustedViewportFrame / q1;
- balance *= 32767;
- balance = 32768 - balance;
- } else if (adjustedViewportFrame < q2) {
- balance = (float)(adjustedViewportFrame - q1) / q1;
- balance *= 32767;
- } else if (adjustedViewportFrame < q3) {
- balance = (float)(adjustedViewportFrame - q2) / q1;
- balance *= 32767;
- balance += 32768;
- } else {
- balance = (float)(adjustedViewportFrame - q3) / q1;
- balance *= 32767;
- balance = 65535 - balance;
- }
-
- // The original engine's algorithm is broken and results in flipped
- // stereo; the following line fixes this bug
+ Channel &chan = _channels[channelID];
+ if (chan.isPanning) {
+ switch (sceneSummary.totalViewAngle) {
+ case 180:
+ _mixer->setChannelBalance(chan.handle, CLIP<int32>((viewportFrameID - chan.panAnchorFrame) * sceneSummary.soundPanPerFrame * 364, -32768, 32767) / 256);
+ break;
+ case 360: {
+ int16 adjustedViewportFrame = viewportFrameID - chan.panAnchorFrame;
+ if (adjustedViewportFrame < 0) {
+ adjustedViewportFrame += sceneSummary.numberOfVideoFrames;
+ }
+
+ // Divide the virtual space into quarters
+ uint16 q1 = sceneSummary.numberOfVideoFrames / 4;
+ uint16 q2 = sceneSummary.numberOfVideoFrames / 2;
+ uint16 q3 = sceneSummary.numberOfVideoFrames * 3 / 4;
+
+ float balance;
+
+ if (adjustedViewportFrame < q1) {
+ balance = (float)adjustedViewportFrame / q1;
+ balance *= 32767;
+ balance = 32768 - balance;
+ } else if (adjustedViewportFrame < q2) {
+ balance = (float)(adjustedViewportFrame - q1) / q1;
+ balance *= 32767;
+ } else if (adjustedViewportFrame < q3) {
+ balance = (float)(adjustedViewportFrame - q2) / q1;
+ balance *= 32767;
+ balance += 32768;
+ } else {
+ balance = (float)(adjustedViewportFrame - q3) / q1;
+ balance *= 32767;
balance = 65535 - balance;
+ }
+
+ // The original engine's algorithm is broken and results in flipped
+ // stereo; the following line fixes this bug
+ balance = 65535 - balance;
- _mixer->setChannelBalance(chan.handle, (balance - 32768) / 256);
- break;
- }
- default:
- _mixer->setChannelBalance(chan.handle, 0);
- break;
+ _mixer->setChannelBalance(chan.handle, (balance - 32768) / 256);
+ break;
}
+ default:
+ _mixer->setChannelBalance(chan.handle, 0);
+ break;
}
}
}
+void SoundManager::calculatePan(const SoundDescription &description) {
+ if (description.name != "NO SOUND") {
+ calculatePan(description.channelID);
+ }
+}
+
+void SoundManager::calculatePanForAllSounds() {
+ for (uint i = 0; i < 31; ++i) {
+ calculatePan(i);
+ }
+}
+
void SoundManager::stopAndUnloadSpecificSounds() {
// TODO missing if
diff --git a/engines/nancy/sound.h b/engines/nancy/sound.h
index 1cacf146bf1..3149a1e1d8f 100644
--- a/engines/nancy/sound.h
+++ b/engines/nancy/sound.h
@@ -65,6 +65,8 @@ public:
void stopSound(const Common::String &chunkName);
void stopAllSounds();
+ void calculatePan(uint16 channelID);
+ void calculatePan(const SoundDescription &description);
void calculatePanForAllSounds();
// Used when changing scenes
More information about the Scummvm-git-logs
mailing list