Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(miles): pan a 3D sound to the side it is on

Olcay Seyganf57d08309052
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 71af1bb87..bd2f4682b 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1276,6 +1276,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same
- A death cry plays to the end. So does "construction complete", and the tail of a gun. Telling a sound to stop used to cut it off that frame, where the 2003 game let it finish and only kept it from repeating; our own fix for the audio thread broke that, and it is put back. A looping sound caught in the pause between two plays can be stopped too, instead of carrying on after whatever made it is gone.
- Your units answer you over the battle. A reply plays at whichever of the effects and voice sliders is higher, lifted again on top of that, so "Moving out" is heard in the middle of an artillery duel. Nothing else is turned down to make room for it. EVA and briefings stay where the voice slider puts them.
- Movies follow the voice volume slider. The volume was handed to the video before it was ready to take it, so every movie played at full level, and moving the slider while one was playing changed nothing.
+- A sound on the right of the screen comes out of the right speaker. Since the game went 64-bit its sound library worked left and right out the wrong way round, so a tank firing off to the right was heard on the left. Only a sound well off to one side swings far enough to notice, which is why it seemed to come and go.
- A sound at the edge of its range can fade out instead of stopping dead. The volume curve never
actually reaches zero, so a sound you are walking away from was cut off mid-note at the maximum
range. `RangeVolumeFade = Yes` in `AudioSettings.ini` uses a fade that reaches zero exactly where
diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/xaudio2/miles_xaudio2.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/xaudio2/miles_xaudio2.cpp
index 33886cd1d..be717490e 100644
--- a/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/xaudio2/miles_xaudio2.cpp
+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/Miles6/xaudio2/miles_xaudio2.cpp
@@ -371,10 +371,11 @@ void computeSpatialGain(const Sample &sample, float *volumeOut, float *panOut)
float pan = DEFAULT_PAN;
if (distance > 0.0001f) {
- // right = face x up, which is the axis a stereo pan actually moves along
- const float rightX = listener.faceY * listener.upZ - listener.faceZ * listener.upY;
- const float rightY = listener.faceZ * listener.upX - listener.faceX * listener.upZ;
- const float rightZ = listener.faceX * listener.upY - listener.faceY * listener.upX;
+ // right = up x face, the axis a stereo pan moves along. face x up is left in either
+ // handedness, and taking it sent every sound on the right of the screen to the left ear.
+ const float rightX = listener.upY * listener.faceZ - listener.upZ * listener.faceY;
+ const float rightY = listener.upZ * listener.faceX - listener.upX * listener.faceZ;
+ const float rightZ = listener.upX * listener.faceY - listener.upY * listener.faceX;
const float rightLength = (float)sqrt(rightX * rightX + rightY * rightY + rightZ * rightZ);
if (rightLength > 0.0001f) {
const float projection = (dx * rightX + dy * rightY + dz * rightZ) / (rightLength * distance);