Index: webrtc/modules/audio_processing/test/fake_recording_device.h |
diff --git a/webrtc/modules/audio_processing/test/fake_recording_device.h b/webrtc/modules/audio_processing/test/fake_recording_device.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..5ee74a0cf3e1f7a30ae2822189b4d139224a0966 |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/test/fake_recording_device.h |
@@ -0,0 +1,93 @@ |
+/* |
+ * 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_FAKE_RECORDING_DEVICE_H_ |
+#define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ |
+ |
+#include <algorithm> |
+#include <vector> |
+ |
+#include "webrtc/base/array_view.h" |
+#include "webrtc/base/callback.h" |
+#include "webrtc/base/checks.h" |
+#include "webrtc/common_audio/channel_buffer.h" |
+#include "webrtc/modules/include/module_common_types.h" |
+ |
+namespace webrtc { |
+ |
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.
|
+typedef rtc::Callback3<int16_t, int16_t, int, rtc::Optional<int>> |
+ SimulatorCallbackInt16; |
+typedef rtc::Callback3<float, float, int, rtc::Optional<int>> |
+ SimulatorCallbackFloat; |
+ |
+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.
|
+const int16_t kSampleMaxInt16 = -255; |
+const float kSampleMinFloat = -1.0f; |
+const float kSampleMaxFloat = 1.0f; |
+ |
+// Class for simulating a microphone with analog gain. |
+// |
+// The intended mode of operation is the following: |
+// |
+// auto fake_mic = FakeRecordingDevice( |
+// FakeRecordingDevice::MicrophoneKind::kLinear); |
+// fake_mic.SimulateAnalogGain(target_level, real_device_level, buffer); |
+// |
+// The last call optionally "undoes" the gain applied by the real microphone. |
+// For instance, when an AEC dump includes the applied mic gain, this value can |
+// be used to virtually restore the microphone signal with unmodified level. |
+class FakeRecordingDevice final { |
+ public: |
+ enum class MicrophoneKind { |
+ kIdentity, |
+ kLinear, |
+ }; |
+ |
+ explicit FakeRecordingDevice(MicrophoneKind mapping_kind); |
+ |
+ ~FakeRecordingDevice(); |
+ |
+ // 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,
|
+ // If |real_device_level| is a valid level, the unmodified mic signal is |
+ // virtually restored. To skip the latter step set |real_device_level| to |
+ // 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.
|
+ void SimulateAnalogGain(int level, rtc::Optional<int> real_device_level, |
+ 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
|
+ |
+ // Simulates the analog gain on a ChannelBuffer<float> buffer. |
+ // For further details, see the comment above. |
+ void SimulateAnalogGain(int level, rtc::Optional<int> real_device_level, |
+ ChannelBuffer<float>* buffer); |
+ |
+ // Simulates the analog gain on an AudioFrame buffer (fixed point). |
+ // For further details, see the comment above. |
+ void SimulateAnalogGain(int level, rtc::Optional<int> real_device_level, |
+ AudioFrame* buffer); |
+ |
+ private: |
+ // Identity simulator: the samples are not changed. |
+ SimulatorCallbackInt16 AnalogGainSimulatorIdentityInt16(); |
+ SimulatorCallbackFloat AnalogGainSimulatorIdentityFloat(); |
+ |
+ // Linear simulator with hard-clipping. |
+ SimulatorCallbackInt16 AnalogGainSimulatorLinearInt16(); |
+ SimulatorCallbackFloat AnalogGainSimulatorLinearFloat(); |
+ |
+ int16_t ClipSample(int16_t sample); |
+ float ClipSample(float sample); |
+ |
+ const MicrophoneKind mapping_kind_; |
+ SimulatorCallbackInt16 simulator_callback_int16_; |
+ SimulatorCallbackFloat simulator_callback_float_; |
+}; |
+ |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ |