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

Unified Diff: webrtc/modules/audio_processing/test/fake_rec_device_linear.cc

Issue 2834643002: audioproc_f with simulated mic analog gain (Closed)
Patch Set: FakeRecordingDevice refactoring, minor comments addressed Created 3 years, 7 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_rec_device_linear.cc
diff --git a/webrtc/modules/audio_processing/test/fake_rec_device_linear.cc b/webrtc/modules/audio_processing/test/fake_rec_device_linear.cc
new file mode 100644
index 0000000000000000000000000000000000000000..8cc649fb2fd3ad26521a340302f6b3f418bc4099
--- /dev/null
+++ b/webrtc/modules/audio_processing/test/fake_rec_device_linear.cc
@@ -0,0 +1,60 @@
+/*
+ * 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.
+ */
+
+#include "webrtc/modules/audio_processing/test/fake_rec_device_linear.h"
+
+#include "webrtc/base/logging.h"
+
+namespace webrtc {
+namespace test {
+
+FakeRecordingDeviceLinear::FakeRecordingDeviceLinear(int initial_mic_level)
+ : FakeRecordingDevice(initial_mic_level) {}
+
+FakeRecordingDeviceLinear::~FakeRecordingDeviceLinear() = default;
+
+void FakeRecordingDeviceLinear::ModifySampleInt16(int16_t* sample) {
+ float sample_f = static_cast<float>(*sample);
+ rtc::Optional<int> undo_level = undo_mic_level();
+
+ // Virtually restore the unmodified microphone level.
+ if (undo_level) {
+ if (*undo_level == 0) {
+ LOG(LS_INFO) << "undo level is zero, cannot undo mic level";
+ } else {
+ sample_f = ClipSampleInt16(
+ sample_f * 255.0f / static_cast<float>(*undo_level));
+ }
+ }
AleBzk 2017/05/17 11:52:24 Let's continue the discussion about clipping betwe
+
+ // Simulate the mic gain.
+ *sample = ClipSampleInt16(
+ sample_f * static_cast<float>(mic_level()) / 255.0f);
+}
+
+void FakeRecordingDeviceLinear::ModifySampleFloat(float* sample) {
+ rtc::Optional<int> undo_level = undo_mic_level();
+
+ // Virtually restore the unmodified microphone level.
+ if (undo_level) {
+ if (*undo_level == 0) {
+ LOG(LS_INFO) << "undo level is zero, cannot undo mic level";
+ } else {
+ *sample = ClipSampleFloat(
+ *sample * 255.0f / static_cast<float>(*undo_level));
+ }
+ }
+
+ // Simulate the mic gain.
+ *sample = ClipSampleFloat(*sample * static_cast<float>(mic_level()) / 255.0f);
+}
+
+} // namespace test
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698