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_FAKE_RECORDING_DEVICE_H_ | |
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ | |
13 | |
14 #include <algorithm> | |
15 #include <vector> | |
16 | |
17 #include "webrtc/base/array_view.h" | |
18 #include "webrtc/base/checks.h" | |
19 #include "webrtc/base/optional.h" | |
20 #include "webrtc/modules/include/module_common_types.h" | |
21 | |
22 namespace webrtc { | |
23 | |
24 // Class for simulating an analog gain controller controlled by | |
peah-webrtc
2017/05/05 06:28:41
I don't think this comment is correct. The class i
AleBzk
2017/05/05 12:20:18
Done.
| |
25 // webrtc::GainControl. The class wraps a mapping from the current | |
26 // level to a floating point scaling factor with the goal of | |
27 // abstracting non-linearities in the gain curve of real analog | |
28 // microphones. The intended mode of operation is | |
29 // | |
30 // set_analog_level(|level suggested by GainControl|); | |
peah-webrtc
2017/05/05 06:28:41
This does not really reflect the way it is current
AleBzk
2017/05/05 12:20:18
Right. I'll make it more generic.
| |
31 // NotifyAudioDeviceLevel(|recorded level of real microphone|); // Optional! | |
32 // ProcessStream(src, dest) | |
33 // | |
34 // In these three calls, the fake device optionally undoes the gain | |
35 // applied by the real microphone. Then in applies a new gain | |
36 // suggested by the AGC. | |
37 class FakeRecordingDevice { | |
38 public: | |
39 enum class LevelToScalingMappingKind { | |
40 kIdentity, // Always producing 1.0f. | |
41 kLinear // A level within [0, 255] is linearly scaled. 0 produces | |
42 // 0.f, and 255 is 1.0f. | |
aleloi
2017/05/04 12:47:13
Nit: please indent comments
AleBzk
2017/05/05 12:20:18
Done.
| |
43 }; | |
44 | |
45 explicit FakeRecordingDevice(LevelToScalingMappingKind mapping_kind); | |
46 | |
47 ~FakeRecordingDevice(); | |
48 | |
49 // Setters/getters for |level_|. The parameter |level| must be | |
50 // within [0, 255]. | |
51 void set_analog_level(int level); | |
52 int analog_level() const; | |
53 | |
54 LevelToScalingMappingKind mapping_kind() const; | |
aleloi
2017/05/04 12:47:13
Is mapping_kind() used anywhere?
AleBzk
2017/05/05 12:20:18
Nope. Removed.
I had added it when I made the kind
| |
55 | |
56 void ProcessStream(std::vector<rtc::ArrayView<const float>> src, | |
aleloi
2017/05/04 12:47:14
Perhaps add a comment along the lines of 'undoes t
peah-webrtc
2017/05/05 06:28:41
Would it be possible to change ProcessStream to so
AleBzk
2017/05/05 12:20:18
Right. I went for SimulateAnalogGain()
| |
57 std::vector<rtc::ArrayView<float>> dest); | |
58 | |
59 void ProcessStream(const AudioFrame* src, AudioFrame* dest); | |
peah-webrtc
2017/05/05 06:28:41
I think the usage of this class is more complicate
AleBzk
2017/05/05 12:20:18
Thanks for this comment. I think the change you pr
| |
60 | |
61 // Meant to be called before ProcessStream if the source signal | |
62 // passed to ProcessStream has been recorded from a microphone with | |
63 // known gain. | |
64 void NotifyAudioDeviceLevel(int level); | |
65 | |
66 private: | |
67 // Computes scaling factor based on both the recorded real device | |
68 // level, gain curve (which depends on |mapping_kind_) and the | |
aleloi
2017/05/04 12:47:13
Nit: formatting, |mapping_kind_|)
AleBzk
2017/05/05 12:20:18
Done.
| |
69 // current level. | |
70 float ComputeCompoundScalingFactor(); | |
71 | |
72 // Compute scaling factor based on current gain curve, which depends | |
73 // on |mapping_kind_|. | |
74 float GetScalingFactor(int level) const; | |
75 | |
76 int level_ = 0; | |
77 rtc::Optional<int> real_device_level_; | |
78 const LevelToScalingMappingKind mapping_kind_; | |
79 }; | |
80 | |
81 } // namespace webrtc | |
82 | |
83 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ | |
OLD | NEW |