Extract out audio DSP code to utility library
Change-Id: Ib8ce72028a7ea30e82baa518e381370e820ebbd0
This commit is contained in:
@@ -47,6 +47,7 @@ LOCAL_C_INCLUDES += \
|
||||
$(TOP)/frameworks/media/libvideoeditor/osal/inc
|
||||
|
||||
LOCAL_SHARED_LIBRARIES := \
|
||||
libaudioutils \
|
||||
libcutils \
|
||||
libdl \
|
||||
libutils \
|
||||
|
||||
@@ -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 \
|
||||
|
||||
@@ -54,6 +54,8 @@
|
||||
#include <audio_effects/effect_ns.h>
|
||||
#include <audio_effects/effect_aec.h>
|
||||
|
||||
#include <audio_utils/primitives.h>
|
||||
|
||||
#include <cpustats/ThreadCpuUsage.h>
|
||||
#include <powermanager/PowerManager.h>
|
||||
// #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);
|
||||
}
|
||||
|
||||
@@ -30,17 +30,11 @@
|
||||
|
||||
#include <system/audio.h>
|
||||
|
||||
#include <audio_utils/primitives.h>
|
||||
|
||||
#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<c ; i++) {
|
||||
int32_t l = *sums++;
|
||||
int32_t r = *sums++;
|
||||
int32_t nl = l >> 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)
|
||||
{
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user