Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(228)

Unified Diff: webrtc/modules/audio_processing/test/analog_volume_mapper.h

Issue 2837553002: First try on a fake analog volume control interface for use in audioproc_f. (Closed)
Patch Set: Comments addressed: smaller range, simpler checks, working test. Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..40cf8b6edcf622722c215c43e6f4ddb73aad6120
--- /dev/null
+++ b/webrtc/modules/audio_processing/test/analog_volume_mapper.h
@@ -0,0 +1,61 @@
+/*
+ * 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 {
peah-webrtc 2017/04/26 07:20:03 I really think it would be easier to see how to be
+ kIdentity, // Any level produces a constant scaling factor of 1.0f.
+ 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) {}
+
+ // |level| must be within [0, 255].
+ void set_analog_level(int level) {
+ RTC_DCHECK_LE(0, level);
+ RTC_DCHECK_LE(level, 255);
+ 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_
« no previous file with comments | « webrtc/modules/audio_processing/BUILD.gn ('k') | webrtc/modules/audio_processing/test/analog_volume_mapper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698