| OLD | NEW |
| 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/system_wrappers/include/critical_section_wrapper.h" | |
| 14 #include "webrtc/voice_engine/level_indicator.h" | 13 #include "webrtc/voice_engine/level_indicator.h" |
| 15 | 14 |
| 16 namespace webrtc { | 15 namespace webrtc { |
| 17 | 16 |
| 18 namespace voe { | 17 namespace voe { |
| 19 | 18 |
| 20 // Number of bars on the indicator. | 19 // Number of bars on the indicator. |
| 21 // 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 |
| 22 // in the range of 0-32 | 21 // in the range of 0-32 |
| 23 const int8_t permutation[33] = | 22 const int8_t permutation[33] = |
| 24 {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 {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}; |
| 25 | 24 |
| 26 | 25 |
| 27 AudioLevel::AudioLevel() : | 26 AudioLevel::AudioLevel() : |
| 28 _critSect(*CriticalSectionWrapper::CreateCriticalSection()), | |
| 29 _absMax(0), | 27 _absMax(0), |
| 30 _count(0), | 28 _count(0), |
| 31 _currentLevel(0), | 29 _currentLevel(0), |
| 32 _currentLevelFullRange(0) { | 30 _currentLevelFullRange(0) { |
| 33 } | 31 } |
| 34 | 32 |
| 35 AudioLevel::~AudioLevel() { | 33 AudioLevel::~AudioLevel() { |
| 36 delete &_critSect; | |
| 37 } | 34 } |
| 38 | 35 |
| 39 void AudioLevel::Clear() | 36 void AudioLevel::Clear() |
| 40 { | 37 { |
| 41 CriticalSectionScoped cs(&_critSect); | 38 rtc::CritScope cs(&_critSect); |
| 42 _absMax = 0; | 39 _absMax = 0; |
| 43 _count = 0; | 40 _count = 0; |
| 44 _currentLevel = 0; | 41 _currentLevel = 0; |
| 45 _currentLevelFullRange = 0; | 42 _currentLevelFullRange = 0; |
| 46 } | 43 } |
| 47 | 44 |
| 48 void AudioLevel::ComputeLevel(const AudioFrame& audioFrame) | 45 void AudioLevel::ComputeLevel(const AudioFrame& audioFrame) |
| 49 { | 46 { |
| 50 int16_t absValue(0); | 47 int16_t absValue(0); |
| 51 | 48 |
| 52 // Check speech level (works for 2 channels as well) | 49 // Check speech level (works for 2 channels as well) |
| 53 absValue = WebRtcSpl_MaxAbsValueW16( | 50 absValue = WebRtcSpl_MaxAbsValueW16( |
| 54 audioFrame.data_, | 51 audioFrame.data_, |
| 55 audioFrame.samples_per_channel_*audioFrame.num_channels_); | 52 audioFrame.samples_per_channel_*audioFrame.num_channels_); |
| 56 | 53 |
| 57 // Protect member access using a lock since this method is called on a | 54 // Protect member access using a lock since this method is called on a |
| 58 // dedicated audio thread in the RecordedDataIsAvailable() callback. | 55 // dedicated audio thread in the RecordedDataIsAvailable() callback. |
| 59 CriticalSectionScoped cs(&_critSect); | 56 rtc::CritScope cs(&_critSect); |
| 60 | 57 |
| 61 if (absValue > _absMax) | 58 if (absValue > _absMax) |
| 62 _absMax = absValue; | 59 _absMax = absValue; |
| 63 | 60 |
| 64 // Update level approximately 10 times per second | 61 // Update level approximately 10 times per second |
| 65 if (_count++ == kUpdateFrequency) | 62 if (_count++ == kUpdateFrequency) |
| 66 { | 63 { |
| 67 _currentLevelFullRange = _absMax; | 64 _currentLevelFullRange = _absMax; |
| 68 | 65 |
| 69 _count = 0; | 66 _count = 0; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 81 } | 78 } |
| 82 _currentLevel = permutation[position]; | 79 _currentLevel = permutation[position]; |
| 83 | 80 |
| 84 // Decay the absolute maximum (divide by 4) | 81 // Decay the absolute maximum (divide by 4) |
| 85 _absMax >>= 2; | 82 _absMax >>= 2; |
| 86 } | 83 } |
| 87 } | 84 } |
| 88 | 85 |
| 89 int8_t AudioLevel::Level() const | 86 int8_t AudioLevel::Level() const |
| 90 { | 87 { |
| 91 CriticalSectionScoped cs(&_critSect); | 88 rtc::CritScope cs(&_critSect); |
| 92 return _currentLevel; | 89 return _currentLevel; |
| 93 } | 90 } |
| 94 | 91 |
| 95 int16_t AudioLevel::LevelFullRange() const | 92 int16_t AudioLevel::LevelFullRange() const |
| 96 { | 93 { |
| 97 CriticalSectionScoped cs(&_critSect); | 94 rtc::CritScope cs(&_critSect); |
| 98 return _currentLevelFullRange; | 95 return _currentLevelFullRange; |
| 99 } | 96 } |
| 100 | 97 |
| 101 } // namespace voe | 98 } // namespace voe |
| 102 | 99 |
| 103 } // namespace webrtc | 100 } // namespace webrtc |
| OLD | NEW |