From b995bb86dfca1787022197571bca72e319d5fb3e Mon Sep 17 00:00:00 2001 From: Alessio Bazzica Date: Wed, 31 Mar 2021 09:48:49 +0200 Subject: [PATCH] AGC2 size_t -> int Bug: webrtc:7494 Change-Id: I5ecf242e83b509931c1764a37339d11506c5afc6 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/213341 Reviewed-by: Sam Zackrisson Commit-Queue: Alessio Bazzica Cr-Commit-Position: refs/heads/master@{#33600} --- modules/audio_processing/agc2/agc2_common.h | 18 +++++++++--------- .../agc2/fixed_digital_level_estimator.cc | 16 ++++++++-------- .../agc2/fixed_digital_level_estimator.h | 8 ++++---- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/modules/audio_processing/agc2/agc2_common.h b/modules/audio_processing/agc2/agc2_common.h index 5d01100eb7..594a37e291 100644 --- a/modules/audio_processing/agc2/agc2_common.h +++ b/modules/audio_processing/agc2/agc2_common.h @@ -19,9 +19,9 @@ constexpr float kMinFloatS16Value = -32768.f; constexpr float kMaxFloatS16Value = 32767.f; constexpr float kMaxAbsFloatS16Value = 32768.0f; -constexpr size_t kFrameDurationMs = 10; -constexpr size_t kSubFramesInFrame = 20; -constexpr size_t kMaximalNumberOfSamplesPerChannel = 480; +constexpr int kFrameDurationMs = 10; +constexpr int kSubFramesInFrame = 20; +constexpr int kMaximalNumberOfSamplesPerChannel = 480; constexpr float kAttackFilterConstant = 0.f; @@ -38,7 +38,7 @@ constexpr float kLimiterThresholdForAgcGainDbfs = -kHeadroomDbfs; constexpr float kVadConfidenceThreshold = 0.9f; // The amount of 'memory' of the Level Estimator. Decides leak factors. -constexpr size_t kFullBufferSizeMs = 1200; +constexpr int kFullBufferSizeMs = 1200; constexpr float kFullBufferLeakFactor = 1.f - 1.f / kFullBufferSizeMs; constexpr float kInitialSpeechLevelEstimateDbfs = -30.f; @@ -51,12 +51,12 @@ constexpr int kDefaultLevelEstimatorAdjacentSpeechFramesThreshold = 1; constexpr float kDefaultInitialSaturationMarginDb = 20.f; constexpr float kDefaultExtraSaturationMarginDb = 2.f; -constexpr size_t kPeakEnveloperSuperFrameLengthMs = 400; +constexpr int kPeakEnveloperSuperFrameLengthMs = 400; static_assert(kFullBufferSizeMs % kPeakEnveloperSuperFrameLengthMs == 0, "Full buffer size should be a multiple of super frame length for " "optimal Saturation Protector performance."); -constexpr size_t kPeakEnveloperBufferSize = +constexpr int kPeakEnveloperBufferSize = kFullBufferSizeMs / kPeakEnveloperSuperFrameLengthMs + 1; // This value is 10 ** (-1/20 * frame_size_ms / satproc_attack_ms), @@ -76,9 +76,9 @@ constexpr float kDecayFilterConstant = 0.9998848773724686f; // Number of interpolation points for each region of the limiter. // These values have been tuned to limit the interpolated gain curve error given // the limiter parameters and allowing a maximum error of +/- 32768^-1. -constexpr size_t kInterpolatedGainCurveKneePoints = 22; -constexpr size_t kInterpolatedGainCurveBeyondKneePoints = 10; -constexpr size_t kInterpolatedGainCurveTotalPoints = +constexpr int kInterpolatedGainCurveKneePoints = 22; +constexpr int kInterpolatedGainCurveBeyondKneePoints = 10; +constexpr int kInterpolatedGainCurveTotalPoints = kInterpolatedGainCurveKneePoints + kInterpolatedGainCurveBeyondKneePoints; } // namespace webrtc diff --git a/modules/audio_processing/agc2/fixed_digital_level_estimator.cc b/modules/audio_processing/agc2/fixed_digital_level_estimator.cc index 971f4f62b7..9636136e4a 100644 --- a/modules/audio_processing/agc2/fixed_digital_level_estimator.cc +++ b/modules/audio_processing/agc2/fixed_digital_level_estimator.cc @@ -25,7 +25,7 @@ constexpr float kInitialFilterStateLevel = 0.f; } // namespace FixedDigitalLevelEstimator::FixedDigitalLevelEstimator( - size_t sample_rate_hz, + int sample_rate_hz, ApmDataDumper* apm_data_dumper) : apm_data_dumper_(apm_data_dumper), filter_state_level_(kInitialFilterStateLevel) { @@ -52,8 +52,8 @@ std::array FixedDigitalLevelEstimator::ComputeLevel( for (size_t channel_idx = 0; channel_idx < float_frame.num_channels(); ++channel_idx) { const auto channel = float_frame.channel(channel_idx); - for (size_t sub_frame = 0; sub_frame < kSubFramesInFrame; ++sub_frame) { - for (size_t sample_in_sub_frame = 0; + for (int sub_frame = 0; sub_frame < kSubFramesInFrame; ++sub_frame) { + for (int sample_in_sub_frame = 0; sample_in_sub_frame < samples_in_sub_frame_; ++sample_in_sub_frame) { envelope[sub_frame] = std::max(envelope[sub_frame], @@ -66,14 +66,14 @@ std::array FixedDigitalLevelEstimator::ComputeLevel( // Make sure envelope increases happen one step earlier so that the // corresponding *gain decrease* doesn't miss a sudden signal // increase due to interpolation. - for (size_t sub_frame = 0; sub_frame < kSubFramesInFrame - 1; ++sub_frame) { + for (int sub_frame = 0; sub_frame < kSubFramesInFrame - 1; ++sub_frame) { if (envelope[sub_frame] < envelope[sub_frame + 1]) { envelope[sub_frame] = envelope[sub_frame + 1]; } } // Add attack / decay smoothing. - for (size_t sub_frame = 0; sub_frame < kSubFramesInFrame; ++sub_frame) { + for (int sub_frame = 0; sub_frame < kSubFramesInFrame; ++sub_frame) { const float envelope_value = envelope[sub_frame]; if (envelope_value > filter_state_level_) { envelope[sub_frame] = envelope_value * (1 - kAttackFilterConstant) + @@ -97,9 +97,9 @@ std::array FixedDigitalLevelEstimator::ComputeLevel( return envelope; } -void FixedDigitalLevelEstimator::SetSampleRate(size_t sample_rate_hz) { - samples_in_frame_ = rtc::CheckedDivExact(sample_rate_hz * kFrameDurationMs, - static_cast(1000)); +void FixedDigitalLevelEstimator::SetSampleRate(int sample_rate_hz) { + samples_in_frame_ = + rtc::CheckedDivExact(sample_rate_hz * kFrameDurationMs, 1000); samples_in_sub_frame_ = rtc::CheckedDivExact(samples_in_frame_, kSubFramesInFrame); CheckParameterCombination(); diff --git a/modules/audio_processing/agc2/fixed_digital_level_estimator.h b/modules/audio_processing/agc2/fixed_digital_level_estimator.h index aa84a2e0f1..d96aedaf9e 100644 --- a/modules/audio_processing/agc2/fixed_digital_level_estimator.h +++ b/modules/audio_processing/agc2/fixed_digital_level_estimator.h @@ -31,7 +31,7 @@ class FixedDigitalLevelEstimator { // kSubFramesInSample. For kFrameDurationMs=10 and // kSubFramesInSample=20, this means that sample_rate_hz has to be // divisible by 2000. - FixedDigitalLevelEstimator(size_t sample_rate_hz, + FixedDigitalLevelEstimator(int sample_rate_hz, ApmDataDumper* apm_data_dumper); // The input is assumed to be in FloatS16 format. Scaled input will @@ -43,7 +43,7 @@ class FixedDigitalLevelEstimator { // Rate may be changed at any time (but not concurrently) from the // value passed to the constructor. The class is not thread safe. - void SetSampleRate(size_t sample_rate_hz); + void SetSampleRate(int sample_rate_hz); // Resets the level estimator internal state. void Reset(); @@ -55,8 +55,8 @@ class FixedDigitalLevelEstimator { ApmDataDumper* const apm_data_dumper_ = nullptr; float filter_state_level_; - size_t samples_in_frame_; - size_t samples_in_sub_frame_; + int samples_in_frame_; + int samples_in_sub_frame_; RTC_DISALLOW_COPY_AND_ASSIGN(FixedDigitalLevelEstimator); };