12#include <unordered_map>
24constexpr double inf = std::numeric_limits<
double>::infinity();
30constexpr double pi = 3.14159265358979323846;
74inline std::ostream& operator<< (std::ostream& os,
Oversampling oversampling)
76 return os <<
"Oversampling::x" <<
static_cast<
int> (oversampling);
80template<
typename FloatType>
83 return std::numeric_limits<FloatType>::quiet_NaN();
87template <
typename NumericType>
88NumericType
clamp (
const NumericType& value,
const NumericType& low,
const NumericType& high)
90 return std::min<NumericType> (std::max<NumericType> (value, low), high);
96template <
typename SampleType>
102 return std::pow (
static_cast<SampleType> (10), valueDb /
static_cast<SampleType> (20));
108template <
typename SampleType>
111 if (valueLinear < 1e-6)
114 return static_cast<SampleType> (20 * std::log10 (valueLinear));
120template <
typename SampleType>
126 return std::pow (
static_cast<SampleType> (10), valueDb /
static_cast<SampleType> (10));
132template <
typename SampleType>
135 if (valueLinear < 1e-12)
138 return static_cast<SampleType> (10 * std::log10 (valueLinear));
142template <
typename SampleType>
143inline static SampleType
floatsEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
145 return std::abs (a - b) < epsilon;
149template <
typename SampleType>
150inline static SampleType
floatsNotEqual (SampleType a, SampleType b, SampleType epsilon = (SampleType) 1e-8)
152 return std::abs (a - b) >= epsilon;
156template <
typename SampleType>
159 return static_cast<size_t> (x + (SampleType) 0.5);
163inline double addCents (
double baseFrequencyHz,
double cents)
165 return baseFrequencyHz * std::pow (2.0, cents / 1200.0);
169template <
typename SampleType>
172 SampleType wrappedPhaseRadians = std::remainder (phaseRadians, (SampleType)
hart::twoPi);
174 if (wrappedPhaseRadians < 0.0)
177 return wrappedPhaseRadians;
200 while ((power << 1) < x)
209 return (x != 0) && ((x & (x - 1)) == 0);
216 std::ifstream file (path.c_str());
226 if (path[0] ==
'/' || path[0] ==
'\\')
230 if (path.size() > 1 && std::isalpha (path[0]) && path[1] ==
':')
248template <
typename KeyType,
typename ValueType>
249inline static bool contains (
const std::unordered_map<KeyType, ValueType>& map,
const KeyType& key)
251 return map.find (key) != map.end();
256template<
typename ObjectType,
typename... Args>
259 return std::unique_ptr<ObjectType> (
new ObjectType (std::forward<Args> (args)...));
265#if defined(__cpp_lib_uncaught_exceptions
)
266 return std::uncaught_exceptions() > 0;
268 return std::uncaught_exception();
277#define HART_DEFINE_GENERIC_REPRESENT(ClassName)
278 virtual void represent(std::ostream& stream) const override
280 stream << #ClassName "()";
284#if defined(__GNUC__
) || defined(__clang__
)
285 #define HART_DEPRECATED(msg) __attribute__((deprecated(msg)))
286#elif defined(_MSC_VER)
287 #define HART_DEPRECATED(msg) __declspec(deprecated(msg))
289 #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
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.
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.
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.