| 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
|
|
|