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/AudioMixer.h b/services/audioflinger/AudioMixer.h
index e6de00c..a9f4761 100644
--- a/services/audioflinger/AudioMixer.h
+++ b/services/audioflinger/AudioMixer.h
@@ -163,8 +163,9 @@
     struct track_t {
         uint32_t    needs;
 
+        // TODO: Eventually remove legacy integer volume settings
         union {
-        int16_t     volume[MAX_NUM_CHANNELS]; // [0]3.12 fixed point
+        int16_t     volume[MAX_NUM_CHANNELS]; // U4.12 fixed point (top bit should be zero)
         int32_t     volumeRL;
         };
 
@@ -217,7 +218,13 @@
         audio_format_t mMixerInFormat;   // mix internal format AUDIO_FORMAT_PCM_(FLOAT|16_BIT)
                                          // each track must be converted to this format.
 
-        int32_t        mUnused[1];       // alignment padding
+        float          mVolume[MAX_NUM_CHANNELS];     // floating point set volume
+        float          mPrevVolume[MAX_NUM_CHANNELS]; // floating point previous volume
+        float          mVolumeInc[MAX_NUM_CHANNELS];  // floating point volume increment
+
+        float          mAuxLevel;                     // floating point set aux level
+        float          mPrevAuxLevel;                 // floating point prev aux level
+        float          mAuxInc;                       // floating point aux increment
 
         // 16-byte boundary
 
@@ -225,7 +232,7 @@
         bool        setResampler(uint32_t sampleRate, uint32_t devSampleRate);
         bool        doesResample() const { return resampler != NULL; }
         void        resetResampler() { if (resampler != NULL) resampler->reset(); }
-        void        adjustVolumeRamp(bool aux);
+        void        adjustVolumeRamp(bool aux, bool useFloat = false);
         size_t      getUnreleasedFrames() const { return resampler != NULL ?
                                                     resampler->getUnreleasedFrames() : 0; };
     };
@@ -349,6 +356,22 @@
     static pthread_once_t   sOnceControl;
     static void             sInitRoutine();
 
+    /* multi-format volume mixing function (calls template functions
+     * in AudioMixerOps.h).  The template parameters are as follows:
+     *
+     *   MIXTYPE     (see AudioMixerOps.h MIXTYPE_* enumeration)
+     *   NCHAN       (number of channels, 2 for now)
+     *   USEFLOATVOL (set to true if float volume is used)
+     *   ADJUSTVOL   (set to true if volume ramp parameters needs adjustment afterwards)
+     *   TO: int32_t (Q4.27) or float
+     *   TI: int32_t (Q4.27) or int16_t (Q0.15) or float
+     *   TA: int32_t (Q4.27)
+     */
+    template <int MIXTYPE, int NCHAN, bool USEFLOATVOL, bool ADJUSTVOL,
+        typename TO, typename TI, typename TA>
+    static void volumeMix(TO *out, size_t outFrames,
+            const TI *in, TA *aux, bool ramp, AudioMixer::track_t *t);
+
     // multi-format process hooks
     template <int MIXTYPE, int NCHAN, typename TO, typename TI, typename TA>
     static void process_NoResampleOneTrack(state_t* state, int64_t pts);