Add floating point volume handling to AudioMixer

Use floating point volume in AudioMixer mixing when floating
point input is used with the new mixer engine.
AudioResampler is updated to take floating point volume to match.
Both legacy integer and floating point mixer engines work.

For now, integer volume is used when the new mixer engine
runs in integer input mode, for backward compatibility with
the legacy mixer.  The new mixer engine will generally run in
floating point input mode. When the legacy path is removed,
the integer volumes will be removed.

Change-Id: I79e80c292ae7c8b8bdd0aa371a1b2c3a1b618290
diff --git a/services/audioflinger/AudioMixerOps.h b/services/audioflinger/AudioMixerOps.h
index de92946..ad739ff 100644
--- a/services/audioflinger/AudioMixerOps.h
+++ b/services/audioflinger/AudioMixerOps.h
@@ -136,6 +136,46 @@
     return clamp16(MixMul<int32_t, int32_t, int32_t>(value, volume) >> 12);
 }
 
+/* Required for floating point volume.  Some are needed for compilation but
+ * are not needed in execution and should be removed from the final build by
+ * an optimizing compiler.
+ */
+template <>
+inline float MixMul<float, float, float>(float value, float volume) {
+    return value * volume;
+}
+
+template <>
+inline float MixMul<float, int16_t, float>(int16_t value, float volume) {
+    static const float float_from_q_15 = 1. / (1 << 15);
+    return value * volume * float_from_q_15;
+}
+
+template <>
+inline int32_t MixMul<int32_t, int32_t, float>(int32_t value, float volume) {
+    LOG_ALWAYS_FATAL("MixMul<int32_t, int32_t, float> Runtime Should not be here");
+    return value * volume;
+}
+
+template <>
+inline int32_t MixMul<int32_t, int16_t, float>(int16_t value, float volume) {
+    LOG_ALWAYS_FATAL("MixMul<int32_t, int16_t, float> Runtime Should not be here");
+    static const float u4_12_from_float = (1 << 12);
+    return value * volume * u4_12_from_float;
+}
+
+template <>
+inline int16_t MixMul<int16_t, int16_t, float>(int16_t value, float volume) {
+    LOG_ALWAYS_FATAL("MixMul<int16_t, int16_t, float> Runtime Should not be here");
+    return value * volume;
+}
+
+template <>
+inline int16_t MixMul<int16_t, float, float>(float value, float volume) {
+    static const float q_15_from_float = (1 << 15);
+    return value * volume * q_15_from_float;
+}
+
 /*
  * MixAccum is used to add into an accumulator register of a possibly different
  * type. The TO and TI types are the same as MixMul.