summaryrefslogtreecommitdiffstats
path: root/libs
diff options
context:
space:
mode:
authorAntti S. Lankila <alankila@gmail.com>2010-08-05 00:28:48 +0300
committerAntti S. Lankila <alankila@gmail.com>2010-08-06 23:47:37 +0300
commit967bf185d102da1b39b506de005a99baf379d0ee (patch)
tree8333a28a3dae64b8b89165c0fadeb5497cb67c8e /libs
parentc9d93de9e2dee5f9bbda0e07609e917e039e022d (diff)
downloadframeworks_base-967bf185d102da1b39b506de005a99baf379d0ee.zip
frameworks_base-967bf185d102da1b39b506de005a99baf379d0ee.tar.gz
frameworks_base-967bf185d102da1b39b506de005a99baf379d0ee.tar.bz2
Remove boost limit from bottom.
I noticed there was some distortion arising from the fixed bottom level set in the level estimator, so I removed such limits. I also enhanced the estimation quality for the nearly inaudible sound levels. Signed-off-by: Antti S. Lankila <alankila@gmail.com>
Diffstat (limited to 'libs')
-rw-r--r--libs/audioflinger/AudioDSP.cpp28
-rw-r--r--libs/audioflinger/AudioDSP.h2
2 files changed, 15 insertions, 15 deletions
diff --git a/libs/audioflinger/AudioDSP.cpp b/libs/audioflinger/AudioDSP.cpp
index 639736f..545f3ac 100644
--- a/libs/audioflinger/AudioDSP.cpp
+++ b/libs/audioflinger/AudioDSP.cpp
@@ -262,7 +262,7 @@ void EffectCompression::process(int32_t *inout, int32_t frames)
{
}
-int32_t EffectCompression::estimateLevel(const int16_t *audioData, int32_t frames, int32_t samplesPerFrame)
+float EffectCompression::estimateLevel(const int16_t *audioData, int32_t frames, int32_t samplesPerFrame)
{
mWeighter.reset();
uint32_t power = 0;
@@ -277,7 +277,8 @@ int32_t EffectCompression::estimateLevel(const int16_t *audioData, int32_t frame
powerFraction &= 0xffff;
}
- return power;
+ /* peak-to-peak is -32768 to 32767, but we are squared here. */
+ return (65536.0f * power + powerFraction) / (32768.0f * 32768.0f) / frames;
}
EffectTone::EffectTone()
@@ -494,23 +495,22 @@ int32_t AudioDSP::estimateLevel(const int16_t *input, int32_t frames, int32_t sa
}
/* Analyze both channels separately, pick the maximum power measured. */
- int maximumPower = 0;
+ float maximumPowerSquared = 0;
for (int channel = 0; channel < samplesPerFrame; channel ++) {
- int candidatePower = mCompression.estimateLevel(input + channel, frames, samplesPerFrame);
- if (candidatePower > maximumPower) {
- maximumPower = candidatePower;
+ float candidatePowerSquared = mCompression.estimateLevel(input + channel, frames, samplesPerFrame);
+ if (candidatePowerSquared > maximumPowerSquared) {
+ maximumPowerSquared = candidatePowerSquared;
}
}
- /* FIXME: code below should be ported to integer. */
- float signalPower = (65536.0f*maximumPower) / frames / 32768.0f / 32768.0f;
- /* -30 .. 0 dB. */
- float signalPowerDb = logf(signalPower + 1e-3f) / logf(10) * 10;
- /* target 83 dB SPL, and the weighter function peaks at -3 dB */
- signalPowerDb += 96 - 83 + 3;
+ /* -100 .. 0 dB. */
+ float signalPowerDb = logf(maximumPowerSquared + 1e-10f) / logf(10) * 10;
+ /* target 83 dB SPL, and add 6 dB to compensate for the weighter, whose
+ * peak is at -3 dB. */
+ signalPowerDb += 96 - 83 + 6;
- /* now we have an estimate of the signal power in range from
- * -96 dB to 0 dB. Now we estimate what level we want. */
+ /* now we have an estimate of the signal power, with 0 level around 83 dB.
+ * we now select the level to boost to. */
float desiredLevelDb = signalPowerDb / mCompression.mCompressionRatio;
/* turn back to multiplier */
diff --git a/libs/audioflinger/AudioDSP.h b/libs/audioflinger/AudioDSP.h
index 7ac1756..6187201 100644
--- a/libs/audioflinger/AudioDSP.h
+++ b/libs/audioflinger/AudioDSP.h
@@ -83,7 +83,7 @@ class EffectCompression : public Effect {
void configure(const float samplingFrequency);
void setRatio(float compressionRatio);
void process(int32_t* inout, int32_t frames);
- int32_t estimateLevel(const int16_t* audiodata, int32_t frames, int32_t framesPerSample);
+ float estimateLevel(const int16_t* audiodata, int32_t frames, int32_t framesPerSample);
};
class EffectTone : public Effect {