CuteLogger
Fast and simple logging solution for Qt based applications
iecscale.h
1 /*
2  * Copyright (c) 2015 Meltytech, LLC
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #ifndef IECSCALE_H
19 #define IECSCALE_H
20 
21 //----------------------------------------------------------------------------
22 // IEC standard dB scaling -- as borrowed from meterbridge (c) Steve Harris
23 
24 static inline double IEC_Scale(double dB)
25 {
26  double fScale = 1.0f;
27 
28  if (dB < -70.0f)
29  fScale = 0.0f;
30  else if (dB < -60.0f)
31  fScale = (dB + 70.0f) * 0.0025f;
32  else if (dB < -50.0f)
33  fScale = (dB + 60.0f) * 0.005f + 0.025f;
34  else if (dB < -40.0)
35  fScale = (dB + 50.0f) * 0.0075f + 0.075f;
36  else if (dB < -30.0f)
37  fScale = (dB + 40.0f) * 0.015f + 0.15f;
38  else if (dB < -20.0f)
39  fScale = (dB + 30.0f) * 0.02f + 0.3f;
40  else if (dB < -0.001f || dB > 0.001f) /* if (dB < 0.0f) */
41  fScale = (dB + 20.0f) * 0.025f + 0.5f;
42 
43  return fScale;
44 }
45 
46 static inline double IEC_ScaleMax(double dB, double max)
47 {
48  return IEC_Scale(dB) / IEC_Scale(max);
49 }
50 
51 #endif // IECSCALE_H