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..1db4d97962cbf494420040c688b7f55a85e029d5 |
--- /dev/null |
+++ b/webrtc/modules/audio_processing/test/fake_recording_device.h |
@@ -0,0 +1,96 @@ |
+/* |
+ * 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 <memory> |
+#include <vector> |
+ |
+#include "webrtc/base/array_view.h" |
+#include "webrtc/base/checks.h" |
+#include "webrtc/common_audio/channel_buffer.h" |
+#include "webrtc/modules/include/module_common_types.h" |
+ |
+namespace webrtc { |
+namespace test { |
+ |
+// Abstract class for simulating a microphone with analog gain. |
+// |
+// The intended mode of operation is the following: |
+// |
+// auto fake_mic = FakeRecordingDeviceLinear(255); |
+// |
+// fake_mic.set_mic_level(170); |
+// fake_mic.set_mic_level(rtc::Optional<int>()); |
+// fake_mic.SimulateAnalogGain(buffer); |
+// |
+// Simulate the microphone level 170. |
+// |
+// fake_mic.set_mic_level(170); |
+// fake_mic.set_mic_level(rtc::Optional<int>(30)); |
+// fake_mic.SimulateAnalogGain(buffer); |
+// |
+// Virtually restore the unmodified microphone level knowing that the data in |
+// buffer has recorded from a microphone having 30 as level. |
+// Then, calling SimulateAnalogGain() will first "undo" the gain applied by the |
+// real microphone. |
+class FakeRecordingDevice { |
peah-webrtc
2017/05/23 22:13:20
I really think we should put as little implementat
AleBzk
2017/06/22 10:16:00
Done.
|
+ public: |
+ enum class DeviceKind { IDENTITY, LINEAR }; |
+ |
+ explicit FakeRecordingDevice(int initial_mic_level); |
+ virtual ~FakeRecordingDevice() = 0; |
+ |
+ // FakeRecordingDevice factory. |
+ static std::unique_ptr<FakeRecordingDevice> GetFakeRecDevice( |
+ DeviceKind kind, int initial_mic_level); |
+ |
+ // Setter and getter for the mic level to simulate. |
+ void set_mic_level(int level); |
+ int mic_level() const; |
+ |
+ // Setter and getter for the mic level to undo. |
+ void set_undo_mic_level(rtc::Optional<int> level); |
+ rtc::Optional<int> undo_mic_level() const; |
+ |
+ // Simulates the analog gain. |
+ // 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 |
+ // an empty value. |
+ void SimulateAnalogGain(ChannelBuffer<float>* buffer); |
+ |
+ // Simulates the analog gain. |
+ // 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 |
+ // an empty value. |
+ void SimulateAnalogGain(AudioFrame* buffer); |
+ |
+ protected: |
+ // Abstract methods required by SimulateAnalogGain(). |
+ virtual void ModifySampleInt16(int16_t* sample) = 0; |
+ virtual void ModifySampleFloat(float* sample) = 0; |
+ |
+ int16_t ClipSampleInt16(int16_t sample); |
+ float ClipSampleFloat(float sample); |
+ |
+ private: |
+ // Mic level to simulate. |
+ int mic_level_; |
+ |
+ // Optional undo mic level. |
+ rtc::Optional<int> undo_mic_level_; |
+}; |
+ |
+} // namespace test |
+} // namespace webrtc |
+ |
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ |