Add AudioProcessingCaptureStats and a level estimator replacement
This adds an interface for accessing stats on the capture stream, and
adds a level estimator to report one of the stats.
Bug: webrtc:9947
Change-Id: Id472534fa2e04d46c9ab700671f620584a246afb
Reviewed-on: https://webrtc-review.googlesource.com/c/109587
Commit-Queue: Sam Zackrisson <saza@webrtc.org>
Reviewed-by: Per Ã…hgren <peah@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#25786}
diff --git a/modules/audio_processing/audio_processing_unittest.cc b/modules/audio_processing/audio_processing_unittest.cc
index 18e669f..6809ab9 100644
--- a/modules/audio_processing/audio_processing_unittest.cc
+++ b/modules/audio_processing/audio_processing_unittest.cc
@@ -2801,4 +2801,42 @@
EXPECT_FALSE(stats.delay_median_ms);
EXPECT_FALSE(stats.delay_standard_deviation_ms);
}
+
+TEST(ApmStatistics, ReportOutputRmsDbfs) {
+ ProcessingConfig processing_config = {
+ {{32000, 1}, {32000, 1}, {32000, 1}, {32000, 1}}};
+ AudioProcessing::Config config;
+
+ // Set up an audioframe.
+ AudioFrame frame;
+ frame.num_channels_ = 1;
+ SetFrameSampleRate(&frame, AudioProcessing::NativeRate::kSampleRate48kHz);
+
+ // Fill the audio frame with a sawtooth pattern.
+ int16_t* ptr = frame.mutable_data();
+ for (size_t i = 0; i < frame.kMaxDataSizeSamples; i++) {
+ ptr[i] = 10000 * ((i % 3) - 1);
+ }
+
+ std::unique_ptr<AudioProcessing> apm(AudioProcessingBuilder().Create());
+ apm->Initialize(processing_config);
+
+ // If not enabled, no metric should be reported.
+ EXPECT_EQ(apm->ProcessStream(&frame), 0);
+ EXPECT_FALSE(apm->GetStatistics(false).output_rms_dbfs);
+
+ // If enabled, metrics should be reported.
+ config.level_estimation.enabled = true;
+ apm->ApplyConfig(config);
+ EXPECT_EQ(apm->ProcessStream(&frame), 0);
+ auto stats = apm->GetStatistics(false);
+ EXPECT_TRUE(stats.output_rms_dbfs);
+ EXPECT_GE(*stats.output_rms_dbfs, 0);
+
+ // If re-disabled, the value is again not reported.
+ config.level_estimation.enabled = false;
+ apm->ApplyConfig(config);
+ EXPECT_EQ(apm->ProcessStream(&frame), 0);
+ EXPECT_FALSE(apm->GetStatistics(false).output_rms_dbfs);
+}
} // namespace webrtc