From 490909d2c057f348c0a6c69e5e6e9ab48fa8ea07 Mon Sep 17 00:00:00 2001 From: Glenn Kasten Date: Thu, 15 Dec 2011 09:52:39 -0800 Subject: Extract out audio DSP code to utility library Change-Id: Ib8ce72028a7ea30e82baa518e381370e820ebbd0 --- services/audioflinger/Android.mk | 4 +- services/audioflinger/AudioFlinger.cpp | 16 ++--- services/audioflinger/AudioMixer.cpp | 105 +-------------------------------- services/audioflinger/AudioMixer.h | 2 - 4 files changed, 10 insertions(+), 117 deletions(-) (limited to 'services') diff --git a/services/audioflinger/Android.mk b/services/audioflinger/Android.mk index fa49592..52834db 100644 --- a/services/audioflinger/Android.mk +++ b/services/audioflinger/Android.mk @@ -11,9 +11,11 @@ LOCAL_SRC_FILES:= \ AudioPolicyService.cpp LOCAL_C_INCLUDES := \ - system/media/audio_effects/include + system/media/audio_effects/include \ + system/media/audio_utils/include LOCAL_SHARED_LIBRARIES := \ + libaudioutils \ libcutils \ libutils \ libbinder \ diff --git a/services/audioflinger/AudioFlinger.cpp b/services/audioflinger/AudioFlinger.cpp index b48f23d..58482d5 100644 --- a/services/audioflinger/AudioFlinger.cpp +++ b/services/audioflinger/AudioFlinger.cpp @@ -54,6 +54,8 @@ #include #include +#include + #include #include // #define DEBUG_CPU_USAGE 10 // log statistics every n wall clock seconds @@ -2455,14 +2457,6 @@ AudioFlinger::DirectOutputThread::~DirectOutputThread() { } - -static inline int16_t clamp16(int32_t sample) -{ - if ((sample>>15) ^ (sample>>31)) - sample = 0x7FFF ^ (sample>>31); - return sample; -} - static inline int32_t mul(int16_t in, int16_t v) { @@ -4391,7 +4385,7 @@ bool AudioFlinger::RecordThread::threadLoop() // ditherAndClamp() works as long as all buffers returned by mActiveTrack->getNextBuffer() // are 32 bit aligned which should be always true. if (mChannelCount == 2 && mReqChannelCount == 1) { - AudioMixer::ditherAndClamp(mRsmpOutBuffer, mRsmpOutBuffer, framesOut); + ditherAndClamp(mRsmpOutBuffer, mRsmpOutBuffer, framesOut); // the resampler always outputs stereo samples: do post stereo to mono conversion int16_t *src = (int16_t *)mRsmpOutBuffer; int16_t *dst = buffer.i16; @@ -4400,7 +4394,7 @@ bool AudioFlinger::RecordThread::threadLoop() src += 2; } } else { - AudioMixer::ditherAndClamp((int32_t *)buffer.raw, mRsmpOutBuffer, framesOut); + ditherAndClamp((int32_t *)buffer.raw, mRsmpOutBuffer, framesOut); } } @@ -6271,7 +6265,7 @@ void AudioFlinger::EffectModule::process() if (isProcessEnabled()) { // do 32 bit to 16 bit conversion for auxiliary effect input buffer if ((mDescriptor.flags & EFFECT_FLAG_TYPE_MASK) == EFFECT_FLAG_TYPE_AUXILIARY) { - AudioMixer::ditherAndClamp(mConfig.inputCfg.buffer.s32, + ditherAndClamp(mConfig.inputCfg.buffer.s32, mConfig.inputCfg.buffer.s32, mConfig.inputCfg.buffer.frameCount/2); } diff --git a/services/audioflinger/AudioMixer.cpp b/services/audioflinger/AudioMixer.cpp index 7c7fa56..fe56771 100644 --- a/services/audioflinger/AudioMixer.cpp +++ b/services/audioflinger/AudioMixer.cpp @@ -30,17 +30,11 @@ #include +#include + #include "AudioMixer.h" namespace android { -// ---------------------------------------------------------------------------- - -static inline int16_t clamp16(int32_t sample) -{ - if ((sample>>15) ^ (sample>>31)) - sample = 0x7FFF ^ (sample>>31); - return sample; -} // ---------------------------------------------------------------------------- @@ -479,88 +473,6 @@ void AudioMixer::process__validate(state_t* state) } } -static inline -int32_t mulAdd(int16_t in, int16_t v, int32_t a) -{ -#if defined(__arm__) && !defined(__thumb__) - int32_t out; - asm( "smlabb %[out], %[in], %[v], %[a] \n" - : [out]"=r"(out) - : [in]"%r"(in), [v]"r"(v), [a]"r"(a) - : ); - return out; -#else - return a + in * int32_t(v); -#endif -} - -static inline -int32_t mul(int16_t in, int16_t v) -{ -#if defined(__arm__) && !defined(__thumb__) - int32_t out; - asm( "smulbb %[out], %[in], %[v] \n" - : [out]"=r"(out) - : [in]"%r"(in), [v]"r"(v) - : ); - return out; -#else - return in * int32_t(v); -#endif -} - -static inline -int32_t mulAddRL(int left, uint32_t inRL, uint32_t vRL, int32_t a) -{ -#if defined(__arm__) && !defined(__thumb__) - int32_t out; - if (left) { - asm( "smlabb %[out], %[inRL], %[vRL], %[a] \n" - : [out]"=r"(out) - : [inRL]"%r"(inRL), [vRL]"r"(vRL), [a]"r"(a) - : ); - } else { - asm( "smlatt %[out], %[inRL], %[vRL], %[a] \n" - : [out]"=r"(out) - : [inRL]"%r"(inRL), [vRL]"r"(vRL), [a]"r"(a) - : ); - } - return out; -#else - if (left) { - return a + int16_t(inRL&0xFFFF) * int16_t(vRL&0xFFFF); - } else { - return a + int16_t(inRL>>16) * int16_t(vRL>>16); - } -#endif -} - -static inline -int32_t mulRL(int left, uint32_t inRL, uint32_t vRL) -{ -#if defined(__arm__) && !defined(__thumb__) - int32_t out; - if (left) { - asm( "smulbb %[out], %[inRL], %[vRL] \n" - : [out]"=r"(out) - : [inRL]"%r"(inRL), [vRL]"r"(vRL) - : ); - } else { - asm( "smultt %[out], %[inRL], %[vRL] \n" - : [out]"=r"(out) - : [inRL]"%r"(inRL), [vRL]"r"(vRL) - : ); - } - return out; -#else - if (left) { - return int16_t(inRL&0xFFFF) * int16_t(vRL&0xFFFF); - } else { - return int16_t(inRL>>16) * int16_t(vRL>>16); - } -#endif -} - void AudioMixer::track__genericResample(track_t* t, int32_t* out, size_t outFrameCount, int32_t* temp, int32_t* aux) { @@ -845,19 +757,6 @@ void AudioMixer::track__16BitsMono(track_t* t, int32_t* out, size_t frameCount, t->in = in; } -void AudioMixer::ditherAndClamp(int32_t* out, int32_t const *sums, size_t c) -{ - for (size_t i=0 ; i> 12; - int32_t nr = r >> 12; - l = clamp16(nl); - r = clamp16(nr); - *out++ = (r<<16) | (l & 0xFFFF); - } -} - // no-op case void AudioMixer::process__nop(state_t* state) { diff --git a/services/audioflinger/AudioMixer.h b/services/audioflinger/AudioMixer.h index 75c9170..bdbbaf3 100644 --- a/services/audioflinger/AudioMixer.h +++ b/services/audioflinger/AudioMixer.h @@ -89,8 +89,6 @@ public: uint32_t trackNames() const { return mTrackNames; } - static void ditherAndClamp(int32_t* out, int32_t const *sums, size_t c); - private: enum { -- cgit v1.1