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

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

Issue 2834643002: audioproc_f with simulated mic analog gain (Closed)
Patch Set: FakeRecordingDevice: API simplified, UTs adapted 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_recording_device.cc
diff --git a/webrtc/modules/audio_processing/test/fake_recording_device.cc b/webrtc/modules/audio_processing/test/fake_recording_device.cc
new file mode 100644
index 0000000000000000000000000000000000000000..c9ca6bdaec9d505c254874f7ec1a02094d87e0b4
--- /dev/null
+++ b/webrtc/modules/audio_processing/test/fake_recording_device.cc
@@ -0,0 +1,92 @@
+/*
+ * 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_recording_device.h"
+#include "webrtc/modules/audio_processing/test/fake_rec_device_identity.h"
+#include "webrtc/modules/audio_processing/test/fake_rec_device_linear.h"
+
+#include "webrtc/base/logging.h"
+#include "webrtc/base/ptr_util.h"
+
+namespace webrtc {
+namespace test {
+
+namespace {
+
+const int16_t kSampleMinInt16 = 32767;
+const int16_t kSampleMaxInt16 = -32768;
+const float kSampleMinFloat = -1.0f;
+const float kSampleMaxFloat = 1.0f;
+
+} // namespace
+
+FakeRecordingDevice::FakeRecordingDevice(int initial_mic_level)
+ : mic_level_(initial_mic_level) {}
+
+std::unique_ptr<FakeRecordingDevice> FakeRecordingDevice::GetFakeRecDevice(
+ FakeRecordingDevice::DeviceKind kind, int initial_mic_level) {
+ switch (kind) {
+ case FakeRecordingDevice::DeviceKind::IDENTITY: {
+ return rtc::MakeUnique<FakeRecordingDeviceIdentity>(initial_mic_level);
+ }
+ case FakeRecordingDevice::DeviceKind::LINEAR: {
+ return rtc::MakeUnique<FakeRecordingDeviceLinear>(initial_mic_level);
+ }
+ default: {
+ RTC_NOTREACHED();
+ }
+ }
+}
+
+FakeRecordingDevice::~FakeRecordingDevice() = default;
+
+void FakeRecordingDevice::set_mic_level(int level) {
+ mic_level_ = level;
+}
+
+int FakeRecordingDevice::mic_level() const {
+ return mic_level_;
+}
+
+void FakeRecordingDevice::set_undo_mic_level(rtc::Optional<int> level) {
+ undo_mic_level_ = level;
+}
+
+rtc::Optional<int> FakeRecordingDevice::undo_mic_level() const {
+ return undo_mic_level_;
+}
+
+void FakeRecordingDevice::SimulateAnalogGain(ChannelBuffer<float>* buffer) {
+ size_t number_of_samples = buffer->num_frames();
+ for (size_t i = 0; i < buffer->num_channels(); ++i) {
+ std::for_each(buffer->channels()[i],
+ buffer->channels()[i] + number_of_samples,
+ [this](float& x) { ModifySampleFloat(&x); });
+ }
+}
+
+void FakeRecordingDevice::SimulateAnalogGain(AudioFrame* buffer) {
+ const size_t number_of_samples =
+ buffer->samples_per_channel_ * buffer->num_channels_;
+ RTC_DCHECK_LE(number_of_samples, AudioFrame::kMaxDataSizeSamples);
+ std::for_each(buffer->data_, buffer->data_ + number_of_samples,
+ [this](int16_t& x) { ModifySampleInt16(&x); });
+}
+
+int16_t FakeRecordingDevice::ClipSampleInt16(int16_t sample) {
+ return std::max(std::min(sample, kSampleMaxInt16), kSampleMinInt16);
+}
+
+float FakeRecordingDevice::ClipSampleFloat(float sample) {
+ return std::max(std::min(sample, kSampleMaxFloat), kSampleMinFloat);
+}
+
+} // namespace test
+} // namespace webrtc

Powered by Google App Engine
This is Rietveld 408576698