Correct SCALEVOLUME behavior

This commit is contained in:
Jack Andersen 2019-02-07 15:07:46 -10:00
parent fc2f8542c1
commit 54ef2dd73b
2 changed files with 5 additions and 4 deletions

View File

@ -96,6 +96,7 @@ class Voice : public Entity {
float m_targetUserVol = 1.f; /**< Target user volume of voice (slewed to prevent audible aliasing) */ float m_targetUserVol = 1.f; /**< Target user volume of voice (slewed to prevent audible aliasing) */
float m_curUserVol = 1.f; /**< Current user volume of voice */ float m_curUserVol = 1.f; /**< Current user volume of voice */
float m_curVol = 1.f; /**< Current volume of voice */ float m_curVol = 1.f; /**< Current volume of voice */
float m_envelopeVol = 1.f; /**< Current envelope volume of voice */
float m_curReverbVol = 0.f; /**< Current reverb volume of voice */ float m_curReverbVol = 0.f; /**< Current reverb volume of voice */
float m_curAuxBVol = 0.f; /**< Current AuxB volume of voice */ float m_curAuxBVol = 0.f; /**< Current AuxB volume of voice */
float m_curPan = 0.f; /**< Current pan of voice */ float m_curPan = 0.f; /**< Current pan of voice */

View File

@ -221,9 +221,9 @@ void Voice::_procSamplePre(int16_t& samp) {
float t = clamp(0.f, float(m_envelopeTime / m_envelopeDur), 1.f); float t = clamp(0.f, float(m_envelopeTime / m_envelopeDur), 1.f);
if (m_envelopeCurve && m_envelopeCurve->data.size() >= 128) if (m_envelopeCurve && m_envelopeCurve->data.size() >= 128)
t = m_envelopeCurve->data[t * 127.f] / 127.f; t = m_envelopeCurve->data[t * 127.f] / 127.f;
m_curVol = clamp(0.f, (start * (1.0f - t)) + (end * t), 1.f); m_envelopeVol = clamp(0.f, (start * (1.0f - t)) + (end * t), 1.f);
// printf("%d %f\n", m_vid, m_curVol); // printf("%d %f\n", m_vid, m_envelopeVol);
/* Done with envelope */ /* Done with envelope */
if (m_envelopeTime > m_envelopeDur) if (m_envelopeTime > m_envelopeDur)
@ -256,7 +256,7 @@ void Voice::_procSamplePre(int16_t& samp) {
/* Factor in ADSR envelope state */ /* Factor in ADSR envelope state */
float adsr = m_volAdsr.advance(dt, *this); float adsr = m_volAdsr.advance(dt, *this);
m_lastLevel = m_nextLevel; m_lastLevel = m_nextLevel;
m_nextLevel = m_curUserVol * m_curVol * adsr * (m_state.m_curVel / 127.f); m_nextLevel = m_curUserVol * m_curVol * m_envelopeVol * adsr * (m_state.m_curVel / 127.f);
/* Apply tremolo */ /* Apply tremolo */
if (m_state.m_tremoloSel && (m_tremoloScale || m_tremoloModScale)) { if (m_state.m_tremoloSel && (m_tremoloScale || m_tremoloModScale)) {
@ -1060,7 +1060,7 @@ void Voice::setChannelCoefs(const float coefs[8]) {
void Voice::startEnvelope(double dur, float vol, const Curve* envCurve) { void Voice::startEnvelope(double dur, float vol, const Curve* envCurve) {
m_envelopeTime = 0.f; m_envelopeTime = 0.f;
m_envelopeDur = dur; m_envelopeDur = dur;
m_envelopeStart = clamp(0.f, m_curVol, 1.f); m_envelopeStart = clamp(0.f, m_envelopeVol, 1.f);
m_envelopeEnd = clamp(0.f, vol, 1.f); m_envelopeEnd = clamp(0.f, vol, 1.f);
m_envelopeCurve = envCurve; m_envelopeCurve = envCurve;
} }