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/modules/include/module_common_types.h" | |
20 | |
21 namespace webrtc { | |
22 | |
23 // Class for simulating a microphone with analog gain. The class wraps a mapping | |
peah-webrtc
2017/05/05 20:25:21
This seems out of date, could you please update.
AleBzk
2017/05/16 08:53:03
Done.
| |
24 // from the current level to a floating point scaling factor. | |
25 // | |
26 // The intended mode of operation is the following: | |
27 // | |
28 // set_analog_level(|mic gain level|); | |
29 // NotifyAudioDeviceLevel(|recorded level of real microphone|); // Optional! | |
peah-webrtc
2017/05/05 20:25:21
NotifyAudioDeviceLevel Is no longer present, right
AleBzk
2017/05/16 08:53:03
Done.
| |
30 // SimulateAnalogGain(src, dest); | |
31 // | |
32 // In these three calls, the fake device optionally undoes the gain | |
33 // applied by the real microphone, and then applies a new mic gain level. | |
34 class FakeRecordingDevice final { | |
35 public: | |
36 static const int kRealDeviceLevelUnknown = -1; | |
37 | |
38 enum class LevelToScalingMappingKind { | |
peah-webrtc
2017/05/05 20:25:21
I think the mapping name is too specific. What if
aleloi
2017/05/08 10:15:23
+1
AleBzk
2017/05/16 08:53:03
Done.
| |
39 kIdentity, // Always producing 1.0f. | |
40 kLinear // A level within [0, 255] is linearly scaled. 0 produces | |
41 // 0.f, and 255 is 1.0f. | |
42 }; | |
43 | |
44 explicit FakeRecordingDevice(LevelToScalingMappingKind mapping_kind); | |
45 | |
46 ~FakeRecordingDevice(); | |
47 | |
48 // Simulates the analog gain on a std::vector<rtc::ArrayView<>> buffer. | |
49 // If |real_device_level| is a valid level, the unmodified mic signal is | |
50 // virtually restored. To skip the latter step set |real_device_level| to | |
51 // FakeRecordingDevice::kRealDeviceLevelUnknown. | |
52 void SimulateAnalogGain(std::vector<rtc::ArrayView<const float>> src, | |
peah-webrtc
2017/05/05 20:25:21
Seeing how this is used, I don't see why there nee
aleloi
2017/05/08 10:15:23
+1
AleBzk
2017/05/16 08:53:04
Done.
| |
53 std::vector<rtc::ArrayView<float>> dest, | |
peah-webrtc
2017/05/05 20:25:21
The style guide says that input-only parameters sh
AleBzk
2017/05/16 08:53:03
Done.
| |
54 int level, | |
55 int real_device_level = kRealDeviceLevelUnknown); | |
peah-webrtc
2017/05/05 20:25:21
As real_device_level is actually always used whene
AleBzk
2017/05/16 08:53:03
Done.
| |
56 | |
57 // Simulates the analog gain on an AudioFrame buffer. | |
58 // For further details, see the comment above. | |
59 void SimulateAnalogGain(const AudioFrame* src, | |
60 AudioFrame* dest, | |
61 int level, | |
62 int real_device_level = kRealDeviceLevelUnknown); | |
aleloi
2017/05/08 10:15:23
Note that the comment about ordering and default p
AleBzk
2017/05/16 08:53:04
Done.
| |
63 | |
64 private: | |
65 // Computes the PCM samples scaling factor based on the following: | |
66 // - gain curve (which depends on |mapping_kind_|), | |
peah-webrtc
2017/05/05 20:25:21
The style guide says "Declaration comments describ
AleBzk
2017/05/16 08:53:04
Done.
| |
67 // - the desired mic level |level|, | |
68 // - the real device mic level |real_device_level| (optional). | |
69 float ComputeCompoundScalingFactor(int level, int real_device_level) const; | |
70 | |
71 // Compute scaling factor based on current gain curve, which depends | |
72 // on |mapping_kind_|. | |
73 float GetScalingFactor(int level) const; | |
74 | |
75 const LevelToScalingMappingKind mapping_kind_; | |
76 }; | |
77 | |
78 } // namespace webrtc | |
79 | |
80 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ | |
OLD | NEW |