| * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| * Use of this source code is governed by a BSD-style license |
| * that can be found in the LICENSE file in the root of the source |
| * tree. An additional intellectual property rights grant can be found |
| * in the file PATENTS. All contributing project authors may |
| * be found in the AUTHORS file in the root of the source tree. |
| #include "level_indicator.h" |
| // Array for adding smothing to level changes (ad-hoc). |
| const WebRtc_UWord32 perm[] = |
| {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}; |
| LevelIndicator::LevelIndicator() |
| LevelIndicator::~LevelIndicator() |
| // Level is based on the highest absolute value for all samples. |
| void LevelIndicator::ComputeLevel(const WebRtc_Word16* speech, |
| const WebRtc_UWord16 nrOfSamples) |
| for(WebRtc_UWord32 i = 0; i < nrOfSamples; i++) |
| if(_count == TICKS_BEFORE_CALCULATION) |
| // Highest sample value maps directly to a level. |
| WebRtc_Word32 position = _max / 1000; |
| _currentLevel = perm[position]; |
| // The max value is decayed and stored so that it can be reused to slow |
| // down decreases in level. |
| WebRtc_Word32 LevelIndicator::GetLevel() |