From 5e58b0abe5b6c8f5bd96a8f78bbeeeb4d3892020 Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Mon, 23 Jun 2014 19:07:29 -0700 Subject: 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 --- services/audioflinger/AudioMixerOps.h | 40 +++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'services/audioflinger/AudioMixerOps.h') 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 @@ inline int16_t MixMul(int32_t value, int32_t volume) return clamp16(MixMul(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 value, float volume) { + return value * volume; +} + +template <> +inline float MixMul(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 value, float volume) { + LOG_ALWAYS_FATAL("MixMul Runtime Should not be here"); + return value * volume; +} + +template <> +inline int32_t MixMul(int16_t value, float volume) { + LOG_ALWAYS_FATAL("MixMul 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 value, float volume) { + LOG_ALWAYS_FATAL("MixMul Runtime Should not be here"); + return value * volume; +} + +template <> +inline int16_t MixMul(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. -- cgit v1.1