11#include <unordered_map>
23constexpr double inf = std::numeric_limits<
double>::infinity();
29constexpr double pi = 3.14159265358979323846;
73inline std::ostream& operator<< (std::ostream& os,
Oversampling oversampling)
75 return os <<
"Oversampling::x" <<
static_cast<
int> (oversampling);
79template<
typename FloatType>
82 return std::numeric_limits<FloatType>::quiet_NaN();
86template <
typename NumericType>
87NumericType
clamp (
const NumericType& value,
const NumericType& low,
const NumericType& high)
89 return std::min<NumericType> (std::max<NumericType> (value, low), high);
95template <
typename SampleType>
101 return std::pow (
static_cast<SampleType> (10), valueDb /
static_cast<SampleType> (20));
107template <
typename SampleType>
110 if (valueLinear < 1e-6)
113 return static_cast<SampleType> (20 * std::log10 (valueLinear));
119template <
typename SampleType>
125 return std::pow (
static_cast<SampleType> (10), valueDb /
static_cast<SampleType> (10));
131template <
typename SampleType>
134 if (valueLinear < 1e-12)
137 return static_cast<SampleType> (10 * std::log10 (valueLinear));
141template <
typename SampleType>
142inline static SampleType
floatsEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
144 return std::abs (a - b) < epsilon;
148template <
typename SampleType>
149inline static SampleType
floatsNotEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
151 return std::abs (a - b) >= epsilon;
155template <
typename SampleType>
158 return static_cast<size_t> (x + (SampleType) 0.5);
162inline double addCents (
double baseFrequencyHz,
double cents)
164 return baseFrequencyHz * std::pow (2.0, cents / 1200.0);
168template <
typename SampleType>
171 SampleType wrappedPhaseRadians = std::remainder (phaseRadians, (SampleType)
hart::twoPi);
173 if (wrappedPhaseRadians < 0.0)
176 return wrappedPhaseRadians;
185 if (path[0] ==
'/' || path[0] ==
'\\')
189 if (path.size() > 1 && std::isalpha (path[0]) && path[1] ==
':')
207template <
typename KeyType,
typename ValueType>
208inline static bool contains (
const std::unordered_map<KeyType, ValueType>& map,
const KeyType& key)
210 return map.find (key) != map.end();
215template<
typename ObjectType,
typename... Args>
218 return std::unique_ptr<ObjectType> (
new ObjectType (std::forward<Args> (args)...));
224#if defined(__cpp_lib_uncaught_exceptions
)
225 return std::uncaught_exceptions() > 0;
227 return std::uncaught_exception();
236#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
237 virtual void represent(std::ostream& stream) const override
239 stream << #ClassName "()";
243#if defined(__GNUC__
) || defined(__clang__
)
244 #define HART_DEPRECATED(msg) __attribute__((deprecated(msg)))
245#elif defined(_MSC_VER)
246 #define HART_DEPRECATED(msg) __declspec(deprecated(msg))
248 #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.
Interpolation
Interpolation method.
std::unique_ptr< ObjectType > make_unique(Args &&... args)
std::make_unique() replacement for C++11
static SampleType powerToDecibels(SampleType valueLinear)
Converts linear value (power) to dB.
double addCents(double baseFrequencyHz, double cents)
Anns an offset in cents to a frequency in Hz.
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 bool isExceptionUnwinding()
Returns true if an exception is currently being unwound.
static SampleType floatsEqual(SampleType a, SampleType b, SampleType epsilon=(SampleType) 1e-8)
Compares two floating point numbers within a given tolerance.
static SampleType decibelsToPower(SampleType valueDb)
Converts dB to linear value (power)
Oversampling
Oversampling ratio.
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.