summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/AudioMixerOps.h
diff options
context:
space:
mode:
authorAndy Hung <hunga@google.com>2014-06-23 19:07:29 -0700
committerAndy Hung <hunga@google.com>2014-07-08 21:09:13 -0700
commit5e58b0abe5b6c8f5bd96a8f78bbeeeb4d3892020 (patch)
tree975ed02efce4eaefcf5b0ceb5f33d212542a33a6 /services/audioflinger/AudioMixerOps.h
parent72d039f007722c92ee5ea7ffd03ece19d2781103 (diff)
downloadframeworks_av-5e58b0abe5b6c8f5bd96a8f78bbeeeb4d3892020.zip
frameworks_av-5e58b0abe5b6c8f5bd96a8f78bbeeeb4d3892020.tar.gz
frameworks_av-5e58b0abe5b6c8f5bd96a8f78bbeeeb4d3892020.tar.bz2
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
Diffstat (limited to 'services/audioflinger/AudioMixerOps.h')
-rw-r--r--services/audioflinger/AudioMixerOps.h40
1 files changed, 40 insertions, 0 deletions
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<int16_t, int32_t, int32_t>(int32_t value, int32_t volume)
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.