Store the last number of active voices instead of computing it on each call to the getter

This commit is contained in:
Paul Ferrand 2020-07-18 13:33:12 +02:00 committed by Jean Pierre Cimalando
parent 2d7fbe365a
commit 4fadda23de
2 changed files with 4 additions and 8 deletions

View file

@ -627,11 +627,6 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept
int sfz::Synth::getNumActiveVoices() const noexcept int sfz::Synth::getNumActiveVoices() const noexcept
{ {
auto activeVoices = 0;
for (const auto& voice : voices) {
if (!voice->isFree())
activeVoices++;
}
return activeVoices; return activeVoices;
} }
@ -711,7 +706,7 @@ void sfz::Synth::renderBlock(AudioSpan<float> buffer) noexcept
return; return;
} }
int numActiveVoices { 0 }; activeVoices = 0;
{ // Main render block { // Main render block
ScopedTiming logger { callbackBreakdown.renderMethod, ScopedTiming::Operation::addToDuration }; ScopedTiming logger { callbackBreakdown.renderMethod, ScopedTiming::Operation::addToDuration };
tempSpan->fill(0.0f); tempSpan->fill(0.0f);
@ -730,7 +725,7 @@ void sfz::Synth::renderBlock(AudioSpan<float> buffer) noexcept
if (voice->isFree()) if (voice->isFree())
continue; continue;
numActiveVoices++; activeVoices++;
renderVoiceToOutputs(*voice, *tempSpan); renderVoiceToOutputs(*voice, *tempSpan);
callbackBreakdown.data += voice->getLastDataDuration(); callbackBreakdown.data += voice->getLastDataDuration();
callbackBreakdown.amplitude += voice->getLastAmplitudeDuration(); callbackBreakdown.amplitude += voice->getLastAmplitudeDuration();
@ -770,7 +765,7 @@ void sfz::Synth::renderBlock(AudioSpan<float> buffer) noexcept
} }
callbackBreakdown.dispatch = dispatchDuration; callbackBreakdown.dispatch = dispatchDuration;
resources.logger.logCallbackTime(callbackBreakdown, numActiveVoices, numFrames); resources.logger.logCallbackTime(callbackBreakdown, activeVoices, numFrames);
// Reset the dispatch counter // Reset the dispatch counter
dispatchDuration = Duration(0); dispatchDuration = Duration(0);

View file

@ -731,6 +731,7 @@ private:
float sampleRate { config::defaultSampleRate }; float sampleRate { config::defaultSampleRate };
float volume { Default::globalVolume }; float volume { Default::globalVolume };
int numVoices { config::numVoices }; int numVoices { config::numVoices };
int activeVoices { 0 };
Oversampling oversamplingFactor { config::defaultOversamplingFactor }; Oversampling oversamplingFactor { config::defaultOversamplingFactor };
// Distribution used to generate random value for the *rand opcodes // Distribution used to generate random value for the *rand opcodes