diff --git a/modules/audio_processing/agc2/noise_level_estimator.cc b/modules/audio_processing/agc2/noise_level_estimator.cc index 9fb1c24b65..691513b509 100644 --- a/modules/audio_processing/agc2/noise_level_estimator.cc +++ b/modules/audio_processing/agc2/noise_level_estimator.cc @@ -72,6 +72,7 @@ class NoiseFloorEstimator : public NoiseLevelEstimator { "noise levels."); NoiseFloorEstimator(ApmDataDumper* data_dumper) : data_dumper_(data_dumper) { + RTC_DCHECK(data_dumper_); // Initially assume that 48 kHz will be used. `Analyze()` will detect the // used sample rate and call `Initialize()` again if needed. Initialize(/*sample_rate_hz=*/48000); @@ -91,8 +92,9 @@ class NoiseFloorEstimator : public NoiseLevelEstimator { const float frame_energy = FrameEnergy(frame); if (frame_energy <= min_noise_energy_) { // Ignore frames when muted or below the minimum measurable energy. - data_dumper_->DumpRaw("agc2_noise_floor_estimator_preliminary_level", - noise_energy_); + if (data_dumper_) + data_dumper_->DumpRaw("agc2_noise_floor_estimator_preliminary_level", + noise_energy_); return EnergyToDbfs(noise_energy_, static_cast(frame.samples_per_channel())); } @@ -104,8 +106,9 @@ class NoiseFloorEstimator : public NoiseLevelEstimator { preliminary_noise_energy_ = frame_energy; preliminary_noise_energy_set_ = true; } - data_dumper_->DumpRaw("agc2_noise_floor_estimator_preliminary_level", - preliminary_noise_energy_); + if (data_dumper_) + data_dumper_->DumpRaw("agc2_noise_floor_estimator_preliminary_level", + preliminary_noise_energy_); if (counter_ == 0) { // Full period observed. @@ -128,8 +131,13 @@ class NoiseFloorEstimator : public NoiseLevelEstimator { noise_energy_ = std::min(noise_energy_, preliminary_noise_energy_); counter_--; } - return EnergyToDbfs(noise_energy_, - static_cast(frame.samples_per_channel())); + + float noise_rms_dbfs = EnergyToDbfs( + noise_energy_, static_cast(frame.samples_per_channel())); + if (data_dumper_) + data_dumper_->DumpRaw("agc2_noise_rms_dbfs", noise_rms_dbfs); + + return noise_rms_dbfs; } private: