histograms.cc (1659B)
1 /* 2 * Copyright (c) 2019 The WebRTC project authors. All Rights Reserved. 3 * 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 6 * tree. An additional intellectual property rights grant can be found 7 * in the file PATENTS. All contributing project authors may 8 * be found in the AUTHORS file in the root of the source tree. 9 */ 10 11 #include "modules/audio_processing/ns/histograms.h" 12 13 #include "modules/audio_processing/ns/ns_common.h" 14 #include "modules/audio_processing/ns/signal_model.h" 15 16 namespace webrtc { 17 18 Histograms::Histograms() { 19 Clear(); 20 } 21 22 void Histograms::Clear() { 23 lrt_.fill(0); 24 spectral_flatness_.fill(0); 25 spectral_diff_.fill(0); 26 } 27 28 void Histograms::Update(const SignalModel& features_) { 29 // Update the histogram for the LRT. 30 constexpr float kOneByBinSizeLrt = 1.f / kBinSizeLrt; 31 if (features_.lrt < kHistogramSize * kBinSizeLrt && features_.lrt >= 0.f) { 32 ++lrt_[kOneByBinSizeLrt * features_.lrt]; 33 } 34 35 // Update histogram for the spectral flatness. 36 constexpr float kOneByBinSizeSpecFlat = 1.f / kBinSizeSpecFlat; 37 if (features_.spectral_flatness < kHistogramSize * kBinSizeSpecFlat && 38 features_.spectral_flatness >= 0.f) { 39 ++spectral_flatness_[features_.spectral_flatness * kOneByBinSizeSpecFlat]; 40 } 41 42 // Update histogram for the spectral difference. 43 constexpr float kOneByBinSizeSpecDiff = 1.f / kBinSizeSpecDiff; 44 if (features_.spectral_diff < kHistogramSize * kBinSizeSpecDiff && 45 features_.spectral_diff >= 0.f) { 46 ++spectral_diff_[features_.spectral_diff * kOneByBinSizeSpecDiff]; 47 } 48 } 49 50 } // namespace webrtc