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/AudioResamplerDyn.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'services/audioflinger/AudioResamplerDyn.cpp') diff --git a/services/audioflinger/AudioResamplerDyn.cpp b/services/audioflinger/AudioResamplerDyn.cpp index 043c803..e201ff8 100644 --- a/services/audioflinger/AudioResamplerDyn.cpp +++ b/services/audioflinger/AudioResamplerDyn.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "AudioResamplerFirOps.h" // USE_NEON and USE_INLINE_ASSEMBLY defined here #include "AudioResamplerFirProcess.h" @@ -190,17 +191,17 @@ void AudioResamplerDyn::init() } template -void AudioResamplerDyn::setVolume(int16_t left, int16_t right) +void AudioResamplerDyn::setVolume(float left, float right) { AudioResampler::setVolume(left, right); - // volume is applied on the output type. if (is_same::value || is_same::value) { - const TO scale = 1. / (1UL << 12); - mVolumeSimd[0] = static_cast(left) * scale; - mVolumeSimd[1] = static_cast(right) * scale; - } else { - mVolumeSimd[0] = static_cast(left) << 16; - mVolumeSimd[1] = static_cast(right) << 16; + mVolumeSimd[0] = static_cast(left); + mVolumeSimd[1] = static_cast(right); + } else { // integer requires scaling to U4_28 (rounding down) + // integer volumes are clamped to 0 to UNITY_GAIN so there + // are no issues with signed overflow. + mVolumeSimd[0] = u4_28_from_float(clampFloatVol(left)); + mVolumeSimd[1] = u4_28_from_float(clampFloatVol(right)); } } @@ -410,7 +411,7 @@ void AudioResamplerDyn::setSampleRate(int32_t inSampleRate) // Note: A stride of 2 is achieved with non-SIMD processing. int stride = ((c.mHalfNumCoefs & 7) == 0) ? 16 : 2; LOG_ALWAYS_FATAL_IF(stride < 16, "Resampler stride must be 16 or more"); - LOG_ALWAYS_FATAL_IF(mChannelCount > 8 || mChannelCount < 1, + LOG_ALWAYS_FATAL_IF(mChannelCount < 1 || mChannelCount > 8, "Resampler channels(%d) must be between 1 to 8", mChannelCount); // stride 16 (falls back to stride 2 for machines that do not support NEON) if (locked) { -- cgit v1.1