From 41ba70fbb9dc5042da37395a9d7a28fd967036d0 Mon Sep 17 00:00:00 2001 From: Chris Cannam Date: Thu, 13 Jan 2022 08:42:56 +0000 Subject: [PATCH] Enforce range and integer hints on ratio controls, for predictability --- ladspa-lv2/RubberBandPitchShifter.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/ladspa-lv2/RubberBandPitchShifter.cpp b/ladspa-lv2/RubberBandPitchShifter.cpp index 3c9ce7e..801bbc1 100644 --- a/ladspa-lv2/RubberBandPitchShifter.cpp +++ b/ladspa-lv2/RubberBandPitchShifter.cpp @@ -496,10 +496,26 @@ RubberBandPitchShifter::activateImpl() void RubberBandPitchShifter::updateRatio() { - double oct = (m_octaves ? *m_octaves : 0.0); - oct += (m_semitones ? *m_semitones : 0.0) / 12; - oct += (m_cents ? *m_cents : 0.0) / 1200; - m_ratio = pow(2.0, oct); + // The octaves, semitones, and cents parameters are supposed to be + // integral: enforce that, just to avoid inconsistencies between + // hosts if some respect the hints more than others + + double octaves = round(m_octaves ? *m_octaves : 0.0); + if (octaves < -2.0) octaves = -2.0; + if (octaves > 2.0) octaves = 2.0; + + double semitones = round(m_semitones ? *m_semitones : 0.0); + if (semitones < -12.0) semitones = -12.0; + if (semitones > 12.0) semitones = 12.0; + + double cents = round(m_cents ? *m_cents : 0.0); + if (cents < -100.0) cents = -100.0; + if (cents > 100.0) cents = 100.0; + + m_ratio = pow(2.0, + octaves + + semitones / 12.0 + + cents / 1200.0); } void