diff --git a/src/config.cpp b/src/config.cpp index 5a6fc88..7a53d58 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -200,6 +200,8 @@ void CConfig::Load (void) m_bProfileEnabled = m_Properties.GetNumber ("ProfileEnabled", 0) != 0; m_bPerformanceSelectToLoad = m_Properties.GetNumber ("PerformanceSelectToLoad", 1) != 0; m_bPerformanceSelectChannel = m_Properties.GetNumber ("PerformanceSelectChannel", 0); + + m_nMasterVolume = m_Properties.GetNumber ("MasterVolume", 64); } unsigned CConfig::GetToneGenerators (void) const diff --git a/src/config.h b/src/config.h index 166a14e..b0735d3 100644 --- a/src/config.h +++ b/src/config.h @@ -239,6 +239,8 @@ public: bool GetPerformanceSelectToLoad (void) const; unsigned GetPerformanceSelectChannel (void) const; + unsigned GetMasterVolume() const { return m_nMasterVolume; } + private: CPropertiesFatFsFile m_Properties; @@ -353,6 +355,8 @@ private: bool m_bProfileEnabled; bool m_bPerformanceSelectToLoad; unsigned m_bPerformanceSelectChannel; + + unsigned m_nMasterVolume; // Master volume 0-127 }; #endif diff --git a/src/minidexed.cpp b/src/minidexed.cpp index f49c840..21709af 100644 --- a/src/minidexed.cpp +++ b/src/minidexed.cpp @@ -218,7 +218,8 @@ CMiniDexed::CMiniDexed (CConfig *pConfig, CInterruptSystem *pInterrupt, } #endif - setMasterVolume(1.0); + float masterVolNorm = (float)(pConfig->GetMasterVolume()) / 127.0f; + setMasterVolume(masterVolNorm); // BEGIN setup tg_mixer tg_mixer = new AudioStereoMixer(pConfig->GetChunkSize()/2); @@ -1800,14 +1801,17 @@ void CMiniDexed::getSysExVoiceDump(uint8_t* dest, uint8_t nTG) dest[162] = 0xF7; // SysEx end } -void CMiniDexed::setMasterVolume (float32_t vol) +void CMiniDexed::setMasterVolume(float32_t vol) { - if(vol < 0.0) - vol = 0.0; - else if(vol > 1.0) - vol = 1.0; + if (vol < 0.0) + vol = 0.0; + else if (vol > 1.0) + vol = 1.0; - nMasterVolume=vol; + // Apply logarithmic scaling to match perceived loudness + vol = powf(vol, 2.0f); + + nMasterVolume = vol; } std::string CMiniDexed::GetPerformanceFileName(unsigned nID) diff --git a/src/minidexed.ini b/src/minidexed.ini index 7fbb229..a20b41d 100644 --- a/src/minidexed.ini +++ b/src/minidexed.ini @@ -13,6 +13,8 @@ ChannelsSwapped=0 # Engine Type ( 1=Modern ; 2=Mark I ; 3=OPL ) EngineType=1 QuadDAC8Chan=0 +# Master Volume (0-127) +MasterVolume=64 # MIDI MIDIBaudRate=31250