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/AudioResampler.h b/services/audioflinger/AudioResampler.h
index be747f6..cdc6d92 100644
--- a/services/audioflinger/AudioResampler.h
+++ b/services/audioflinger/AudioResampler.h
@@ -47,6 +47,8 @@
DYN_HIGH_QUALITY=7,
};
+ static const float UNITY_GAIN_FLOAT = 1.0f;
+
static AudioResampler* create(audio_format_t format, int inChannelCount,
int32_t sampleRate, src_quality quality=DEFAULT_QUALITY);
@@ -54,7 +56,7 @@
virtual void init() = 0;
virtual void setSampleRate(int32_t inSampleRate);
- virtual void setVolume(int16_t left, int16_t right);
+ virtual void setVolume(float left, float right);
virtual void setLocalTimeFreq(uint64_t freq);
// set the PTS of the next buffer output by the resampler
@@ -142,6 +144,15 @@
+ (mSampleRate - 1))/mSampleRate;
}
+ inline float clampFloatVol(float volume) {
+ if (volume > UNITY_GAIN_FLOAT) {
+ return UNITY_GAIN_FLOAT;
+ } else if (volume >= 0.) {
+ return volume;
+ }
+ return 0.; // NaN or negative volume maps to 0.
+ }
+
private:
const src_quality mQuality;