Better volume handling

This commit is contained in:
Jack Andersen 2017-02-05 17:21:38 -10:00
parent 2e7345f11d
commit aff8880595
3 changed files with 5 additions and 4 deletions

View File

@ -49,6 +49,7 @@ class Engine
std::unordered_map<uint16_t, std::tuple<AudioGroup*, int, const SFXGroupIndex::SFXEntry*>> m_sfxLookup; std::unordered_map<uint16_t, std::tuple<AudioGroup*, int, const SFXGroupIndex::SFXEntry*>> m_sfxLookup;
std::linear_congruential_engine<uint32_t, 0x41c64e6d, 0x3039, UINT32_MAX> m_random; std::linear_congruential_engine<uint32_t, 0x41c64e6d, 0x3039, UINT32_MAX> m_random;
int m_nextVid = 0; int m_nextVid = 0;
float m_masterVolume = 1.f;
AudioGroup* _addAudioGroup(const AudioGroupData& data, std::unique_ptr<AudioGroup>&& grp); AudioGroup* _addAudioGroup(const AudioGroupData& data, std::unique_ptr<AudioGroup>&& grp);
std::pair<AudioGroup*, const SongGroupIndex*> _findSongGroup(int groupId) const; std::pair<AudioGroup*, const SongGroupIndex*> _findSongGroup(int groupId) const;

View File

@ -388,7 +388,7 @@ std::shared_ptr<Sequencer> Engine::seqPlay(int groupId, int songId, const unsign
/** Set total volume of engine */ /** Set total volume of engine */
void Engine::setVolume(float vol) void Engine::setVolume(float vol)
{ {
m_backend.setVolume(vol); m_masterVolume = vol;
} }
/** Find voice from VoiceId */ /** Find voice from VoiceId */

View File

@ -192,7 +192,7 @@ std::list<std::shared_ptr<Voice>>::iterator Voice::_destroyVoice(std::list<std::
template <typename T> template <typename T>
static T ApplyVolume(float vol, T samp) static T ApplyVolume(float vol, T samp)
{ {
return samp * 0.5f * vol; return samp * 0.7f * vol;
} }
void Voice::_procSamplePre(int16_t& samp) void Voice::_procSamplePre(int16_t& samp)
@ -219,7 +219,7 @@ void Voice::_procSamplePre(int16_t& samp)
float l = clamp(0.f, m_lastLevel * (1.f - t) + m_nextLevel * t, 1.f); float l = clamp(0.f, m_lastLevel * (1.f - t) + m_nextLevel * t, 1.f);
/* Apply total volume to sample using decibel scale */ /* Apply total volume to sample using decibel scale */
samp = ApplyVolume(l, samp); samp = ApplyVolume(l * m_engine.m_masterVolume, samp);
return; return;
} }
@ -313,7 +313,7 @@ void Voice::_procSamplePre(int16_t& samp)
m_nextLevel = clamp(0.f, m_nextLevel, 1.f); m_nextLevel = clamp(0.f, m_nextLevel, 1.f);
/* Apply total volume to sample using decibel scale */ /* Apply total volume to sample using decibel scale */
samp = ApplyVolume(m_nextLevel, samp); samp = ApplyVolume(m_nextLevel * m_engine.m_masterVolume, samp);
} }
template <typename T> template <typename T>