Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(184)

Side by Side Diff: webrtc/voice_engine/level_indicator.cc

Issue 2731993002: Update formatting of AudioLevel class (Closed)
Patch Set: Change file names Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
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_librar y.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 AudioLevel::AudioLevel() :
27 _absMax(0),
28 _count(0),
29 _currentLevel(0),
30 _currentLevelFullRange(0) {
31 WebRtcSpl_Init();
32 }
33
34 AudioLevel::~AudioLevel() {
35 }
36
37 void AudioLevel::Clear()
38 {
39 rtc::CritScope cs(&_critSect);
40 _absMax = 0;
41 _count = 0;
42 _currentLevel = 0;
43 _currentLevelFullRange = 0;
44 }
45
46 void AudioLevel::ComputeLevel(const AudioFrame& audioFrame)
47 {
48 int16_t absValue(0);
49
50 // Check speech level (works for 2 channels as well)
51 absValue = WebRtcSpl_MaxAbsValueW16(
52 audioFrame.data_,
53 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 rtc::CritScope cs(&_critSect);
58
59 if (absValue > _absMax)
60 _absMax = absValue;
61
62 // Update level approximately 10 times per second
63 if (_count++ == kUpdateFrequency)
64 {
65 _currentLevelFullRange = _absMax;
66
67 _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 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 if ((position == 0) && (_absMax > 250))
77 {
78 position = 1;
79 }
80 _currentLevel = permutation[position];
81
82 // Decay the absolute maximum (divide by 4)
83 _absMax >>= 2;
84 }
85 }
86
87 int8_t AudioLevel::Level() const
88 {
89 rtc::CritScope cs(&_critSect);
90 return _currentLevel;
91 }
92
93 int16_t AudioLevel::LevelFullRange() const
94 {
95 rtc::CritScope cs(&_critSect);
96 return _currentLevelFullRange;
97 }
98
99 } // namespace voe
100
101 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698