Files
UnrealEngineUWP/Engine/Plugins/Runtime/Metasound/Source/MetasoundStandardNodes/Public/MetasoundGain.h
jimmy smith 78a90297c2 Mixer Node for Metasounds
#jira UEAU-617
#rob.gay phil.popp aaron.mcleran

[CL 15197329 by jimmy smith in ue5-main branch]
2021-01-25 22:03:24 -04:00

125 lines
2.6 KiB
C++

// Copyright Epic Games, Inc. All Rights Reserved.
#pragma once
#include "MetasoundDataReference.h"
#include "MetasoundDataTypeRegistrationMacro.h"
namespace Metasound
{
/** Representation of a gain */
enum class EGainRepresentation : uint8
{
/** Gain in linear scale */
Linear,
/** Gain is in decibels */
Decibels
};
/** FGain represents a gain value. It provides clearly defined
* getters and setters as well as several convenience functions for
* converting gain to decibels.
*/
class FGain
{
public:
static constexpr const float DefaultGain = 1.0f;
/** Construct gain of 1 */
FGain()
: LinearGain(DefaultGain)
{
}
/** Construct a Gain with a given value and representation.
*
* @param InValue - The value of the gain at the given
* representation.
* @param InRep - The representation of the given value.
*/
FGain(float InValue, EGainRepresentation InRep)
: LinearGain(DefaultGain)
{
switch (InRep)
{
case EGainRepresentation::Decibels:
SetDecibels(InValue);
break;
case EGainRepresentation::Linear:
SetLinear(InValue);
break;
default:
checkNoEntry();
break;
}
}
/**
* FGain constructor used to pass in float literals from the metasound frontend.
*/
FGain(float InValue)
: FGain(InValue, EGainRepresentation::Linear)
{}
/** Implicit operator used for math operations. */
operator float() const
{
return LinearGain;
}
FGain& operator+=(const FGain& InOther)
{
LinearGain += InOther.GetLinear();
return *this;
}
FGain& operator-=(const FGain& InOther)
{
LinearGain -= InOther.GetLinear();
return *this;
}
FGain& operator*=(const FGain& InOther)
{
LinearGain *= InOther.GetLinear();
return *this;
}
FGain& operator/=(const FGain& InOther)
{
LinearGain /= InOther.GetLinear();
return *this;
}
/** Set the gain in decibels */
void SetDecibels(float InDecibels)
{
LinearGain = Audio::ConvertToLinear(InDecibels);
}
/** Get the gain in decibels */
float GetDecibels() const
{
return Audio::ConvertToLinear(LinearGain);
}
/** Set the gain in LinearScale */
void SetLinear(float InLinearScale)
{
LinearGain = InLinearScale;
}
/** Return the gain in LinearScale. */
float GetLinear() const
{
return LinearGain;
}
private:
float LinearGain = DefaultGain;
};
DECLARE_METASOUND_DATA_REFERENCE_TYPES(FGain, METASOUNDSTANDARDNODES_API, FGainTypeInfo, FGainReadRef, FGainWriteRef)
}