Quickly fade out samples of a stopping voice
Rather than linearly fading out the mix over the mixing update, logarithmically fade out the post-resampled samples by approx -60dB per millisecond.
This commit is contained in:
@@ -497,6 +497,15 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
}
|
||||
}
|
||||
|
||||
float fadeCoeff{1.0f}, fadeGain{1.0f};
|
||||
if UNLIKELY(vstate == Stopping)
|
||||
{
|
||||
/* Calculate the multiplier for fading the resampled signal by -60dB
|
||||
* over 1ms.
|
||||
*/
|
||||
fadeCoeff = std::pow(0.001f, 1000.0f/static_cast<float>(Device->Frequency));
|
||||
}
|
||||
|
||||
uint buffers_done{0u};
|
||||
uint OutPos{0u};
|
||||
do {
|
||||
@@ -572,6 +581,7 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
}
|
||||
}
|
||||
|
||||
const float fadeVal{fadeGain};
|
||||
ASSUME(DstBufferSize > 0);
|
||||
for(auto &chandata : mChans)
|
||||
{
|
||||
@@ -621,6 +631,16 @@ void Voice::mix(const State vstate, ALCcontext *Context, const uint SamplesToDo)
|
||||
chandata.mAmbiSplitter.processHfScale({ResampledData, DstBufferSize},
|
||||
chandata.mAmbiScale);
|
||||
|
||||
if UNLIKELY(vstate == Stopping)
|
||||
{
|
||||
fadeGain = fadeVal;
|
||||
for(float &sample : al::span<float>{ResampledData, DstBufferSize})
|
||||
{
|
||||
fadeGain *= fadeCoeff;
|
||||
sample *= fadeGain;
|
||||
}
|
||||
}
|
||||
|
||||
/* Now filter and mix to the appropriate outputs. */
|
||||
float (&FilterBuf)[BufferLineSize] = Device->FilteredData;
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user