From 6ba96e9a60428676fdf5cf6060e5d981ba1f3976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Sat, 21 Jul 2018 14:35:36 +0200 Subject: Switch latency_stddev to be samplerate independent (and thus in ms). Visualization seems correct but I didn't verify the math. --- plugingui/humaniservisualiser.cc | 2 +- plugingui/timingframecontent.cc | 12 ++---------- src/latencyfilter.cc | 19 ++++++------------- src/latencyfilter.h | 2 +- src/settings.h | 14 +++++++------- 5 files changed, 17 insertions(+), 32 deletions(-) diff --git a/plugingui/humaniservisualiser.cc b/plugingui/humaniservisualiser.cc index fd643d4..f0c016a 100644 --- a/plugingui/humaniservisualiser.cc +++ b/plugingui/humaniservisualiser.cc @@ -105,7 +105,7 @@ void HumaniserVisualiser::Canvas::repaintEvent(GUI::RepaintEvent *repaintEvent) float v = (-1.0f * velocity_offset + 1.0f) * 0.8; int y = height() * 0.2 + v * height(); y = std::max(0, y); - int w = latency_stddev / spx * 3 * 2; // stddev is ~ +/- 3 span + int w = 50.f * latency_stddev / spx * 3 * 2; // stddev is ~ +/- 3 span int h = velocity_stddev * height() / 4; DEBUG(vis, "max: %d, spx: %d, x: %d, w: %d", latency_max_samples, spx, x, w); diff --git a/plugingui/timingframecontent.cc b/plugingui/timingframecontent.cc index 835356d..50a5da3 100644 --- a/plugingui/timingframecontent.cc +++ b/plugingui/timingframecontent.cc @@ -86,20 +86,12 @@ TimingframeContent::TimingframeContent(Widget* parent, float TimingframeContent::thightnessKnobToSettings(float value) const { - value -= 1.0f; - value *= -1.0f; - value *= 500.0f; - - return value; + return (1.f - value)*10.f; } float TimingframeContent::tightnessSettingsToKnob(float value) const { - value /= 500.0f; - value *= -1.0f; - value += 1.0f; - - return value; + return 1.f - (value/10.f); } void TimingframeContent::tightnessKnobValueChanged(float value) diff --git a/src/latencyfilter.cc b/src/latencyfilter.cc index abb67cd..9410b50 100644 --- a/src/latencyfilter.cc +++ b/src/latencyfilter.cc @@ -73,21 +73,14 @@ bool LatencyFilter::filter(event_t& event, std::size_t pos) latency_last_pos = pos; - float offset_min = latency * -1.0f; - float offset_max = latency * 1.0f; - - float mean = 0.0f;//latency_laid_back; - float stddev = latency_stddev; - - float offset = random.normalDistribution(mean, stddev); - - latency_offset += offset; - - if(latency_offset > offset_max) latency_offset = offset_max; - if(latency_offset < offset_min) latency_offset = offset_min; + float offset_min = -latency; + float offset_max = latency; + float offset_ms = random.normalDistribution(0.0f, latency_stddev); + latency_offset += getLatencySamples(offset_ms, samplerate); + latency_offset = std::max(offset_min, std::min(offset_max, latency_offset)); DEBUG(offset, "latency: %d, offset: %f, drift: %f", - (int)latency, offset, latency_offset); + (int)latency, offset_ms, latency_offset); event.offset += latency; // fixed latency offset event.offset += latency_laid_back; // laid back offset (user controlled) diff --git a/src/latencyfilter.h b/src/latencyfilter.h index a49dd47..8191276 100644 --- a/src/latencyfilter.h +++ b/src/latencyfilter.h @@ -44,6 +44,6 @@ public: private: Settings& settings; Random& random; - double latency_offset{0.0}; + float latency_offset{0.0}; std::size_t latency_last_pos{0}; }; diff --git a/src/settings.h b/src/settings.h index 6b4048c..f37a810 100644 --- a/src/settings.h +++ b/src/settings.h @@ -111,13 +111,13 @@ struct Settings static float constexpr latency_laid_back_ms_default = 0.0f; Atomic latency_laid_back_ms{latency_laid_back_ms_default}; - //! 0 := Robot - //! 100 := Good drummer - //! 200 := Decent drummer - //! 300 := Decent drummer on a bad day - //! 400 := Bad drummer - //! 500 := Bad and drunk drummer - static float constexpr latency_stddev_default = 100.0f; + //! 0.0 := Robot + //! 2.0 := Good drummer + //! 4.0 := Decent drummer + //! 6.0 := Decent drummer on a bad day + //! 8.0 := Bad drummer + //! 10.0 := Bad and drunk drummer + static float constexpr latency_stddev_default = 2.0f; Atomic latency_stddev{latency_stddev_default}; //! Regain on-beat position. -- cgit v1.2.3