| 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..8e19e058f57fc43a9078c318a24ce1fe6d930c15
|
| --- /dev/null
|
| +++ b/webrtc/modules/audio_processing/test/fake_recording_device.h
|
| @@ -0,0 +1,79 @@
|
| +/*
|
| + * 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 <vector>
|
| +
|
| +#include "webrtc/base/array_view.h"
|
| +#include "webrtc/base/checks.h"
|
| +#include "webrtc/base/optional.h"
|
| +#include "webrtc/modules/include/module_common_types.h"
|
| +
|
| +namespace webrtc {
|
| +
|
| +// Class for simulating an analog gain controller controlled by
|
| +// webrtc::GainControl. The class wraps a mapping from the current
|
| +// level to a floating point scaling factor with the goal of
|
| +// abstracting non-linearities in the gain curve of real analog
|
| +// microphones. The intended mode of operation is
|
| +//
|
| +// set_analog_level(|level suggested by GainControl|);
|
| +// NotifyAudioDeviceLevel(|recorded level of real microphone|); // Optional!
|
| +// ProcessStream(src, dest)
|
| +//
|
| +// In these three calls, the fake device optionally undoes the gain
|
| +// applied by the real microphone. Then in applies a new gain
|
| +// suggested by the AGC.
|
| +class FakeRecordingDevice {
|
| + public:
|
| + enum class LevelToScalingMappingKind {
|
| + kLinear // A level within [0, 255] is linearly scaled. 0 produces
|
| + // 0.f, and 255 is 1.0f.
|
| + };
|
| +
|
| + explicit FakeRecordingDevice(LevelToScalingMappingKind mapping_kind);
|
| +
|
| + ~FakeRecordingDevice();
|
| +
|
| + // Setters/getters for |level_|. The parameter |level| must be
|
| + // within [0, 255].
|
| + void set_analog_level(int level);
|
| + int analog_level() const;
|
| +
|
| + void ProcessStream(std::vector<rtc::ArrayView<const float>> src,
|
| + std::vector<rtc::ArrayView<float>> dest);
|
| +
|
| + void ProcessStream(const AudioFrame* src, AudioFrame* dest);
|
| +
|
| + // Meant to be called before ProcessStream if the source signal
|
| + // passed to ProcessStream has been recorded from a microphone with
|
| + // known gain.
|
| + void NotifyAudioDeviceLevel(int level);
|
| +
|
| + private:
|
| + // Computes scaling factor based on both the recorded real device
|
| + // level, gain curve (which depends on |mapping_kind_) and the
|
| + // current level.
|
| + float ComputeCompoundScalingFactor();
|
| +
|
| + // Compute scaling factor based on current gain curve, which depends
|
| + // on |mapping_kind_|.
|
| + float GetScalingFactor(int level) const;
|
| +
|
| + int level_ = 0;
|
| + rtc::Optional<int> real_device_level_;
|
| + const LevelToScalingMappingKind mapping_kind_;
|
| +};
|
| +} // namespace webrtc
|
| +
|
| +#endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_
|
|
|