Engine polyphony is checked in findFreeVoice()
This commit is contained in:
parent
ca7d74e841
commit
5139c648f0
2 changed files with 16 additions and 18 deletions
|
|
@ -659,7 +659,18 @@ sfz::Voice* sfz::Synth::findFreeVoice() noexcept
|
||||||
if (freeVoice != voices.end())
|
if (freeVoice != voices.end())
|
||||||
return freeVoice->get();
|
return freeVoice->get();
|
||||||
|
|
||||||
return {};
|
// Engine polyphony reached
|
||||||
|
Voice* stolenVoice = stealer.steal(absl::MakeSpan(voiceViewArray));
|
||||||
|
if (stolenVoice == nullptr)
|
||||||
|
return {};
|
||||||
|
|
||||||
|
auto tempSpan = resources.bufferPool.getStereoBuffer(samplesPerBlock);
|
||||||
|
SisterVoiceRing::applyToRing(stolenVoice, [&] (Voice* v) {
|
||||||
|
renderVoiceToOutputs(*v, *tempSpan);
|
||||||
|
v->reset();
|
||||||
|
});
|
||||||
|
|
||||||
|
return stolenVoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
int sfz::Synth::getNumActiveVoices(bool recompute) const noexcept
|
int sfz::Synth::getNumActiveVoices(bool recompute) const noexcept
|
||||||
|
|
@ -997,27 +1008,11 @@ void sfz::Synth::noteOnDispatch(int delay, int noteNumber, float velocity) noexc
|
||||||
}
|
}
|
||||||
|
|
||||||
Voice* selectedVoice = findFreeVoice();
|
Voice* selectedVoice = findFreeVoice();
|
||||||
|
|
||||||
// Engine polyphony reached, we're stealing something
|
|
||||||
if (selectedVoice == nullptr) {
|
|
||||||
selectedVoice = stealer.steal(absl::MakeSpan(voiceViewArray));
|
|
||||||
}
|
|
||||||
|
|
||||||
// For some reason we did not find a voice to use.
|
// For some reason we did not find a voice to use.
|
||||||
// This is a degraded case but we'll just drop the note on.
|
// This is a degraded case but we'll just drop the note on.
|
||||||
if (selectedVoice == nullptr)
|
if (selectedVoice == nullptr)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Kill voice if necessary, pre-rendering it into the output buffers
|
|
||||||
if (!selectedVoice->isFree()) {
|
|
||||||
auto tempSpan = resources.bufferPool.getStereoBuffer(samplesPerBlock);
|
|
||||||
SisterVoiceRing::applyToRing(selectedVoice, [&] (Voice* v) {
|
|
||||||
renderVoiceToOutputs(*v, *tempSpan);
|
|
||||||
v->reset();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Voice should be free now
|
|
||||||
ASSERT(selectedVoice->isFree());
|
ASSERT(selectedVoice->isFree());
|
||||||
selectedVoice->startVoice(region, delay, noteNumber, velocity, Voice::TriggerType::NoteOn);
|
selectedVoice->startVoice(region, delay, noteNumber, velocity, Voice::TriggerType::NoteOn);
|
||||||
ring.addVoiceToRing(selectedVoice);
|
ring.addVoiceToRing(selectedVoice);
|
||||||
|
|
|
||||||
|
|
@ -765,18 +765,21 @@ private:
|
||||||
using RegionSetPtr = std::unique_ptr<RegionSet>;
|
using RegionSetPtr = std::unique_ptr<RegionSet>;
|
||||||
std::vector<RegionPtr> regions;
|
std::vector<RegionPtr> regions;
|
||||||
std::vector<VoicePtr> voices;
|
std::vector<VoicePtr> voices;
|
||||||
|
|
||||||
// These are more general "groups" than sfz and encapsulates the full hierarchy
|
// These are more general "groups" than sfz and encapsulates the full hierarchy
|
||||||
RegionSet* currentSet;
|
RegionSet* currentSet;
|
||||||
OpcodeScope lastHeader { OpcodeScope::kOpcodeScopeGlobal };
|
OpcodeScope lastHeader { OpcodeScope::kOpcodeScopeGlobal };
|
||||||
std::vector<RegionSetPtr> sets;
|
std::vector<RegionSetPtr> sets;
|
||||||
|
|
||||||
// These are the `group=` groups where you can off voices
|
// These are the `group=` groups where you can off voices
|
||||||
std::vector<PolyphonyGroup> polyphonyGroups;
|
std::vector<PolyphonyGroup> polyphonyGroups;
|
||||||
|
|
||||||
// Views to speed up iteration over the regions and voices when events
|
// Views to speed up iteration over the regions and voices when events
|
||||||
// occur in the audio callback
|
// occur in the audio callback
|
||||||
VoiceViewVector regionPolyphonyArray;
|
VoiceViewVector regionPolyphonyArray;
|
||||||
|
VoiceViewVector voiceViewArray;
|
||||||
VoiceStealing stealer;
|
VoiceStealing stealer;
|
||||||
|
|
||||||
VoiceViewVector voiceViewArray;
|
|
||||||
std::array<RegionViewVector, 128> noteActivationLists;
|
std::array<RegionViewVector, 128> noteActivationLists;
|
||||||
std::array<RegionViewVector, config::numCCs> ccActivationLists;
|
std::array<RegionViewVector, config::numCCs> ccActivationLists;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue