From 7d20a4c870ab57d2561d1afd5de70b3ac7937230 Mon Sep 17 00:00:00 2001 From: Christian Semmler Date: Sat, 8 Jun 2024 13:35:12 -0400 Subject: [PATCH] Fix volume --- LEGO1/omni/include/mxsoundmanager.h | 2 +- LEGO1/omni/include/mxwavepresenter.h | 12 +++++------- LEGO1/omni/src/audio/mxsoundmanager.cpp | 10 +++++----- LEGO1/omni/src/audio/mxwavepresenter.cpp | 6 ++---- 4 files changed, 13 insertions(+), 17 deletions(-) diff --git a/LEGO1/omni/include/mxsoundmanager.h b/LEGO1/omni/include/mxsoundmanager.h index 092a5671..79aebd27 100644 --- a/LEGO1/omni/include/mxsoundmanager.h +++ b/LEGO1/omni/include/mxsoundmanager.h @@ -24,7 +24,7 @@ class MxSoundManager : public MxAudioManager { inline ma_engine* GetEngine() { return &m_engine; } - MxS32 GetAttenuation(MxU32 p_volume); + float GetAttenuation(MxU32 p_volume); protected: void Init(); diff --git a/LEGO1/omni/include/mxwavepresenter.h b/LEGO1/omni/include/mxwavepresenter.h index 63b8b053..e703a828 100644 --- a/LEGO1/omni/include/mxwavepresenter.h +++ b/LEGO1/omni/include/mxwavepresenter.h @@ -90,13 +90,11 @@ class MxWavePresenter : public MxSoundPresenter { WaveFormat* m_waveFormat; // 0x54 ma_pcm_rb m_rb; ma_sound m_sound; - MxU32 m_chunkLength; // 0x5c - MxU32 m_lockSize; // 0x60 - MxU8 m_writtenChunks; // 0x64 - MxBool m_started; // 0x65 - MxBool m_is3d; // 0x66 - MxS8 m_silenceData; // 0x67 - MxBool m_paused; // 0x68 + MxU32 m_chunkLength; // 0x5c + MxBool m_started; // 0x65 + MxBool m_is3d; // 0x66 + MxS8 m_silenceData; // 0x67 + MxBool m_paused; // 0x68 }; #endif // MXWAVEPRESENTER_H diff --git a/LEGO1/omni/src/audio/mxsoundmanager.cpp b/LEGO1/omni/src/audio/mxsoundmanager.cpp index 8010cb91..0e82fc9d 100644 --- a/LEGO1/omni/src/audio/mxsoundmanager.cpp +++ b/LEGO1/omni/src/audio/mxsoundmanager.cpp @@ -188,15 +188,15 @@ MxPresenter* MxSoundManager::FUN_100aebd0(const MxAtomId& p_atomId, MxU32 p_obje } // FUNCTION: LEGO1 0x100aecf0 -MxS32 MxSoundManager::GetAttenuation(MxU32 p_volume) +float MxSoundManager::GetAttenuation(MxU32 p_volume) { - // The unit for p_volume is percent, rounded to integer. - // Convert to DSOUND attenuation units: -10000 (silent) to 0 (loudest). + // [library:audio] Convert DSOUND attenutation units to linear miniaudio volume + if (p_volume == 0) { - return DSBVOLUME_MIN; + return 0.0f; } - return g_volumeAttenuation[p_volume - 1]; + return ma_volume_db_to_linear((float) g_volumeAttenuation[p_volume - 1] / 100.0f); } // FUNCTION: LEGO1 0x100aed10 diff --git a/LEGO1/omni/src/audio/mxwavepresenter.cpp b/LEGO1/omni/src/audio/mxwavepresenter.cpp index d3687cd0..1314d71a 100644 --- a/LEGO1/omni/src/audio/mxwavepresenter.cpp +++ b/LEGO1/omni/src/audio/mxwavepresenter.cpp @@ -22,8 +22,6 @@ void MxWavePresenter::Init() SDL_zero(m_rb); SDL_zero(m_sound); m_chunkLength = 0; - m_lockSize = 0; - m_writtenChunks = 0; m_started = FALSE; m_is3d = FALSE; m_paused = FALSE; @@ -267,7 +265,8 @@ void MxWavePresenter::SetVolume(MxS32 p_volume) m_volume = p_volume; if (ma_sound_get_engine(&m_sound)) { MxS32 volume = p_volume * MxOmni::GetInstance()->GetSoundManager()->GetVolume() / 100; - ma_sound_set_volume(&m_sound, (float) volume / 100.0f); + float attenuation = MxOmni::GetInstance()->GetSoundManager()->GetAttenuation(volume); + ma_sound_set_volume(&m_sound, attenuation); } m_criticalSection.Leave(); @@ -280,7 +279,6 @@ void MxWavePresenter::Enable(MxBool p_enable) MxSoundPresenter::Enable(p_enable); if (p_enable) { - m_writtenChunks = 0; m_started = FALSE; } else if (ma_sound_get_engine(&m_sound)) {