You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
66 lines
1.2 KiB
C++
66 lines
1.2 KiB
C++
// Copyright 1998-2017 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "DSP/ParamInterpolator.h"
|
|
|
|
namespace Audio
|
|
{
|
|
/**
|
|
* FParamInterpolator implementation
|
|
*/
|
|
|
|
FParamInterpolator::FParamInterpolator()
|
|
: StartValue(0.0f)
|
|
, EndValue(0.0f)
|
|
, CurrentTick(1.0f)
|
|
, NumTicksToNewValue(1.0f)
|
|
{
|
|
}
|
|
|
|
FParamInterpolator::~FParamInterpolator()
|
|
{
|
|
}
|
|
|
|
void FParamInterpolator::InitValue(const float InValue)
|
|
{
|
|
StartValue = InValue;
|
|
EndValue = InValue;
|
|
CurrentTick = 1.0f;
|
|
NumTicksToNewValue = 1.0f;
|
|
}
|
|
|
|
void FParamInterpolator::SetValue(const float InValue, const uint32 InNumInterpolationTicks)
|
|
{
|
|
EndValue = InValue;
|
|
if (InNumInterpolationTicks == 0)
|
|
{
|
|
NumTicksToNewValue = 1.0f;
|
|
CurrentTick = 1.0f;
|
|
}
|
|
else
|
|
{
|
|
NumTicksToNewValue = (float)InNumInterpolationTicks;
|
|
CurrentTick = 0.0f;
|
|
}
|
|
check(NumTicksToNewValue > 0.0f);
|
|
}
|
|
|
|
float FParamInterpolator::GetValue() const
|
|
{
|
|
float Alpha = FMath::Min(1.0f, CurrentTick / NumTicksToNewValue);
|
|
float Result = FMath::Lerp(StartValue, EndValue, Alpha);
|
|
return Result;
|
|
}
|
|
|
|
float FParamInterpolator::operator()()
|
|
{
|
|
if (CurrentTick >= NumTicksToNewValue)
|
|
{
|
|
return EndValue;
|
|
}
|
|
|
|
float Result = GetValue();
|
|
CurrentTick += 1.0f;
|
|
return Result;
|
|
}
|
|
}
|