Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(790)

Unified Diff: webrtc/modules/audio_processing/test/fake_recording_device.h

Issue 2834643002: audioproc_f with simulated mic analog gain (Closed)
Patch Set: fake rec device boilerplate reduced, aec dump simulated analog gain logic moved Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..f6da3d51c16064664b9a35ba1b1787636f004822
--- /dev/null
+++ b/webrtc/modules/audio_processing/test/fake_recording_device.h
@@ -0,0 +1,90 @@
+/*
+ * 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/base/optional.h"
+#include "webrtc/common_audio/channel_buffer.h"
+#include "webrtc/modules/include/module_common_types.h"
+
+namespace webrtc {
+namespace test {
+
+class FakeRecordingDeviceWorker;
AleBzk 2017/06/22 10:16:01 Forward declaration for the FakeRecordingDeviceWor
+
+// Abstract class for simulating a microphone with analog gain.
peah-webrtc 2017/06/29 05:45:27 This is not an abstract class, right? Or did I get
AleBzk 2017/06/29 11:43:36 Sorry, this comment applies to the previous PS, I
+//
+// The intended modes of operation are the following:
+//
+// auto fake_mic = FakeRecordingDevice(
+// 255, FakeRecordingDevice.DeviceKind.LINEAR);
AleBzk 2017/06/22 10:16:01 I fixed this as follows: // FakeRecordingDevice f
+//
+// fake_mic.set_mic_level(170);
+// fake_mic.set_undo_mic_level(rtc::Optional<int>());
+// fake_mic.SimulateAnalogGain(buffer);
+//
+// When the mic level to undo is known:
+//
+// fake_mic.set_mic_level(170);
+// fake_mic.set_undo_mic_level(rtc::Optional<int>(30));
+// fake_mic.SimulateAnalogGain(buffer);
+//
+// The second option virtually restores the unmodified microphone level. Calling
+// SimulateAnalogGain() will first "undo" the gain applied by the real
+// microphone (e.g., 30).
+class FakeRecordingDevice final {
+ public:
+ enum class DeviceKind { IDENTITY, LINEAR };
+
+ FakeRecordingDevice(int initial_mic_level, DeviceKind kind);
+ ~FakeRecordingDevice();
+
+ // Setter and getter for the mic level to simulate.
+ void set_mic_level(int level) { mic_level_ = level; }
+ int mic_level() const { return mic_level_; }
+
+ // Setter and getter for the mic level to undo.
+ void set_undo_mic_level(rtc::Optional<int> level) { undo_mic_level_ = level; }
+ rtc::Optional<int> undo_mic_level() const { return undo_mic_level_; }
+
+ // 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);
+
+ private:
+ // Mic level to simulate.
+ int mic_level_;
+
+ // Fake recording device worker.
+ std::unique_ptr<FakeRecordingDeviceWorker> worker_;
+
+ // Optional undo mic level.
+ rtc::Optional<int> undo_mic_level_;
+};
+
+} // namespace test
+} // namespace webrtc
+
+#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_

Powered by Google App Engine
This is Rietveld 408576698