Chromium Code Reviews| Index: webrtc/modules/audio_processing/test/analog_volume_mapper.h |
| diff --git a/webrtc/modules/audio_processing/test/analog_volume_mapper.h b/webrtc/modules/audio_processing/test/analog_volume_mapper.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7a690f67aeac6b3c121902a150c00282fbe692e2 |
| --- /dev/null |
| +++ b/webrtc/modules/audio_processing/test/analog_volume_mapper.h |
| @@ -0,0 +1,73 @@ |
| +/* |
| + * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| + * |
| + * Use of this source code is governed by a BSD-style license |
| + * that can be found in the LICENSE file in the root of the source |
| + * tree. An additional intellectual property rights grant can be found |
| + * in the file PATENTS. All contributing project authors may |
| + * be found in the AUTHORS file in the root of the source tree. |
| + */ |
| + |
| +#ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_ANALOG_VOLUME_MAPPER_H_ |
| +#define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_ANALOG_VOLUME_MAPPER_H_ |
| + |
| +#include "webrtc/base/checks.h" |
| + |
| +namespace webrtc { |
| + |
| +// Class for simulating an analog gain controller controlled by |
| +// webrtc::GainControl. The class wraps a mapping from the current |
| +// level to a floating point scaling factor abstracting |
| +// non-linearities in the gain curve of real analog microphones. The |
| +// intended mode of operation is to use get_scaling_factor() to apply |
| +// a gain factor to a signal. |
| +class AnalogLevelMapper { |
| + public: |
| + enum class LevelToScalingMappingKind { |
| + kIdentity, // Any level produces a |
|
AleBzk
2017/04/24 14:54:30
The comment looks incomplete.
aleloi
2017/04/25 08:23:58
Thanks, done.
|
| + kLinear // A level within [0, 255] is linearly scaled. 0 produces |
| + // 0.f, and 255 is 1.0f. |
| + }; |
| + |
| + explicit AnalogLevelMapper(LevelToScalingMappingKind mapping_kind) |
| + : mapping_kind_(mapping_kind) {} |
| + |
| + bool AnalogLevelIsValid(int level) { |
|
AleBzk
2017/04/24 14:54:30
From this method, I understand that different mapp
aleloi
2017/04/25 08:23:58
I couldn't find a range outside 0, 255 except in t
|
| + switch (mapping_kind_) { |
| + case LevelToScalingMappingKind::kIdentity: { |
| + return level_ <= 65535 && 0 <= level_; |
|
AleBzk
2017/04/24 14:54:30
You probably want to check level and not level_.
aleloi
2017/04/25 08:23:58
Oh, good catch! Done.
|
| + } |
| + case LevelToScalingMappingKind::kLinear: { |
| + return level_ <= 255 && 0 <= level_; |
|
AleBzk
2017/04/24 14:54:30
Same here
aleloi
2017/04/25 08:23:58
Done.
|
| + RTC_DCHECK_LE(0, level_); |
| + } |
| + } |
| + } |
| + |
| + // As the analog level limits in webrtc::GainControl, |level| must |
| + // be within [0, 65535]. |
| + void set_analog_level(int level) { |
| + RTC_DCHECK(AnalogLevelIsValid(level)); |
| + level_ = level; |
| + } |
| + |
| + int analog_level() const { return level_; } |
| + |
| + float GetScalingFactor() const { |
| + switch (mapping_kind_) { |
| + case LevelToScalingMappingKind::kIdentity: { |
| + return 1.0f; |
| + } |
| + case LevelToScalingMappingKind::kLinear: { |
| + return static_cast<float>(level_) / 255.0f; |
| + } |
| + } |
| + } |
| + |
| + private: |
| + int level_ = 0; |
| + const LevelToScalingMappingKind mapping_kind_; |
| +}; |
| +} // namespace webrtc |
| + |
| +#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_ANALOG_VOLUME_MAPPER_H_ |