25 lines
582 B
C++
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
|