From 42b011166ece30969667e0ff9dcf4832568c9c1a Mon Sep 17 00:00:00 2001 From: Andy Hung Date: Sun, 20 Jul 2014 14:04:19 -0700 Subject: Fix multichannel integer resampling and add tests Change-Id: I384bf8317d4f03616bf9f2b458a8700965d5cf56 --- services/audioflinger/AudioResamplerFirProcess.h | 36 +++++++----------------- 1 file changed, 10 insertions(+), 26 deletions(-) (limited to 'services/audioflinger/AudioResamplerFirProcess.h') diff --git a/services/audioflinger/AudioResamplerFirProcess.h b/services/audioflinger/AudioResamplerFirProcess.h index bb0f1c9..d130013 100644 --- a/services/audioflinger/AudioResamplerFirProcess.h +++ b/services/audioflinger/AudioResamplerFirProcess.h @@ -109,40 +109,25 @@ public: } }; -/* - * Helper template functions for interpolating filter coefficients. - */ - -template -void adjustLerp(T& lerpP __unused) -{ -} - -template -void adjustLerp(T& lerpP) -{ - lerpP >>= 16; // lerpP is 32bit for NEON int32_t, but always 16 bit for non-NEON path -} - template -static inline +inline TC interpolate(TC coef_0, TC coef_1, TINTERP lerp) { return lerp * (coef_1 - coef_0) + coef_0; } -template -static inline -int16_t interpolate(int16_t coef_0, int16_t coef_1, uint32_t lerp) -{ - return (static_cast(lerp) * ((coef_1-coef_0)<<1)>>16) + coef_0; +template<> +inline +int16_t interpolate(int16_t coef_0, int16_t coef_1, uint32_t lerp) +{ // in some CPU architectures 16b x 16b multiplies are faster. + return (static_cast(lerp) * static_cast(coef_1 - coef_0) >> 15) + coef_0; } -template -static inline -int32_t interpolate(int32_t coef_0, int32_t coef_1, uint32_t lerp) +template<> +inline +int32_t interpolate(int32_t coef_0, int32_t coef_1, uint32_t lerp) { - return mulAdd(static_cast(lerp), (coef_1-coef_0)<<1, coef_0); + return (lerp * static_cast(coef_1 - coef_0) >> 31) + coef_0; } /* class scope for passing in functions into templates */ @@ -283,7 +268,6 @@ void Process(TO* const out, TINTERP lerpP, const TO* const volumeLR) { - adjustLerp(lerpP); // coefficient type adjustment for interpolations ProcessBase(out, count, coefsP, coefsN, sP, sN, lerpP, volumeLR); } -- cgit v1.1