From 6213f3da599e7dab091b20bd3cf6f12a97a7bf03 Mon Sep 17 00:00:00 2001 From: brunoherbelin Date: Fri, 28 Aug 2020 22:29:20 +0200 Subject: [PATCH] Fixed interpolation alpha in timeline --- Timeline.cpp | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/Timeline.cpp b/Timeline.cpp index 95d9b04..b993417 100644 --- a/Timeline.cpp +++ b/Timeline.cpp @@ -1,6 +1,6 @@ #include - +#include #include "defines.h" #include "Log.h" @@ -194,14 +194,13 @@ void Timeline::clearGaps() float Timeline::fadingAt(const GstClockTime t) { - GstClockTime modulo = t % step_; - GstClockTime keyframe = t - modulo; - size_t keyframe_index = CLAMP( (MAX_TIMELINE_ARRAY * keyframe) / timing_.end, 0, MAX_TIMELINE_ARRAY-1); + double true_index = (static_cast(MAX_TIMELINE_ARRAY) * static_cast(t)) / static_cast(timing_.end); + double previous_index = floor(true_index); + float percent = static_cast(true_index - previous_index); + size_t keyframe_index = CLAMP( static_cast(previous_index), 0, MAX_TIMELINE_ARRAY-1); size_t keyframe_next_index = CLAMP( keyframe_index+1, 0, MAX_TIMELINE_ARRAY-1); - - float interpol = static_cast( static_cast(modulo) / static_cast(step_) ); float v = fadingArray_[keyframe_index]; - v += interpol * (fadingArray_[keyframe_next_index] - fadingArray_[keyframe_index]); + v += percent * (fadingArray_[keyframe_next_index] - fadingArray_[keyframe_index]); return v; }