Move the voice rendering into a private method

This commit is contained in:
Paul Ferrand 2020-05-08 00:16:28 +02:00
parent ec13c70b82
commit 6df5b217c9
2 changed files with 23 additions and 22 deletions

View file

@ -512,14 +512,7 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept
auto tempSpan = resources.bufferPool.getStereoBuffer(samplesPerBlock);
const auto killVoice = [&] (Voice* v) {
const auto region = v->getRegion(); // voice can die after rendering, so save this
v->renderBlock(*tempSpan);
for (size_t i = 0, n = effectBuses.size(); i < n; ++i) {
if (auto& bus = effectBuses[i]) {
float addGain = region->getGainToEffectBus(i);
bus->addToInputs(*tempSpan, addGain, samplesPerBlock);
}
}
renderVoiceToOutputs(*v, *tempSpan);
v->reset();
};
@ -610,6 +603,19 @@ void sfz::Synth::setSampleRate(float sampleRate) noexcept
}
}
void sfz::Synth::renderVoiceToOutputs(Voice& voice, AudioSpan<float>& tempSpan) noexcept
{
const Region* region = voice.getRegion();
voice.renderBlock(tempSpan);
for (size_t i = 0, n = effectBuses.size(); i < n; ++i) {
if (auto& bus = effectBuses[i]) {
float addGain = region->getGainToEffectBus(i);
bus->addToInputs(tempSpan, addGain, tempSpan.getNumFrames());
}
}
}
void sfz::Synth::renderBlock(AudioSpan<float> buffer) noexcept
{
ScopedFTZ ftz;
@ -655,21 +661,8 @@ void sfz::Synth::renderBlock(AudioSpan<float> buffer) noexcept
if (voice->isFree())
continue;
const Region* region = voice->getRegion();
numActiveVoices++;
voice->renderBlock(*tempSpan);
{ // Add the output into the effects linked to this region
ScopedTiming logger { callbackBreakdown.effects, ScopedTiming::Operation::addToDuration };
for (size_t i = 0, n = effectBuses.size(); i < n; ++i) {
if (auto& bus = effectBuses[i]) {
float addGain = region->getGainToEffectBus(i);
bus->addToInputs(*tempSpan, addGain, numFrames);
}
}
}
renderVoiceToOutputs(*voice, *tempSpan);
callbackBreakdown.data += voice->getLastDataDuration();
callbackBreakdown.amplitude += voice->getLastAmplitudeDuration();
callbackBreakdown.filters += voice->getLastFilterDuration();

View file

@ -490,6 +490,14 @@ private:
*/
void resetVoices(int numVoices);
/**
* @brief Render the voice to its designated outputs and effect busses.
*
* @param voice
* @param tempSpan a temporary span used for rendering
*/
void renderVoiceToOutputs(Voice& voice, AudioSpan<float>& tempSpan) noexcept;
fs::file_time_type checkModificationTime();
void noteOnDispatch(int delay, int noteNumber, float velocity) noexcept;