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 |
(...skipping 30 matching lines...) Expand all Loading... |
41 } | 41 } |
42 | 42 |
43 void AudioLevel::Clear() { | 43 void AudioLevel::Clear() { |
44 rtc::CritScope cs(&crit_sect_); | 44 rtc::CritScope cs(&crit_sect_); |
45 abs_max_ = 0; | 45 abs_max_ = 0; |
46 count_ = 0; | 46 count_ = 0; |
47 current_level_ = 0; | 47 current_level_ = 0; |
48 current_level_full_range_ = 0; | 48 current_level_full_range_ = 0; |
49 } | 49 } |
50 | 50 |
51 void AudioLevel::ComputeLevel(const AudioFrame& audioFrame) { | 51 double AudioLevel::TotalEnergy() const { |
| 52 rtc::CritScope cs(&crit_sect_); |
| 53 return total_energy_; |
| 54 } |
| 55 |
| 56 double AudioLevel::TotalDuration() const { |
| 57 rtc::CritScope cs(&crit_sect_); |
| 58 return total_duration_; |
| 59 } |
| 60 |
| 61 void AudioLevel::ComputeLevel(const AudioFrame& audioFrame, double duration) { |
52 // Check speech level (works for 2 channels as well) | 62 // Check speech level (works for 2 channels as well) |
53 int16_t abs_value = audioFrame.muted() ? 0 : | 63 int16_t abs_value = audioFrame.muted() ? 0 : |
54 WebRtcSpl_MaxAbsValueW16( | 64 WebRtcSpl_MaxAbsValueW16( |
55 audioFrame.data(), | 65 audioFrame.data(), |
56 audioFrame.samples_per_channel_ * audioFrame.num_channels_); | 66 audioFrame.samples_per_channel_ * audioFrame.num_channels_); |
57 | 67 |
58 // Protect member access using a lock since this method is called on a | 68 // Protect member access using a lock since this method is called on a |
59 // dedicated audio thread in the RecordedDataIsAvailable() callback. | 69 // dedicated audio thread in the RecordedDataIsAvailable() callback. |
60 rtc::CritScope cs(&crit_sect_); | 70 rtc::CritScope cs(&crit_sect_); |
61 | 71 |
(...skipping 14 matching lines...) Expand all Loading... |
76 // Make it less likely that the bar stays at position 0. I.e. only if it's | 86 // Make it less likely that the bar stays at position 0. I.e. only if it's |
77 // in the range 0-250 (instead of 0-1000) | 87 // in the range 0-250 (instead of 0-1000) |
78 if ((position == 0) && (abs_max_ > 250)) { | 88 if ((position == 0) && (abs_max_ > 250)) { |
79 position = 1; | 89 position = 1; |
80 } | 90 } |
81 current_level_ = kPermutation[position]; | 91 current_level_ = kPermutation[position]; |
82 | 92 |
83 // Decay the absolute maximum (divide by 4) | 93 // Decay the absolute maximum (divide by 4) |
84 abs_max_ >>= 2; | 94 abs_max_ >>= 2; |
85 } | 95 } |
| 96 |
| 97 // See the description for "totalAudioEnergy" in the WebRTC stats spec |
| 98 // (https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudi
oenergy) |
| 99 // for an explanation of these formulas. In short, we need a value that can |
| 100 // be used to compute RMS audio levels over different time intervals, by |
| 101 // taking the difference between the results from two getStats calls. To do |
| 102 // this, the value needs to be of units "squared sample value * time". |
| 103 double additional_energy = |
| 104 static_cast<double>(current_level_full_range_) / INT16_MAX; |
| 105 additional_energy *= additional_energy; |
| 106 total_energy_ += additional_energy * duration; |
| 107 total_duration_ += duration; |
86 } | 108 } |
87 | 109 |
88 } // namespace voe | 110 } // namespace voe |
89 } // namespace webrtc | 111 } // namespace webrtc |
OLD | NEW |