1
0
basics/units.h
2022-12-05 21:06:19 +00:00

25 lines
582 B
C++

/* Copyright 2022 Signalsmith Audio Ltd. / Geraint Luff
Released under the Boost Software License (see LICENSE.txt) */
#ifndef SIGNALSMITH_UNITS_H
#define SIGNALSMITH_UNITS_H
#include <cmath>
namespace signalsmith { namespace units {
static double dbToGain(double db) {
return std::pow(10, db*0.05);
}
static double gainToDb(double gain) {
return std::log10(std::max<double>(gain, 1e-10))*20;
}
static double pcToRatio(double percent) {
return percent*0.01;
}
static double ratioToPc(double linear) {
return linear*100;
}
}} // namespace
#endif // include guard