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

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

Issue 2230823004: Added a level indicator to new mixer. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@mixer_gn_fixes
Patch Set: Fake participant returns frame copy. Created 4 years, 4 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
1 /* 1 /*
2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. 2 * Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license 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 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 6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may 7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree. 8 * be found in the AUTHORS file in the root of the source tree.
9 */ 9 */
10 10
11 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h" 11 #include "webrtc/common_audio/signal_processing/include/signal_processing_librar y.h"
12 #include "webrtc/modules/include/module_common_types.h" 12 #include "webrtc/modules/include/module_common_types.h"
13 #include "webrtc/voice_engine/level_indicator.h" 13 #include "webrtc/voice_engine/level_indicator.h"
14 14
15 namespace webrtc { 15 namespace webrtc {
16 16
17 namespace voe { 17 namespace voe {
18 18
19 // Number of bars on the indicator. 19 // Number of bars on the indicator.
20 // Note that the number of elements is specified because we are indexing it 20 // Note that the number of elements is specified because we are indexing it
21 // in the range of 0-32 21 // in the range of 0-32
22 const int8_t permutation[33] = 22 const int8_t permutation[33] = {0, 1, 2, 3, 4, 4, 5, 5, 5, 5, 6,
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}; 23 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8,
24 24 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9};
25 25
26 AudioLevel::AudioLevel() : 26 AudioLevel::AudioLevel() :
27 _absMax(0), 27 _absMax(0),
28 _count(0), 28 _count(0),
29 _currentLevel(0), 29 _currentLevel(0),
30 _currentLevelFullRange(0) { 30 _currentLevelFullRange(0) {
31 WebRtcSpl_Init();
minyue-webrtc 2016/08/15 06:26:15 I think clang format made irrelevant changes to th
aleloi 2016/08/15 11:52:13 Acknowledged.
minyue-webrtc 2016/08/15 15:58:37 I think there are still too many lines of changes.
31 } 32 }
32 33
33 AudioLevel::~AudioLevel() { 34 AudioLevel::~AudioLevel() {
34 } 35 }
35 36
36 void AudioLevel::Clear() 37 void AudioLevel::Clear() {
37 { 38 rtc::CritScope cs(&_critSect);
38 rtc::CritScope cs(&_critSect); 39 _absMax = 0;
39 _absMax = 0; 40 _count = 0;
40 _count = 0; 41 _currentLevel = 0;
41 _currentLevel = 0; 42 _currentLevelFullRange = 0;
42 _currentLevelFullRange = 0;
43 } 43 }
44 44
45 void AudioLevel::ComputeLevel(const AudioFrame& audioFrame) 45 void AudioLevel::ComputeLevel(const AudioFrame& audioFrame) {
46 { 46 int16_t absValue(0);
47 int16_t absValue(0);
48 47
49 // Check speech level (works for 2 channels as well) 48 // Check speech level (works for 2 channels as well)
50 absValue = WebRtcSpl_MaxAbsValueW16( 49 absValue = WebRtcSpl_MaxAbsValueW16(
51 audioFrame.data_, 50 audioFrame.data_,
52 audioFrame.samples_per_channel_*audioFrame.num_channels_); 51 audioFrame.samples_per_channel_ * audioFrame.num_channels_);
53 52
54 // Protect member access using a lock since this method is called on a 53 // Protect member access using a lock since this method is called on a
55 // dedicated audio thread in the RecordedDataIsAvailable() callback. 54 // dedicated audio thread in the RecordedDataIsAvailable() callback.
56 rtc::CritScope cs(&_critSect); 55 rtc::CritScope cs(&_critSect);
57 56
58 if (absValue > _absMax) 57 if (absValue > _absMax)
59 _absMax = absValue; 58 _absMax = absValue;
60 59
61 // Update level approximately 10 times per second 60 // Update level approximately 10 times per second
62 if (_count++ == kUpdateFrequency) 61 if (_count++ == kUpdateFrequency) {
63 { 62 _currentLevelFullRange = _absMax;
64 _currentLevelFullRange = _absMax;
65 63
66 _count = 0; 64 _count = 0;
67 65
68 // Highest value for a int16_t is 0x7fff = 32767 66 // Highest value for a int16_t is 0x7fff = 32767
69 // Divide with 1000 to get in the range of 0-32 which is the range of 67 // Divide with 1000 to get in the range of 0-32 which is the range of
70 // the permutation vector 68 // the permutation vector
71 int32_t position = _absMax/1000; 69 int32_t position = _absMax / 1000;
72 70
73 // Make it less likely that the bar stays at position 0. I.e. only if 71 // Make it less likely that the bar stays at position 0. I.e. only if
74 // its in the range 0-250 (instead of 0-1000) 72 // its in the range 0-250 (instead of 0-1000)
75 if ((position == 0) && (_absMax > 250)) 73 if ((position == 0) && (_absMax > 250)) {
76 { 74 position = 1;
77 position = 1; 75 }
78 } 76 _currentLevel = permutation[position];
79 _currentLevel = permutation[position];
80 77
81 // Decay the absolute maximum (divide by 4) 78 // Decay the absolute maximum (divide by 4)
82 _absMax >>= 2; 79 _absMax >>= 2;
83 } 80 }
84 } 81 }
85 82
86 int8_t AudioLevel::Level() const 83 int8_t AudioLevel::Level() const {
87 { 84 rtc::CritScope cs(&_critSect);
88 rtc::CritScope cs(&_critSect); 85 return _currentLevel;
89 return _currentLevel;
90 } 86 }
91 87
92 int16_t AudioLevel::LevelFullRange() const 88 int16_t AudioLevel::LevelFullRange() const {
93 { 89 rtc::CritScope cs(&_critSect);
94 rtc::CritScope cs(&_critSect); 90 return _currentLevelFullRange;
95 return _currentLevelFullRange;
96 } 91 }
97 92
98 } // namespace voe 93 } // namespace voe
99 94
100 } // namespace webrtc 95 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698