From 0468ca9d7f0f01767ab0d3d4557ddac93b6b2c7e Mon Sep 17 00:00:00 2001 From: "Antti S. Lankila" Date: Tue, 3 Aug 2010 20:08:35 +0300 Subject: Fix rattling of very quiet sounds An integer truncation issue resulted in discontinuous estimates of sound level when the audio stream sound level was very quiet. --- libs/audioflinger/AudioDSP.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'libs') diff --git a/libs/audioflinger/AudioDSP.cpp b/libs/audioflinger/AudioDSP.cpp index 24f99fc..639736f 100644 --- a/libs/audioflinger/AudioDSP.cpp +++ b/libs/audioflinger/AudioDSP.cpp @@ -266,12 +266,15 @@ int32_t EffectCompression::estimateLevel(const int16_t *audioData, int32_t frame { mWeighter.reset(); uint32_t power = 0; + uint32_t powerFraction = 0; for (int32_t i = 0; i < frames; i ++) { int16_t tmp = *audioData; audioData += samplesPerFrame; int32_t out = mWeighter.process(tmp) >> 12; - power += out * out >> 16; + powerFraction += out * out; + power += powerFraction >> 16; + powerFraction &= 0xffff; } return power; -- cgit v1.1