9#include <unordered_map>
21constexpr double inf = std::numeric_limits<
double>::infinity();
27constexpr double pi = 3.14159265358979323846;
57template<
typename FloatType>
60 return std::numeric_limits<FloatType>::quiet_NaN();
64template <
typename NumericType>
65NumericType
clamp (
const NumericType& value,
const NumericType& low,
const NumericType& high)
67 return std::min<NumericType> (std::max<NumericType> (value, low), high);
73template <
typename SampleType>
79 return std::pow (
static_cast<SampleType> (10), valueDb /
static_cast<SampleType> (20));
85template <
typename SampleType>
88 if (valueLinear < 1e-6)
91 return static_cast<SampleType> (20 * std::log10 (valueLinear));
95template <
typename SampleType>
96inline static SampleType
floatsEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
98 return std::abs (a - b) < epsilon;
102template <
typename SampleType>
103inline static SampleType
floatsNotEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
105 return std::abs (a - b) >= epsilon;
109template <
typename SampleType>
112 return static_cast<size_t> (x + (SampleType) 0.5);
116template <
typename SampleType>
119 SampleType wrappedPhaseRadians = std::remainder (phaseRadians, (SampleType)
hart::twoPi);
121 if (wrappedPhaseRadians < 0.0)
124 return wrappedPhaseRadians;
133 if (path[0] ==
'/' || path[0] ==
'\\')
137 if (path.size() > 1 && std::isalpha (path[0]) && path[1] ==
':')
155template <
typename KeyType,
typename ValueType>
156inline static bool contains (
const std::unordered_map<KeyType, ValueType>& map,
const KeyType& key)
158 return map.find (key) != map.end();
163template<
typename ObjectType,
typename... Args>
166 return std::unique_ptr<ObjectType> (
new ObjectType (std::forward<Args> (args)...));
174#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
175 virtual void represent(std::ostream& stream) const override
177 stream << #ClassName "()";
181#if defined(__GNUC__
) || defined(__clang__
)
182 #define HART_DEPRECATED(msg) __attribute__((deprecated(msg)))
183#elif defined(_MSC_VER)
184 #define HART_DEPRECATED(msg) __declspec(deprecated(msg))
186 #define HART_DEPRECATED(msg)
constexpr double twoPi
2 * pi
static bool isAbsolutePath(const std::string &path)
Checks if the provided file path is absolute.
FloatType nan()
Returns a quiet NaN value for the given floating-point type.
Channel
Helper values for channel indices.
SampleType wrapPhase(const SampleType phaseRadians)
Keeps phase in 0..twoPi range.
static bool contains(const std::unordered_map< KeyType, ValueType > &map, const KeyType &key)
std::unordered_map::contains() replacement for C++11
constexpr double halfPi
pi / 2
static size_t roundToSizeT(SampleType x)
Rounds a floating point value to a size_t value.
constexpr double inf
Infinity.
static SampleType ratioToDecibels(SampleType valueLinear)
Converts linear value (ratio) to dB.
static SampleType floatsNotEqual(SampleType a, SampleType b, SampleType epsilon=(SampleType) 1e-8)
Compares two floating point numbers within a given tolerance.
MidSideChannel
Helper values for mid-side channel indices.
std::unique_ptr< ObjectType > make_unique(Args &&... args)
std::make_unique() replacement for C++11
NumericType clamp(const NumericType &value, const NumericType &low, const NumericType &high)
std::clamp() replacement for C++11
constexpr double oo
Infinity.
static std::string toAbsolutePath(const std::string &path)
Converts path to absolute, if it's relative.
static SampleType decibelsToRatio(SampleType valueDb)
Converts dB to linear value (ratio)
static SampleType floatsEqual(SampleType a, SampleType b, SampleType epsilon=(SampleType) 1e-8)
Compares two floating point numbers within a given tolerance.
Loop
Helper values for something that could loop, like a Signal.
Holds values set by the user via CLI interface.
std::string getDataRootPath()
Get data root path set by a "`--data-root-path`,`-d`" argument.
static CLIConfig & getInstance()
Get the singleton instance.