Files
UnrealEngineUWP/Engine/Source/Runtime/SignalProcessing/Public/DSP/ParamInterpolator.h
rob gay 539f7a9217 Clean-up InterpolatedOnePole & expose target value in param interpolator
#rb maxwell.hayes
#rnx

#ROBOMERGE-SOURCE: CL 13062839 via CL 13062840 via CL 13062842
#ROBOMERGE-BOT: RELEASE (Release-Engine-Staging -> Main) (v686-13045012)

[CL 13062843 by rob gay in Main branch]
2020-04-28 23:48:04 -04:00

78 lines
1.5 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "CoreMinimal.h"
namespace Audio
{
class FParam
{
public:
FParam()
: CurrentValue(0.0f)
, StartingValue(0.0f)
, TargetValue(0.0f)
, DeltaValue(0.0f)
, bIsInit(true)
{}
// Set the parameter value to the given target value over the given interpolation frames.
FORCEINLINE void SetValue(const float InValue, const int32 InNumInterpFrames = 0)
{
TargetValue = InValue;
if (bIsInit || InNumInterpFrames == 0)
{
bIsInit = false;
StartingValue = TargetValue;
CurrentValue = TargetValue;
DeltaValue = 0.0f;
}
else
{
DeltaValue = (InValue - CurrentValue) / InNumInterpFrames;
StartingValue = CurrentValue;
}
}
FORCEINLINE void Init()
{
bIsInit = true;
}
// Resets the delta value back to 0.0. To be called at beginning of callback render.
FORCEINLINE void Reset()
{
DeltaValue = 0.0f;
CurrentValue = TargetValue;
}
// Updates the parameter, assumes called in one of the frames.
FORCEINLINE float Update()
{
CurrentValue += DeltaValue;
return CurrentValue;
}
// Returns the current value, but does not update the value
FORCEINLINE float GetValue() const
{
return CurrentValue;
}
// Returns the target value
FORCEINLINE float GetTarget() const
{
return TargetValue;
}
private:
float CurrentValue;
float StartingValue;
float TargetValue;
float DeltaValue;
bool bIsInit;
};
}