12#include <unordered_map>
24constexpr double inf = std::numeric_limits<
double>::infinity();
30constexpr double pi = 3.14159265358979323846;
81inline std::ostream& operator<< (std::ostream& os,
Oversampling oversampling)
83 return os <<
"Oversampling::x" <<
static_cast<
int> (oversampling);
87template<
typename FloatType>
90 return std::numeric_limits<FloatType>::quiet_NaN();
94template <
typename NumericType>
95NumericType
clamp (
const NumericType& value,
const NumericType& low,
const NumericType& high)
97 return std::min<NumericType> (std::max<NumericType> (value, low), high);
103template <
typename SampleType>
109 return std::pow (
static_cast<SampleType> (10), valueDb /
static_cast<SampleType> (20));
115template <
typename SampleType>
118 if (valueLinear < 1e-6)
121 return static_cast<SampleType> (20 * std::log10 (valueLinear));
127template <
typename SampleType>
133 return std::pow (
static_cast<SampleType> (10), valueDb /
static_cast<SampleType> (10));
139template <
typename SampleType>
142 if (valueLinear < 1e-12)
145 return static_cast<SampleType> (10 * std::log10 (valueLinear));
149template <
typename SampleType>
150inline static SampleType
floatsEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
152 return std::abs (a - b) < epsilon;
156template <
typename SampleType>
157inline static SampleType
floatsNotEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
159 return std::abs (a - b) >= epsilon;
163template <
typename SampleType>
166 return static_cast<size_t> (x + (SampleType) 0.5);
172 return std::pow (2.0, cents / 1200.0);
176inline double addCents (
double baseFrequencyHz,
double cents)
182template <
typename SampleType>
185 SampleType wrappedPhaseRadians = std::remainder (phaseRadians, (SampleType)
hart::twoPi);
187 if (wrappedPhaseRadians < 0.0)
190 return wrappedPhaseRadians;
213 while ((power << 1) < x)
222 return (x != 0) && ((x & (x - 1)) == 0);
229 std::ifstream file (path.c_str());
239 if (path[0] ==
'/' || path[0] ==
'\\')
243 if (path.size() > 1 && std::isalpha (path[0]) && path[1] ==
':')
261template <
typename KeyType,
typename ValueType>
262inline static bool contains (
const std::unordered_map<KeyType, ValueType>& map,
const KeyType& key)
264 return map.find (key) != map.end();
269template<
typename ObjectType,
typename... Args>
272 return std::unique_ptr<ObjectType> (
new ObjectType (std::forward<Args> (args)...));
278#if defined(__cpp_lib_uncaught_exceptions
)
279 return std::uncaught_exceptions() > 0;
281 return std::uncaught_exception();
290#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
291 virtual void represent(std::ostream& stream) const override
293 stream << #ClassName "()";
297#if defined(__GNUC__
) || defined(__clang__
)
298 #define HART_DEPRECATED(msg) __attribute__((deprecated(msg)))
299#elif defined(_MSC_VER)
300 #define HART_DEPRECATED(msg) __declspec(deprecated(msg))
302 #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.
static bool isPowerOfTwo(size_t x)
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
Normalise
Helper values for something that could normalise something.
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)
Adds an offset in cents to a frequency in Hz.
static size_t nextPowerOfTwo(size_t x)
Finds next power of 2 after a non-negative number x.
NumericType clamp(const NumericType &value, const NumericType &low, const NumericType &high)
std::clamp() replacement for C++11
constexpr double oo
Infinity.
static bool fileExistsAndReadable(const std::string &path)
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 size_t previousPowerOfTwo(size_t x)
Finds previous power of 2 after a non-negative number x.
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.
double centsToRatio(double cents)
Converts frequency difference in cents to frequence ratio.
Loop
Helper values for something that could loop, like a Signal.
Holds values set by the user via CLI interface.
std::string getDataRootPath() const
Get data root path set by a "`--data-root-path`,`-d`" argument.
static CLIConfig & getInstance()
Get the singleton instance.