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_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/callback.h" | |
| 19 #include "webrtc/base/checks.h" | |
| 20 #include "webrtc/common_audio/channel_buffer.h" | |
| 21 #include "webrtc/modules/include/module_common_types.h" | |
| 22 | |
| 23 namespace webrtc { | |
| 24 | |
|
peah-webrtc
2017/05/16 12:19:36
I think it would make sense to use the test namesp
AleBzk
2017/05/17 11:52:23
Done.
| |
| 25 typedef rtc::Callback3<int16_t, int16_t, int, rtc::Optional<int>> | |
| 26 SimulatorCallbackInt16; | |
| 27 typedef rtc::Callback3<float, float, int, rtc::Optional<int>> | |
| 28 SimulatorCallbackFloat; | |
| 29 | |
| 30 const int16_t kSampleMinInt16 = 255; | |
|
peah-webrtc
2017/05/16 12:19:36
These constants are not used in the header file. P
AleBzk
2017/05/17 11:52:24
Done.
| |
| 31 const int16_t kSampleMaxInt16 = -255; | |
| 32 const float kSampleMinFloat = -1.0f; | |
| 33 const float kSampleMaxFloat = 1.0f; | |
| 34 | |
| 35 // Class for simulating a microphone with analog gain. | |
| 36 // | |
| 37 // The intended mode of operation is the following: | |
| 38 // | |
| 39 // auto fake_mic = FakeRecordingDevice( | |
| 40 // FakeRecordingDevice::MicrophoneKind::kLinear); | |
| 41 // fake_mic.SimulateAnalogGain(target_level, real_device_level, buffer); | |
| 42 // | |
| 43 // The last call optionally "undoes" the gain applied by the real microphone. | |
| 44 // For instance, when an AEC dump includes the applied mic gain, this value can | |
| 45 // be used to virtually restore the microphone signal with unmodified level. | |
| 46 class FakeRecordingDevice final { | |
| 47 public: | |
| 48 enum class MicrophoneKind { | |
| 49 kIdentity, | |
| 50 kLinear, | |
| 51 }; | |
| 52 | |
| 53 explicit FakeRecordingDevice(MicrophoneKind mapping_kind); | |
| 54 | |
| 55 ~FakeRecordingDevice(); | |
| 56 | |
| 57 // Simulates the analog gain on an std::vector<rtc::ArrayView<float>> buffer. | |
|
peah-webrtc
2017/05/16 12:19:36
The buffer type is stated in the method header:
AleBzk
2017/05/17 11:52:23
I would leave it as it is to distinguish the 3 met
peah-webrtc
2017/05/17 14:52:12
Lets discuss the three methods first. In general,
| |
| 58 // If |real_device_level| is a valid level, the unmodified mic signal is | |
| 59 // virtually restored. To skip the latter step set |real_device_level| to | |
| 60 // nullptr. | |
|
peah-webrtc
2017/05/16 12:19:36
real_device_level is not a pointer but an optional
AleBzk
2017/05/17 11:52:23
Comment changed.
| |
| 61 void SimulateAnalogGain(int level, rtc::Optional<int> real_device_level, | |
| 62 std::vector<rtc::ArrayView<float>> buffer); | |
|
peah-webrtc
2017/05/16 12:19:36
Why do you need 3 methods for SimulateAnalogGain?
AleBzk
2017/05/17 11:52:24
I left SimulateAnalogGain(int, rtc::Optional<int>,
peah-webrtc
2017/05/17 14:52:12
I think it always makes sense to keep the API surf
| |
| 63 | |
| 64 // Simulates the analog gain on a ChannelBuffer<float> buffer. | |
| 65 // For further details, see the comment above. | |
| 66 void SimulateAnalogGain(int level, rtc::Optional<int> real_device_level, | |
| 67 ChannelBuffer<float>* buffer); | |
| 68 | |
| 69 // Simulates the analog gain on an AudioFrame buffer (fixed point). | |
| 70 // For further details, see the comment above. | |
| 71 void SimulateAnalogGain(int level, rtc::Optional<int> real_device_level, | |
| 72 AudioFrame* buffer); | |
| 73 | |
| 74 private: | |
| 75 // Identity simulator: the samples are not changed. | |
| 76 SimulatorCallbackInt16 AnalogGainSimulatorIdentityInt16(); | |
| 77 SimulatorCallbackFloat AnalogGainSimulatorIdentityFloat(); | |
| 78 | |
| 79 // Linear simulator with hard-clipping. | |
| 80 SimulatorCallbackInt16 AnalogGainSimulatorLinearInt16(); | |
| 81 SimulatorCallbackFloat AnalogGainSimulatorLinearFloat(); | |
| 82 | |
| 83 int16_t ClipSample(int16_t sample); | |
| 84 float ClipSample(float sample); | |
| 85 | |
| 86 const MicrophoneKind mapping_kind_; | |
| 87 SimulatorCallbackInt16 simulator_callback_int16_; | |
| 88 SimulatorCallbackFloat simulator_callback_float_; | |
| 89 }; | |
| 90 | |
| 91 } // namespace webrtc | |
| 92 | |
| 93 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ | |
| OLD | NEW |