Cache the region pitch keycenter at voice start

This commit is contained in:
Paul Fd 2021-04-01 06:44:45 +02:00
parent 6826024ee2
commit 78db0b73db
4 changed files with 8 additions and 6 deletions

View file

@ -53,9 +53,9 @@ sfz::Region::Region(int regionNumber, absl::string_view defaultPath)
case hash(x "_stepcc&"): \
case hash(x "_smoothcc&")
bool sfz::Region::parseOpcode(const Opcode& rawOpcode, bool rtSafe)
bool sfz::Region::parseOpcode(const Opcode& rawOpcode, bool cleanOpcode)
{
const Opcode opcode = rtSafe ? rawOpcode : rawOpcode.cleanUp(kOpcodeScopeRegion);
const Opcode opcode = cleanOpcode ? rawOpcode.cleanUp(kOpcodeScopeRegion) : rawOpcode;
switch (opcode.lettersOnlyHash) {

View file

@ -186,11 +186,11 @@ struct Region {
* This must be called multiple times for each opcode applying to this region.
*
* @param opcode
* @param rtSafe whether the processing has to be real-time safe
* @param cleanOpcode whether the opcode should be canonicalized
* @return true if the opcode was properly read and stored.
* @return false
*/
bool parseOpcode(const Opcode& opcode, bool rtSafe = false);
bool parseOpcode(const Opcode& opcode, bool cleanOpcode = true);
/**
* @brief Parse a opcode which is specific to a particular SFZv1 LFO:
* amplfo, pitchlfo, fillfo.

View file

@ -902,7 +902,7 @@ void Synth::Impl::updateRegions() noexcept
if (!update.region)
continue;
update.region->parseOpcode(update.opcode, true);
update.region->parseOpcode(update.opcode, false);
}
regionUpdates_.clear();

View file

@ -222,6 +222,7 @@ struct Voice::Impl
float baseVolumedB_ { 0.0 };
float baseGain_ { 1.0 };
float baseFrequency_ { 440.0 };
uint8_t pitchKeycenter_ { Default::key };
float floatPositionOffset_ { 0.0f };
int sourcePosition_ { 0 };
@ -467,6 +468,7 @@ bool Voice::startVoice(Layer* layer, int delay, const TriggerEvent& event) noexc
if (resources.stretch)
impl.pitchRatio_ *= resources.stretch->getRatioForFractionalKey(numberRetuned);
impl.pitchKeycenter_ = region.pitchKeycenter;
impl.baseVolumedB_ = region.getBaseVolumedB(resources.midiState, impl.triggerEvent_.number);
impl.baseGain_ = region.getBaseGain();
if (impl.triggerEvent_.type != TriggerEventType::CC)
@ -1425,7 +1427,7 @@ void Voice::Impl::fillWithGenerator(AudioSpan<float> buffer) noexcept
if (!frequencies)
return;
float keycenterFrequency = midiNoteFrequency(region_->pitchKeycenter);
float keycenterFrequency = midiNoteFrequency(pitchKeycenter_);
fill(*frequencies, pitchRatio_ * keycenterFrequency);
pitchEnvelope(*frequencies);