2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "webrtc/modules/audio_conference_mixer/source/level_indicator.h"
14 // Array for adding smothing to level changes (ad-hoc).
15 const uint32_t perm[] =
16 {0,1,2,3,4,4,5,5,5,5,6,6,6,6,6,7,7,7,7,8,8,8,9,9,9,9,9,9,9,9,9,9,9};
18 LevelIndicator::LevelIndicator()
25 LevelIndicator::~LevelIndicator()
29 // Level is based on the highest absolute value for all samples.
30 void LevelIndicator::ComputeLevel(const int16_t* speech,
31 const uint16_t nrOfSamples)
34 for(uint32_t i = 0; i < nrOfSamples; i++)
46 // Absolute max value.
52 if(_count == TICKS_BEFORE_CALCULATION)
54 // Highest sample value maps directly to a level.
55 int32_t position = _max / 1000;
56 if ((position == 0) &&
61 _currentLevel = perm[position];
62 // The max value is decayed and stored so that it can be reused to slow
63 // down decreases in level.
71 int32_t LevelIndicator::GetLevel()