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

Unified Diff: webrtc/voice_engine/audio_level.cc

Issue 2984473002: Move total audio energy and duration tracking to AudioLevel and protect with existing critial secti… (Closed)
Patch Set: rebase Created 3 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webrtc/voice_engine/audio_level.h ('k') | webrtc/voice_engine/channel.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/voice_engine/audio_level.cc
diff --git a/webrtc/voice_engine/audio_level.cc b/webrtc/voice_engine/audio_level.cc
index 27a7dde1b2b25c2faefa1aa6a8d6641c07776d37..ab4114987cc794ee31ad9470368036d9c7742a2a 100644
--- a/webrtc/voice_engine/audio_level.cc
+++ b/webrtc/voice_engine/audio_level.cc
@@ -48,7 +48,17 @@ void AudioLevel::Clear() {
current_level_full_range_ = 0;
}
-void AudioLevel::ComputeLevel(const AudioFrame& audioFrame) {
+double AudioLevel::TotalEnergy() const {
+ rtc::CritScope cs(&crit_sect_);
+ return total_energy_;
+}
+
+double AudioLevel::TotalDuration() const {
+ rtc::CritScope cs(&crit_sect_);
+ return total_duration_;
+}
+
+void AudioLevel::ComputeLevel(const AudioFrame& audioFrame, double duration) {
// Check speech level (works for 2 channels as well)
int16_t abs_value = audioFrame.muted() ? 0 :
WebRtcSpl_MaxAbsValueW16(
@@ -83,6 +93,18 @@ void AudioLevel::ComputeLevel(const AudioFrame& audioFrame) {
// Decay the absolute maximum (divide by 4)
abs_max_ >>= 2;
}
+
+ // See the description for "totalAudioEnergy" in the WebRTC stats spec
+ // (https://w3c.github.io/webrtc-stats/#dom-rtcmediastreamtrackstats-totalaudioenergy)
+ // for an explanation of these formulas. In short, we need a value that can
+ // be used to compute RMS audio levels over different time intervals, by
+ // taking the difference between the results from two getStats calls. To do
+ // this, the value needs to be of units "squared sample value * time".
+ double additional_energy =
+ static_cast<double>(current_level_full_range_) / INT16_MAX;
+ additional_energy *= additional_energy;
+ total_energy_ += additional_energy * duration;
+ total_duration_ += duration;
}
} // namespace voe
« no previous file with comments | « webrtc/voice_engine/audio_level.h ('k') | webrtc/voice_engine/channel.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698