#include "modules/audio_processing/agc2/input_volume_controller.h"
#include <algorithm>
#include <fstream>
#include <limits>
#include <string>
#include <vector>
#include "rtc_base/numerics/safe_minmax.h"
#include "rtc_base/strings/string_builder.h"
#include "system_wrappers/include/metrics.h"
#include "test/field_trial.h"
#include "test/gmock.h"
#include "test/gtest.h"
#include "test/testsupport/file_utils.h"
_;
AtLeast;
DoAll;
Return;
SetArgPointee;
namespace webrtc {
namespace {
constexpr int kSampleRateHz = …;
constexpr int kNumChannels = …;
constexpr int kInitialInputVolume = …;
constexpr int kClippedMin = …;
constexpr float kAboveClippedThreshold = …;
constexpr int kMinMicLevel = …;
constexpr int kClippedLevelStep = …;
constexpr float kClippedRatioThreshold = …;
constexpr int kClippedWaitFrames = …;
constexpr float kHighSpeechProbability = …;
constexpr float kLowSpeechProbability = …;
constexpr float kSpeechLevel = …;
constexpr float kSpeechProbabilityThreshold = …;
constexpr float kSpeechRatioThreshold = …;
constexpr float kMinSample = …;
constexpr float kMaxSample = …;
ClippingPredictorConfig;
InputVolumeControllerConfig;
constexpr ClippingPredictorConfig kDefaultClippingPredictorConfig{ … };
std::unique_ptr<InputVolumeController> CreateInputVolumeController(
int clipped_level_step = kClippedLevelStep,
float clipped_ratio_threshold = kClippedRatioThreshold,
int clipped_wait_frames = kClippedWaitFrames,
bool enable_clipping_predictor = false,
int update_input_volume_wait_frames = 0) { … }
void WriteAudioBufferSamples(float samples_value,
float clipped_ratio,
AudioBuffer& audio_buffer) { … }
void WriteAlternatingAudioBufferSamples(float samples_value,
AudioBuffer& audio_buffer) { … }
class SpeechSamplesReader { … };
float UpdateRecommendedInputVolume(MonoInputVolumeController& mono_controller,
int applied_input_volume,
float speech_probability,
absl::optional<float> rms_error_dbfs) { … }
}
constexpr InputVolumeControllerConfig GetInputVolumeControllerTestConfig() { … }
class InputVolumeControllerTestHelper { … };
class InputVolumeControllerChannelSampleRateTest
: public ::testing::TestWithParam<std::tuple<int, int>> { … };
TEST_P(InputVolumeControllerChannelSampleRateTest, CheckIsAlive) { … }
INSTANTIATE_TEST_SUITE_P(…);
class InputVolumeControllerParametrizedTest
: public ::testing::TestWithParam<int> { … };
TEST_P(InputVolumeControllerParametrizedTest,
StartupMinVolumeConfigurationRespectedWhenAppliedInputVolumeAboveMin) { … }
TEST_P(
InputVolumeControllerParametrizedTest,
StartupMinVolumeConfigurationRespectedWhenAppliedInputVolumeMaybeBelowMin) { … }
TEST_P(InputVolumeControllerParametrizedTest,
StartupMinVolumeRespectedWhenAppliedVolumeNonZero) { … }
TEST_P(InputVolumeControllerParametrizedTest,
MinVolumeRepeatedlyRespectedWhenAppliedVolumeNonZero) { … }
TEST_P(InputVolumeControllerParametrizedTest,
StartupMinVolumeRespectedOnceWhenAppliedVolumeZero) { … }
TEST_P(InputVolumeControllerParametrizedTest, MicVolumeResponseToRmsError) { … }
TEST_P(InputVolumeControllerParametrizedTest, MicVolumeIsLimited) { … }
TEST_P(InputVolumeControllerParametrizedTest, NoActionWhileMuted) { … }
TEST_P(InputVolumeControllerParametrizedTest,
UnmutingChecksVolumeWithoutRaising) { … }
TEST_P(InputVolumeControllerParametrizedTest, UnmutingRaisesTooLowVolume) { … }
TEST_P(InputVolumeControllerParametrizedTest,
ManualLevelChangeResultsInNoSetMicCall) { … }
TEST_P(InputVolumeControllerParametrizedTest,
RecoveryAfterManualLevelChangeFromMax) { … }
TEST_P(InputVolumeControllerParametrizedTest,
EnforceMinInputVolumeDuringUpwardsAdjustment) { … }
TEST_P(InputVolumeControllerParametrizedTest,
RecoveryAfterManualLevelChangeBelowMin) { … }
TEST_P(InputVolumeControllerParametrizedTest, NoClippingHasNoImpact) { … }
TEST_P(InputVolumeControllerParametrizedTest,
ClippingUnderThresholdHasNoImpact) { … }
TEST_P(InputVolumeControllerParametrizedTest, ClippingLowersVolume) { … }
TEST_P(InputVolumeControllerParametrizedTest,
WaitingPeriodBetweenClippingChecks) { … }
TEST_P(InputVolumeControllerParametrizedTest, ClippingLoweringIsLimited) { … }
TEST_P(InputVolumeControllerParametrizedTest,
ClippingMaxIsRespectedWhenEqualToLevel) { … }
TEST_P(InputVolumeControllerParametrizedTest,
ClippingMaxIsRespectedWhenHigherThanLevel) { … }
TEST_P(InputVolumeControllerParametrizedTest, UserCanRaiseVolumeAfterClipping) { … }
TEST_P(InputVolumeControllerParametrizedTest,
ClippingDoesNotPullLowVolumeBackUp) { … }
TEST_P(InputVolumeControllerParametrizedTest, TakesNoActionOnZeroMicVolume) { … }
TEST_P(InputVolumeControllerParametrizedTest, ClippingDetectionLowersVolume) { … }
TEST_P(InputVolumeControllerParametrizedTest, ClippingParametersVerified) { … }
TEST_P(InputVolumeControllerParametrizedTest,
DisableClippingPredictorDisablesClippingPredictor) { … }
TEST_P(InputVolumeControllerParametrizedTest,
EnableClippingPredictorEnablesClippingPredictor) { … }
TEST_P(InputVolumeControllerParametrizedTest,
DisableClippingPredictorDoesNotLowerVolume) { … }
TEST_P(InputVolumeControllerParametrizedTest,
UsedClippingPredictionsProduceLowerAnalogLevels) { … }
TEST_P(InputVolumeControllerParametrizedTest, EmptyRmsErrorHasNoEffect) { … }
TEST(InputVolumeControllerTest, UpdateInputVolumeWaitFramesIsEffective) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST(InputVolumeControllerTest,
MinInputVolumeEnforcedWithClippingWhenAboveClippedLevelMin) { … }
TEST(InputVolumeControllerTest,
ClippedlevelMinEnforcedWithClippingWhenAboveMinInputVolume) { … }
TEST(InputVolumeControllerTest, SpeechRatioThresholdIsEffective) { … }
TEST(InputVolumeControllerTest, SpeechProbabilityThresholdIsEffective) { … }
TEST(InputVolumeControllerTest,
DoNotLogRecommendedInputVolumeOnChangeToMatchTarget) { … }
TEST(InputVolumeControllerTest,
LogRecommendedInputVolumeOnUpwardChangeToMatchTarget) { … }
TEST(InputVolumeControllerTest,
LogRecommendedInputVolumeOnDownwardChangeToMatchTarget) { … }
TEST(MonoInputVolumeControllerTest, CheckHandleClippingLowersVolume) { … }
TEST(MonoInputVolumeControllerTest,
CheckProcessNegativeRmsErrorDecreasesInputVolume) { … }
TEST(MonoInputVolumeControllerTest,
CheckProcessPositiveRmsErrorIncreasesInputVolume) { … }
TEST(MonoInputVolumeControllerTest,
CheckProcessNegativeRmsErrorDecreasesInputVolumeWithLimit) { … }
TEST(MonoInputVolumeControllerTest,
CheckProcessPositiveRmsErrorIncreasesInputVolumeWithLimit) { … }
TEST(MonoInputVolumeControllerTest,
CheckProcessRmsErrorDecreasesInputVolumeRepeatedly) { … }
TEST(MonoInputVolumeControllerTest,
CheckProcessPositiveRmsErrorIncreasesInputVolumeRepeatedly) { … }
TEST(MonoInputVolumeControllerTest, CheckClippedLevelMinIsEffective) { … }
TEST(MonoInputVolumeControllerTest, CheckMinMicLevelIsEffective) { … }
TEST(MonoInputVolumeControllerTest,
CheckUpdateInputVolumeWaitFramesIsEffective) { … }
TEST(MonoInputVolumeControllerTest,
CheckSpeechProbabilityThresholdIsEffective) { … }
TEST(MonoInputVolumeControllerTest, CheckSpeechRatioThresholdIsEffective) { … }
TEST(MonoInputVolumeControllerTest,
CheckProcessEmptyRmsErrorDoesNotLowerVolume) { … }
}