From 862dfca73e6abdfd64cc4e4b6e0b7859540c7f20 Mon Sep 17 00:00:00 2001 From: Paul Ferrand Date: Fri, 13 Dec 2019 11:10:50 +0100 Subject: [PATCH] Added the pitch envelope on data generators --- src/sfizz/Voice.cpp | 29 ++++++++++++++++++++++++----- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/src/sfizz/Voice.cpp b/src/sfizz/Voice.cpp index 5a155f68..560266c1 100644 --- a/src/sfizz/Voice.cpp +++ b/src/sfizz/Voice.cpp @@ -96,7 +96,7 @@ void sfz::Voice::startVoice(Region* region, int delay, int channel, int number, widthEnvelope.reset(width); pitchBendEnvelope.setFunction([region](float pitchValue){ - const auto normalizedBend = normalizeBend(pitchValue); + const auto normalizedBend = -1 * normalizeBend(pitchValue); const auto bendInCents = normalizedBend > 0 ? normalizedBend * region->bendUp : normalizedBend * region->bendDown; return centsFactor(bendInCents); }); @@ -199,7 +199,6 @@ void sfz::Voice::registerPitchWheel(int delay, int channel, int pitch) noexcept return; pitchBendEnvelope.registerEvent(delay, pitch); - // TODO } void sfz::Voice::registerAftertouch(int delay [[maybe_unused]], int channel [[maybe_unused]], uint8_t aftertouch [[maybe_unused]]) noexcept @@ -367,10 +366,17 @@ void sfz::Voice::fillWithData(AudioSpan buffer) noexcept auto indices = indexSpan.first(buffer.getNumFrames()); auto jumps = tempSpan1.first(buffer.getNumFrames()); + auto bends = tempSpan2.first(buffer.getNumFrames()); auto leftCoeffs = tempSpan1.first(buffer.getNumFrames()); auto rightCoeffs = tempSpan2.first(buffer.getNumFrames()); fill(jumps, pitchRatio * speedRatio); + if (region->bendStep > 1) + pitchBendEnvelope.getQuantizedBlock(bends, region->bendStep); + else + pitchBendEnvelope.getBlock(bends); + + applyGain(bends, jumps); jumps[0] += floatPositionOffset; cumsum(jumps, jumps); sfzInterpolationCast(jumps, indices, leftCoeffs, rightCoeffs); @@ -446,10 +452,23 @@ void sfz::Voice::fillWithGenerator(AudioSpan buffer) noexcept if (buffer.getNumFrames() == 0) return; - float step = baseFrequency * twoPi / sampleRate; - phase = linearRamp(tempSpan1, phase, step); + auto jumps = tempSpan1.first(buffer.getNumFrames()); + auto bends = tempSpan2.first(buffer.getNumFrames()); + auto phases = tempSpan2.first(buffer.getNumFrames()); - sin(tempSpan1.first(buffer.getNumFrames()), buffer.getSpan(0)); + const float step = baseFrequency * twoPi / sampleRate; + fill(jumps, step); + + if (region->bendStep > 1) + pitchBendEnvelope.getQuantizedBlock(bends, region->bendStep); + else + pitchBendEnvelope.getBlock(bends); + applyGain(bends, jumps); + jumps[0] += phase; + cumsum(jumps, phases); + phase = phases.back(); + + sin(phases, buffer.getSpan(0)); copy(buffer.getSpan(0), buffer.getSpan(1)); // Wrap the phase so we don't loose too much precision on longer notes