From f2fbcecc5015b63968154d5133f21b3728e08b96 Mon Sep 17 00:00:00 2001 From: Lost Robot <34612565+LostRobotMusic@users.noreply.github.com> Date: Thu, 27 Jun 2024 00:18:24 -0500 Subject: [PATCH] Fix bad Granular Pitch Shifter init values (#7354) --- .../GranularPitchShifterEffect.cpp | 15 +++++++++++---- .../GranularPitchShifterEffect.h | 2 +- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/plugins/GranularPitchShifter/GranularPitchShifterEffect.cpp b/plugins/GranularPitchShifter/GranularPitchShifterEffect.cpp index edf24c332..90c6e86d3 100755 --- a/plugins/GranularPitchShifter/GranularPitchShifterEffect.cpp +++ b/plugins/GranularPitchShifter/GranularPitchShifterEffect.cpp @@ -96,8 +96,8 @@ bool GranularPitchShifterEffect::processAudioBuffer(sampleFrame* buf, const fpp_ for (fpp_t f = 0; f < frames; ++f) { - const double pitch = pitchBuf ? pitchBuf->value(f) : m_granularpitchshifterControls.m_pitchModel.value(); - const double pitchSpread = (pitchSpreadBuf ? pitchSpreadBuf->value(f) : m_granularpitchshifterControls.m_pitchSpreadModel.value()) * 0.5f; + const double pitch = (pitchBuf ? pitchBuf->value(f) : m_granularpitchshifterControls.m_pitchModel.value()) * (1. / 12.); + const double pitchSpread = (pitchSpreadBuf ? pitchSpreadBuf->value(f) : m_granularpitchshifterControls.m_pitchSpreadModel.value()) * (1. / 24.); // interpolate pitch depending on glide for (int i = 0; i < 2; ++i) @@ -118,8 +118,8 @@ bool GranularPitchShifterEffect::processAudioBuffer(sampleFrame* buf, const fpp_ m_updatePitches = false; std::array speed = { - std::exp2(m_truePitch[0] * (1. / 12.)), - std::exp2(m_truePitch[1] * (1. / 12.)) + std::exp2(m_truePitch[0]), + std::exp2(m_truePitch[1]) }; std::array ratio = { speed[0] / m_speed[0], @@ -274,6 +274,13 @@ void GranularPitchShifterEffect::changeSampleRate() m_grains.reserve(8);// arbitrary m_dcCoeff = std::exp(-2.0 * F_PI * DcRemovalHz / m_sampleRate); + + const double pitch = m_granularpitchshifterControls.m_pitchModel.value() * (1. / 12.); + const double pitchSpread = m_granularpitchshifterControls.m_pitchSpreadModel.value() * (1. / 24.); + m_truePitch[0] = pitch - pitchSpread; + m_truePitch[1] = pitch + pitchSpread; + m_speed[0] = std::exp2(m_truePitch[0]); + m_speed[1] = std::exp2(m_truePitch[1]); } diff --git a/plugins/GranularPitchShifter/GranularPitchShifterEffect.h b/plugins/GranularPitchShifter/GranularPitchShifterEffect.h index 111d0538d..a50ea8238 100755 --- a/plugins/GranularPitchShifter/GranularPitchShifterEffect.h +++ b/plugins/GranularPitchShifter/GranularPitchShifterEffect.h @@ -168,7 +168,7 @@ private: int m_ringBufLength = 0; int m_writePoint = 0; int m_grainCount = 0; - int m_timeSinceLastGrain = 0; + int m_timeSinceLastGrain = 999999999; double m_oldGlide = -1; double m_glideCoef = 0;