9#include <unordered_map>
21constexpr double inf = std::numeric_limits<
double>::infinity();
27constexpr double pi = 3.14159265358979323846;
43template <
typename NumericType>
44NumericType
clamp (
const NumericType& value,
const NumericType& low,
const NumericType& high)
46 return std::min<NumericType> (std::max<NumericType> (value, low), high);
52template <
typename SampleType>
58 return std::pow (
static_cast<SampleType> (10), valueDb /
static_cast<SampleType> (20));
64template <
typename SampleType>
67 if (valueLinear < 1e-6)
70 return static_cast<SampleType> (20 * std::log10 (valueLinear));
74template <
typename SampleType>
75inline static SampleType
floatsEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
77 return std::abs (a - b) < epsilon;
81template <
typename SampleType>
82inline static SampleType
floatsNotEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
84 return std::abs (a - b) >= epsilon;
88template <
typename SampleType>
91 return static_cast<size_t> (x + (SampleType) 0.5);
95template <
typename SampleType>
98 SampleType wrappedPhaseRadians = std::remainder (phaseRadians, (SampleType)
hart::twoPi);
100 if (wrappedPhaseRadians < 0.0)
103 return wrappedPhaseRadians;
112 if (path[0] ==
'/' || path[0] ==
'\\')
116 if (path.size() > 1 && std::isalpha (path[0]) && path[1] ==
':')
134template <
typename KeyType,
typename ValueType>
135inline static bool contains (
const std::unordered_map<KeyType, ValueType>& map,
const KeyType& key)
137 return map.find (key) != map.end();
142template<
typename ObjectType,
typename... Args>
145 return std::unique_ptr<ObjectType> (
new ObjectType (std::forward<Args> (args)...));
153#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
154 virtual void represent(std::ostream& stream) const override
156 stream << #ClassName "()";
constexpr double twoPi
2 * pi
static bool isAbsolutePath(const std::string &path)
Checks if the provided file path is absolute.
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.
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.
std::string getDataRootPath()
static CLIConfig & getInstance()