LCOV - code coverage report
Current view: top level - media/webrtc/trunk/webrtc/voice_engine - level_indicator.cc (source / functions) Hit Total Coverage
Test: output.info Lines: 0 35 0.0 %
Date: 2017-07-14 16:53:18 Functions: 0 7 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :  *  Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
       3             :  *
       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.
       9             :  */
      10             : 
      11             : #include "webrtc/common_audio/signal_processing/include/signal_processing_library.h"
      12             : #include "webrtc/modules/include/module_common_types.h"
      13             : #include "webrtc/voice_engine/level_indicator.h"
      14             : 
      15             : namespace webrtc {
      16             : 
      17             : namespace voe {
      18             : 
      19             : // Number of bars on the indicator.
      20             : // Note that the number of elements is specified because we are indexing it
      21             : // in the range of 0-32
      22             : const int8_t permutation[33] =
      23             :     {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};
      24             : 
      25             : 
      26           0 : AudioLevel::AudioLevel() :
      27             :     _absMax(0),
      28             :     _count(0),
      29             :     _currentLevel(0),
      30           0 :     _currentLevelFullRange(0) {
      31           0 :   WebRtcSpl_Init();
      32           0 : }
      33             : 
      34           0 : AudioLevel::~AudioLevel() {
      35           0 : }
      36             : 
      37           0 : void AudioLevel::Clear()
      38             : {
      39           0 :     rtc::CritScope cs(&_critSect);
      40           0 :     _absMax = 0;
      41           0 :     _count = 0;
      42           0 :     _currentLevel = 0;
      43           0 :     _currentLevelFullRange = 0;
      44           0 : }
      45             : 
      46           0 : void AudioLevel::ComputeLevel(const AudioFrame& audioFrame)
      47             : {
      48           0 :     int16_t absValue(0);
      49             : 
      50             :     // Check speech level (works for 2 channels as well)
      51           0 :     absValue = WebRtcSpl_MaxAbsValueW16(
      52             :         audioFrame.data_,
      53           0 :         audioFrame.samples_per_channel_*audioFrame.num_channels_);
      54             : 
      55             :     // Protect member access using a lock since this method is called on a
      56             :     // dedicated audio thread in the RecordedDataIsAvailable() callback.
      57           0 :     rtc::CritScope cs(&_critSect);
      58             : 
      59           0 :     if (absValue > _absMax)
      60           0 :     _absMax = absValue;
      61             : 
      62             :     // Update level approximately 10 times per second
      63           0 :     if (_count++ == kUpdateFrequency)
      64             :     {
      65           0 :         _currentLevelFullRange = _absMax;
      66             : 
      67           0 :         _count = 0;
      68             : 
      69             :         // Highest value for a int16_t is 0x7fff = 32767
      70             :         // Divide with 1000 to get in the range of 0-32 which is the range of
      71             :         // the permutation vector
      72           0 :         int32_t position = _absMax/1000;
      73             : 
      74             :         // Make it less likely that the bar stays at position 0. I.e. only if
      75             :         // its in the range 0-250 (instead of 0-1000)
      76           0 :         if ((position == 0) && (_absMax > 250))
      77             :         {
      78           0 :             position = 1;
      79             :         }
      80           0 :         _currentLevel = permutation[position];
      81             : 
      82             :         // Decay the absolute maximum (divide by 4)
      83           0 :         _absMax >>= 2;
      84             :     }
      85           0 : }
      86             : 
      87           0 : int8_t AudioLevel::Level() const
      88             : {
      89           0 :     rtc::CritScope cs(&_critSect);
      90           0 :     return _currentLevel;
      91             : }
      92             : 
      93           0 : int16_t AudioLevel::LevelFullRange() const
      94             : {
      95           0 :     rtc::CritScope cs(&_critSect);
      96           0 :     return _currentLevelFullRange;
      97             : }
      98             : 
      99             : }  // namespace voe
     100             : 
     101             : }  // namespace webrtc

Generated by: LCOV version 1.13