audio policy: volume in dBs

Volumes are now stored and exchanged in dBs to be
consistent with the volume tables.

They are converted if needed when applied to the target
gain controller.

Change-Id: I916cbb0bbe65c916444b8c65a2bdca9645c58399
diff --git a/services/audiopolicy/common/include/Volume.h b/services/audiopolicy/common/include/Volume.h
index a4cc759..4205589 100755
--- a/services/audiopolicy/common/include/Volume.h
+++ b/services/audiopolicy/common/include/Volume.h
@@ -18,6 +18,10 @@
 
 #include <system/audio.h>
 #include <utils/Log.h>
+#include <math.h>
+
+// Absolute min volume in dB (can be represented in single precision normal float value)
+#define VOLUME_MIN_DB (-758)
 
 class VolumeCurvePoint
 {
@@ -32,7 +36,7 @@
     /**
      * 4 points to define the volume attenuation curve, each characterized by the volume
      * index (from 0 to 100) at which they apply, and the attenuation in dB at that index.
-     * we use 100 steps to avoid rounding errors when computing the volume in volIndexToAmpl()
+     * we use 100 steps to avoid rounding errors when computing the volume in volIndexToDb()
      *
      * @todo shall become configurable
      */
@@ -134,4 +138,20 @@
         }
     }
 
+    static inline float DbToAmpl(float decibels)
+    {
+        if (decibels <= VOLUME_MIN_DB) {
+            return 0.0f;
+        }
+        return exp( decibels * 0.115129f); // exp( dB * ln(10) / 20 )
+    }
+
+    static inline float AmplToDb(float amplification)
+    {
+        if (amplification == 0) {
+            return VOLUME_MIN_DB;
+        }
+        return 20 * log10(amplification);
+    }
+
 };