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

Side by Side 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: Removed polymorphism, added linear gain curve, enum for mapping type. 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 unified diff | Download patch
OLDNEW
(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 {
27 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.
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 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
36 switch (mapping_kind_) {
37 case LevelToScalingMappingKind::kIdentity: {
38 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.
39 }
40 case LevelToScalingMappingKind::kLinear: {
41 return level_ <= 255 && 0 <= level_;
AleBzk 2017/04/24 14:54:30 Same here
aleloi 2017/04/25 08:23:58 Done.
42 RTC_DCHECK_LE(0, level_);
43 }
44 }
45 }
46
47 // As the analog level limits in webrtc::GainControl, |level| must
48 // be within [0, 65535].
49 void set_analog_level(int level) {
50 RTC_DCHECK(AnalogLevelIsValid(level));
51 level_ = level;
52 }
53
54 int analog_level() const { return level_; }
55
56 float GetScalingFactor() const {
57 switch (mapping_kind_) {
58 case LevelToScalingMappingKind::kIdentity: {
59 return 1.0f;
60 }
61 case LevelToScalingMappingKind::kLinear: {
62 return static_cast<float>(level_) / 255.0f;
63 }
64 }
65 }
66
67 private:
68 int level_ = 0;
69 const LevelToScalingMappingKind mapping_kind_;
70 };
71 } // namespace webrtc
72
73 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_ANALOG_VOLUME_MAPPER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698