From fbafa397fe9faadfc6f6c8b434e4f385bea4eac8 Mon Sep 17 00:00:00 2001 From: Jack Andersen Date: Sat, 21 May 2016 13:41:45 -1000 Subject: [PATCH] Use -10dB RMS formula for amplitude computation --- driver/main.cpp | 2 +- include/amuse/Envelope.hpp | 4 ++-- lib/SongState.cpp | 8 ++++---- lib/Voice.cpp | 3 ++- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/driver/main.cpp b/driver/main.cpp index 8af02f5..d09be62 100644 --- a/driver/main.cpp +++ b/driver/main.cpp @@ -191,7 +191,7 @@ struct AppCallback : boo::IApplicationCallback int8_t m_lastChanProg = -1; /* Control state */ - float m_volume = 0.5f; + float m_volume = 0.8f; float m_modulation = 0.f; float m_pitchBend = 0.f; bool m_updateDisp = false; diff --git a/include/amuse/Envelope.hpp b/include/amuse/Envelope.hpp index aa71862..4c26b6e 100644 --- a/include/amuse/Envelope.hpp +++ b/include/amuse/Envelope.hpp @@ -20,10 +20,10 @@ public: }; private: State m_phase = State::Attack; /**< Current envelope state */ - double m_attackTime = 0.01; /**< Time of attack in seconds */ + double m_attackTime = 0.005; /**< Time of attack in seconds */ double m_decayTime = 0.0; /**< Time of decay in seconds */ double m_sustainFactor = 1.0; /**< Evaluated sustain percentage */ - double m_releaseTime = 0.01; /**< Time of release in seconds */ + double m_releaseTime = 0.005; /**< Time of release in seconds */ double m_releaseStartFactor = 0.0; /**< Level at whenever release event occurs */ double m_curTime = 0.0; /**< Current time of envelope stage in seconds */ public: diff --git a/lib/SongState.cpp b/lib/SongState.cpp index 0f4f823..69dd309 100644 --- a/lib/SongState.cpp +++ b/lib/SongState.cpp @@ -179,9 +179,9 @@ bool SongState::Channel::advance(Sequencer& seq, int32_t ticks) /* See if there's an upcoming pitch change in this interval */ const unsigned char* ptr = m_pitchWheelData; uint32_t deltaTicks = DecodeRLE(ptr); - if (deltaTicks != -1) + if (deltaTicks != 0xffffffff) { - uint32_t nextTick = m_lastPitchTick + deltaTicks; + int32_t nextTick = m_lastPitchTick + deltaTicks; if (pitchTick + remPitchTicks > nextTick) { /* Update pitch */ @@ -212,9 +212,9 @@ bool SongState::Channel::advance(Sequencer& seq, int32_t ticks) /* See if there's an upcoming modulation change in this interval */ const unsigned char* ptr = m_modWheelData; uint32_t deltaTicks = DecodeRLE(ptr); - if (deltaTicks != -1) + if (deltaTicks != 0xffffffff) { - uint32_t nextTick = m_lastModTick + deltaTicks; + int32_t nextTick = m_lastModTick + deltaTicks; if (modTick + remModTicks > nextTick) { /* Update modulation */ diff --git a/lib/Voice.cpp b/lib/Voice.cpp index 9a265f8..7bc87e9 100644 --- a/lib/Voice.cpp +++ b/lib/Voice.cpp @@ -201,7 +201,8 @@ std::list>::iterator Voice::_destroyVoice(Voice* voice) static void ApplyVolume(float vol, int16_t& samp) { /* -10dB to 0dB mapped to full volume range */ - float factor = (std::pow(10.f, vol - 1.f) - 0.1f) * (1.f / 0.9f); + float factor = std::sqrt(std::pow(10.f, (vol - 1.f))) - 0.317f; + if (factor < 0.f) factor = 0.f; samp *= factor; }