| 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 | namespace webrtc { |
| 14 |
| 15 | Histograms::Histograms() { |
| 16 | Clear(); |
| 17 | } |
| 18 |
| 19 | void Histograms::Clear() { |
| 20 | lrt_.fill(0); |
| 21 | spectral_flatness_.fill(0); |
| 22 | spectral_diff_.fill(0); |
| 23 | } |
| 24 |
| 25 | void Histograms::Update(const SignalModel& features_) { |
| 26 | // Update the histogram for the LRT. |
| 27 | constexpr float kOneByBinSizeLrt = 1.f / kBinSizeLrt; |
| 28 | if (features_.lrt < kHistogramSize * kBinSizeLrt && features_.lrt >= 0.f) { |
| 29 | ++lrt_[kOneByBinSizeLrt * features_.lrt]; |
| 30 | } |
| 31 |
| 32 | // Update histogram for the spectral flatness. |
| 33 | constexpr float kOneByBinSizeSpecFlat = 1.f / kBinSizeSpecFlat; |
| 34 | if (features_.spectral_flatness < kHistogramSize * kBinSizeSpecFlat && |
| 35 | features_.spectral_flatness >= 0.f) { |
| 36 | ++spectral_flatness_[features_.spectral_flatness * kOneByBinSizeSpecFlat]; |
| 37 | } |
| 38 |
| 39 | // Update histogram for the spectral difference. |
| 40 | constexpr float kOneByBinSizeSpecDiff = 1.f / kBinSizeSpecDiff; |
| 41 | if (features_.spectral_diff < kHistogramSize * kBinSizeSpecDiff && |
| 42 | features_.spectral_diff >= 0.f) { |
| 43 | ++spectral_diff_[features_.spectral_diff * kOneByBinSizeSpecDiff]; |
| 44 | } |
| 45 | } |
| 46 |
| 47 | } // namespace webrtc |
| 48 |