VU meter label color&shadow tweak by the_CLA
[ardour.git] / gtk2_ardour / logmeter.h
index 0bbce787b2b55706dfbdaa0de05980e89d9c2cb7..c7b18ea6b95acb8eabf8cf578a3e04bff48c9510 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    Copyright (C) 2000-2007 Paul Davis 
+    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
@@ -34,11 +34,21 @@ alt_log_meter (float power)
 }
 #endif
 
+/* prototypes - avoid compiler warning */
+inline float log_meter (float db);
+inline float meter_deflect_ppm (float);
+inline float meter_deflect_din (float);
+inline float meter_deflect_nordic (float);
+inline float meter_deflect_vu (float);
+inline float meter_deflect_k (float, float);
+
+
+
 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) {
@@ -56,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.
         */
@@ -65,4 +75,71 @@ log_meter (float db)
          return def/115.0f;
 }
 
+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;
+               }
+       }
+}
+
+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);
+       }
+}
+
+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;
+               }
+       }
+}
+
+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;
+}
+
+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__ */