Integrate -10dB volume curve

This commit is contained in:
Jack Andersen
2016-05-20 15:15:31 -10:00
parent 64ed5e2ea5
commit e2ee8c550f
3 changed files with 43 additions and 29 deletions

View File

@@ -201,6 +201,13 @@ std::list<std::shared_ptr<Voice>>::iterator Voice::_destroyVoice(Voice* voice)
return m_childVoices.erase(voice->m_engineIt);
}
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);
samp *= factor;
}
bool Voice::_advanceSample(int16_t& samp, int32_t& newPitch)
{
double dt = 1.0 / m_sampleRate;
@@ -251,8 +258,8 @@ bool Voice::_advanceSample(int16_t& samp, int32_t& newPitch)
}
}
/* Multiply sample with total volume */
samp = ClampFull<int16_t>(samp * totalVol);
/* Apple total volume to sample using decibel scale */
ApplyVolume(ClampFull<float>(totalVol), samp);
/* Process active pan-sweep */
if (m_panningTime >= 0.f)