File indexing completed on 2024-04-14 04:46:03
0001 /* 0002 SPDX-FileCopyrightText: 2015 Meltytech, LLC 0003 SPDX-License-Identifier: GPL-3.0-or-later 0004 */ 0005 0006 #ifndef IECSCALE_H 0007 #define IECSCALE_H 0008 0009 #include <cmath> 0010 0011 //---------------------------------------------------------------------------- 0012 // IEC standard dB scaling -- as borrowed from meterbridge (c) Steve Harris 0013 0014 static inline double IEC_Scale(double dB) 0015 { 0016 double fScale = 1.0f; 0017 0018 if (dB < -70.0f) 0019 fScale = 0.0f; 0020 else if (dB < -60.0f) 0021 fScale = (dB + 70.0f) * 0.0025f; 0022 else if (dB < -50.0f) 0023 fScale = (dB + 60.0f) * 0.005f + 0.025f; 0024 else if (dB < -40.0) 0025 fScale = (dB + 50.0f) * 0.0075f + 0.075f; 0026 else if (dB < -30.0f) 0027 fScale = (dB + 40.0f) * 0.015f + 0.15f; 0028 else if (dB < -20.0f) 0029 fScale = (dB + 30.0f) * 0.02f + 0.3f; 0030 else if (dB < -0.001f || dB > 0.001f) /* if (dB < 0.0f) */ 0031 fScale = (dB + 20.0f) * 0.025f + 0.5f; 0032 0033 return fScale; 0034 } 0035 0036 static inline double IEC_ScaleMax(double dB, double max) 0037 { 0038 return IEC_Scale(dB) / IEC_Scale(max); 0039 } 0040 0041 static inline double fromDB(double level) 0042 { 0043 double value = 60; 0044 if (level > 0.) { 0045 // increase volume 0046 value = 100 - ((pow(10, 1. - level / 24) - 1) / .225); 0047 } else if (level < 0.) { 0048 value = ((10 - pow(10, 1. - level / -50)) / -0.11395) + 59; 0049 } 0050 return value; 0051 } 0052 0053 #endif // IECSCALE_H 0054