X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=gtk2_ardour%2Flogmeter.h;h=a244fb4bbeab2a73be15cc603182e64505ea3f9f;hb=91ae97d5c96e18cbb1f9937a961bd503ee8d5a38;hp=8d9f0b9d8278701ad86d9662efbbe23350a92a26;hpb=732a482f439f6df818b90634a5abb1b5d64ff05e;p=ardour.git diff --git a/gtk2_ardour/logmeter.h b/gtk2_ardour/logmeter.h index 8d9f0b9d82..a244fb4bbe 100644 --- a/gtk2_ardour/logmeter.h +++ b/gtk2_ardour/logmeter.h @@ -1,25 +1,54 @@ +/* + Copyright (C) 2000-2007 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #ifndef __ardour_gtk_log_meter_h__ #define __ardour_gtk_log_meter_h__ #if 1 -inline float +static inline float _log_meter (float power, double lower_db, double upper_db, double non_linearity) { return (power < lower_db ? 0.0 : pow((power-lower_db)/(upper_db-lower_db), non_linearity)); } -inline float +static inline float alt_log_meter (float power) { return _log_meter (power, -192.0, 0.0, 8.0); } #endif -inline float +/* prototypes - avoid compiler warning */ +static inline float log_meter (float db); +static inline float meter_deflect_ppm (float); +static inline float meter_deflect_din (float); +static inline float meter_deflect_nordic (float); +static inline float meter_deflect_vu (float); +static inline float meter_deflect_k (float, float); + + + +static inline float log_meter (float db) { gfloat def = 0.0f; /* Meter deflection %age */ - + if (db < -70.0f) { def = 0.0f; } else if (db < -60.0f) { @@ -37,8 +66,8 @@ log_meter (float db) } else { def = 115.0f; } - - /* 115 is the deflection %age that would be + + /* 115 is the deflection %age that would be when db=6.0. this is an arbitrary endpoint for our scaling. */ @@ -46,4 +75,71 @@ log_meter (float db) return def/115.0f; } +static inline float +meter_deflect_ppm (float db) +{ + if (db < -30) { + // 2.258 == ((-30 + 32.0)/ 28.0) / 10^(-30 / 20); + return (dB_to_coefficient(db) * 2.258769757f); + } else { + const float rv = (db + 32.0f) / 28.0f; + if (rv < 1.0) { + return rv; + } else { + return 1.0; + } + } +} + +static inline float +meter_deflect_din (float db) +{ + float rv = dB_to_coefficient(db); + rv = sqrtf (sqrtf (2.3676f * rv)) - 0.1803f; + if (rv >= 1.0) { + return 1.0; + } else { + return (rv > 0 ? rv : 0.0); + } +} + +static inline float +meter_deflect_nordic (float db) +{ + if (db < -60) { + return 0.0; + } else { + const float rv = (db + 60.0f) / 54.0f; + if (rv < 1.0) { + return rv; + } else { + return 1.0; + } + } +} + +static inline float +meter_deflect_vu (float db) +{ + const float rv = 6.77165f * dB_to_coefficient(db); + if (rv > 1.0) return 1.0; + return rv; +} + +static inline float +meter_deflect_k (float db, float krange) +{ + db+=krange; + if (db < -40.0f) { + return (dB_to_coefficient(db) * 500.0f / (krange + 45.0f)); + } else { + const float rv = (db + 45.0f) / (krange + 45.0f); + if (rv < 1.0) { + return rv; + } else { + return 1.0; + } + } +} + #endif /* __ardour_gtk_log_meter_h__ */