Fix animation audio playing ~1.5x too fast with 3D sound enabled

Camera animations compute high listener velocities via
CalculateWorldVelocity, and miniaudio's default Doppler factor of 1.0
shifts the pitch/speed of all spatialized sounds accordingly. Disable
Doppler on sounds created by the multiplayer AudioPlayer using a friend
class to access LegoCacheSound's private ma_sound handle.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Christian Semmler 2026-03-26 19:33:32 -07:00
parent 08f44b9a93
commit 892fb808b6
No known key found for this signature in database
GPG Key ID: 086DAA1360BEEE5C
3 changed files with 9 additions and 0 deletions

View File

@ -2,6 +2,7 @@
#define LEGOCACHSOUND_H
#include "decomp.h"
#include "extensions/fwd.h"
#include "lego3dsound.h"
#include "mxcore.h"
#include "mxstring.h"
@ -58,6 +59,8 @@ class LegoCacheSound : public MxCore {
// LegoCacheSound::`scalar deleting destructor'
private:
friend class Multiplayer::Animation::AudioPlayer;
void Init();
void CopyData(MxU8* p_data, MxU32 p_dataSize);
MxString GetBaseFilename(MxString& p_path);

View File

@ -22,6 +22,7 @@ class NetworkManager;
class WorldStateSync;
namespace Animation
{
class AudioPlayer;
class Catalog;
class Controller;
} // namespace Animation

View File

@ -13,6 +13,11 @@ void AudioPlayer::Init(const std::vector<SceneAnimData::AudioTrack>& p_tracks)
MxWavePresenter::WaveFormat format = audioTrack.format;
if (sound->Create(format, mediaSrcPath, audioTrack.volume, audioTrack.pcmData, audioTrack.pcmDataSize) ==
SUCCESS) {
// Disable Doppler on extension-created sounds. Camera animations drive high
// listener velocities via CalculateWorldVelocity, and miniaudio's default
// dopplerFactor of 1.0 shifts the pitch/speed of spatialized sounds.
ma_sound_set_doppler_factor(sound->m_cacheSound, 0);
ActiveSound active;
active.sound = sound;
active.timeOffset = audioTrack.timeOffset;