summaryrefslogtreecommitdiffstats
path: root/services/audioflinger/AudioResamplerDyn.cpp
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/AudioResamplerDyn.cpp
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/AudioResamplerDyn.cpp')
-rw-r--r--services/audioflinger/AudioResamplerDyn.cpp19
1 files changed, 10 insertions, 9 deletions
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 <cutils/properties.h>
#include <utils/Debug.h>
#include <utils/Log.h>
+#include <audio_utils/primitives.h>
#include "AudioResamplerFirOps.h" // USE_NEON and USE_INLINE_ASSEMBLY defined here
#include "AudioResamplerFirProcess.h"
@@ -190,17 +191,17 @@ void AudioResamplerDyn<TC, TI, TO>::init()
}
template<typename TC, typename TI, typename TO>
-void AudioResamplerDyn<TC, TI, TO>::setVolume(int16_t left, int16_t right)
+void AudioResamplerDyn<TC, TI, TO>::setVolume(float left, float right)
{
AudioResampler::setVolume(left, right);
- // volume is applied on the output type.
if (is_same<TO, float>::value || is_same<TO, double>::value) {
- const TO scale = 1. / (1UL << 12);
- mVolumeSimd[0] = static_cast<TO>(left) * scale;
- mVolumeSimd[1] = static_cast<TO>(right) * scale;
- } else {
- mVolumeSimd[0] = static_cast<int32_t>(left) << 16;
- mVolumeSimd[1] = static_cast<int32_t>(right) << 16;
+ mVolumeSimd[0] = static_cast<TO>(left);
+ mVolumeSimd[1] = static_cast<TO>(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<TC, TI, TO>::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) {