Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 /* | |
| 2 * Copyright (c) 2017 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 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_ANALOG_VOLUME_MAPPER_H_ | |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_ANALOG_VOLUME_MAPPER_H_ | |
| 13 | |
| 14 #include "webrtc/base/checks.h" | |
| 15 | |
| 16 namespace webrtc { | |
| 17 | |
| 18 // Class for simulating an analog gain controller controlled by | |
| 19 // webrtc::GainControl. The class wraps a mapping from the current | |
| 20 // level to a floating point scaling factor abstracting | |
| 21 // non-linearities in the gain curve of real analog microphones. The | |
| 22 // intended mode of operation is to use get_scaling_factor() to apply | |
| 23 // a gain factor to a signal. | |
| 24 class AnalogLevelMapper { | |
| 25 public: | |
| 26 enum class LevelToScalingMappingKind { | |
|
peah-webrtc
2017/04/26 07:20:03
I really think it would be easier to see how to be
| |
| 27 kIdentity, // Any level produces a constant scaling factor of 1.0f. | |
| 28 kLinear // A level within [0, 255] is linearly scaled. 0 produces | |
| 29 // 0.f, and 255 is 1.0f. | |
| 30 }; | |
| 31 | |
| 32 explicit AnalogLevelMapper(LevelToScalingMappingKind mapping_kind) | |
| 33 : mapping_kind_(mapping_kind) {} | |
| 34 | |
| 35 // |level| must be within [0, 255]. | |
| 36 void set_analog_level(int level) { | |
| 37 RTC_DCHECK_LE(0, level); | |
| 38 RTC_DCHECK_LE(level, 255); | |
| 39 level_ = level; | |
| 40 } | |
| 41 | |
| 42 int analog_level() const { return level_; } | |
| 43 | |
| 44 float GetScalingFactor() const { | |
| 45 switch (mapping_kind_) { | |
| 46 case LevelToScalingMappingKind::kIdentity: { | |
| 47 return 1.0f; | |
| 48 } | |
| 49 case LevelToScalingMappingKind::kLinear: { | |
| 50 return static_cast<float>(level_) / 255.0f; | |
| 51 } | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 private: | |
| 56 int level_ = 0; | |
| 57 const LevelToScalingMappingKind mapping_kind_; | |
| 58 }; | |
| 59 } // namespace webrtc | |
| 60 | |
| 61 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_ANALOG_VOLUME_MAPPER_H_ | |
| OLD | NEW |