9#include <unordered_map>
21constexpr double inf = std::numeric_limits<
double>::infinity();
27constexpr double pi = 3.14159265358979323846;
36template <
typename NumericType>
37NumericType
clamp (
const NumericType& value,
const NumericType& low,
const NumericType& high)
39 return std::min<NumericType> (std::max<NumericType> (value, low), high);
45template <
typename SampleType>
51 return std::pow (
static_cast<SampleType> (10), valueDb /
static_cast<SampleType> (20));
57template <
typename SampleType>
60 if (valueLinear < 1e-6)
63 return static_cast<SampleType> (20 * std::log10 (valueLinear));
67template <
typename SampleType>
68inline static SampleType
floatsEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
70 return std::abs (a - b) < epsilon;
74template <
typename SampleType>
75inline static SampleType
floatsNotEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
77 return std::abs (a - b) >= epsilon;
81template <
typename SampleType>
84 return static_cast<size_t> (x + (SampleType) 0.5);
88template <
typename SampleType>
91 SampleType wrappedPhaseRadians = std::remainder (phaseRadians, (SampleType)
hart::twoPi);
93 if (wrappedPhaseRadians < 0.0)
96 return wrappedPhaseRadians;
105 if (path[0] ==
'/' || path[0] ==
'\\')
109 if (path.size() > 1 && std::isalpha (path[0]) && path[1] ==
':')
127template <
typename KeyType,
typename ValueType>
128inline static bool contains (
const std::unordered_map<KeyType, ValueType>& map,
const KeyType& key)
130 return map.find (key) != map.end();
135template<
typename ObjectType,
typename... Args>
138 return std::unique_ptr<ObjectType> (
new ObjectType (std::forward<Args> (args)...));
145#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
146 virtual void represent(std::ostream& stream) const override
148 stream << #ClassName "()";
constexpr double twoPi
2 * pi
static bool isAbsolutePath(const std::string &path)
Checks if the provided file path is absolute.
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 @deials Relative paths are resolved based on a provided -...
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()