Fix volume

This commit is contained in:
Christian Semmler 2024-06-08 13:35:12 -04:00
parent 99f00f3898
commit 7d20a4c870
4 changed files with 13 additions and 17 deletions

View File

@ -24,7 +24,7 @@ class MxSoundManager : public MxAudioManager {
inline ma_engine* GetEngine() { return &m_engine; } inline ma_engine* GetEngine() { return &m_engine; }
MxS32 GetAttenuation(MxU32 p_volume); float GetAttenuation(MxU32 p_volume);
protected: protected:
void Init(); void Init();

View File

@ -91,8 +91,6 @@ class MxWavePresenter : public MxSoundPresenter {
ma_pcm_rb m_rb; ma_pcm_rb m_rb;
ma_sound m_sound; ma_sound m_sound;
MxU32 m_chunkLength; // 0x5c MxU32 m_chunkLength; // 0x5c
MxU32 m_lockSize; // 0x60
MxU8 m_writtenChunks; // 0x64
MxBool m_started; // 0x65 MxBool m_started; // 0x65
MxBool m_is3d; // 0x66 MxBool m_is3d; // 0x66
MxS8 m_silenceData; // 0x67 MxS8 m_silenceData; // 0x67

View File

@ -188,15 +188,15 @@ MxPresenter* MxSoundManager::FUN_100aebd0(const MxAtomId& p_atomId, MxU32 p_obje
} }
// FUNCTION: LEGO1 0x100aecf0 // 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. // [library:audio] Convert DSOUND attenutation units to linear miniaudio volume
// Convert to DSOUND attenuation units: -10000 (silent) to 0 (loudest).
if (p_volume == 0) { 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 // FUNCTION: LEGO1 0x100aed10

View File

@ -22,8 +22,6 @@ void MxWavePresenter::Init()
SDL_zero(m_rb); SDL_zero(m_rb);
SDL_zero(m_sound); SDL_zero(m_sound);
m_chunkLength = 0; m_chunkLength = 0;
m_lockSize = 0;
m_writtenChunks = 0;
m_started = FALSE; m_started = FALSE;
m_is3d = FALSE; m_is3d = FALSE;
m_paused = FALSE; m_paused = FALSE;
@ -267,7 +265,8 @@ void MxWavePresenter::SetVolume(MxS32 p_volume)
m_volume = p_volume; m_volume = p_volume;
if (ma_sound_get_engine(&m_sound)) { if (ma_sound_get_engine(&m_sound)) {
MxS32 volume = p_volume * MxOmni::GetInstance()->GetSoundManager()->GetVolume() / 100; 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(); m_criticalSection.Leave();
@ -280,7 +279,6 @@ void MxWavePresenter::Enable(MxBool p_enable)
MxSoundPresenter::Enable(p_enable); MxSoundPresenter::Enable(p_enable);
if (p_enable) { if (p_enable) {
m_writtenChunks = 0;
m_started = FALSE; m_started = FALSE;
} }
else if (ma_sound_get_engine(&m_sound)) { else if (ma_sound_get_engine(&m_sound)) {