OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
| 3 * |
| 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ |
| 10 |
| 11 #ifndef WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ |
| 12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ |
| 13 |
| 14 #include <algorithm> |
| 15 #include <vector> |
| 16 |
| 17 #include "webrtc/base/array_view.h" |
| 18 #include "webrtc/base/checks.h" |
| 19 #include "webrtc/base/optional.h" |
| 20 #include "webrtc/modules/include/module_common_types.h" |
| 21 |
| 22 namespace webrtc { |
| 23 |
| 24 // Class for simulating an analog gain controller controlled by |
| 25 // webrtc::GainControl. The class wraps a mapping from the current |
| 26 // level to a floating point scaling factor with the goal of |
| 27 // abstracting non-linearities in the gain curve of real analog |
| 28 // microphones. The intended mode of operation is |
| 29 // |
| 30 // set_analog_level(|level suggested by GainControl|); |
| 31 // NotifyAudioDeviceLevel(|recorded level of real microphone|); // Optional! |
| 32 // ProcessStream(src, dest) |
| 33 // |
| 34 // In these three calls, the fake device optionally undoes the gain |
| 35 // applied by the real microphone. Then in applies a new gain |
| 36 // suggested by the AGC. |
| 37 class FakeRecordingDevice { |
| 38 public: |
| 39 enum class LevelToScalingMappingKind { |
| 40 kLinear // A level within [0, 255] is linearly scaled. 0 produces |
| 41 // 0.f, and 255 is 1.0f. |
| 42 }; |
| 43 |
| 44 explicit FakeRecordingDevice(LevelToScalingMappingKind mapping_kind); |
| 45 |
| 46 ~FakeRecordingDevice(); |
| 47 |
| 48 // Setters/getters for |level_|. The parameter |level| must be |
| 49 // within [0, 255]. |
| 50 void set_analog_level(int level); |
| 51 int analog_level() const; |
| 52 |
| 53 void ProcessStream(std::vector<rtc::ArrayView<const float>> src, |
| 54 std::vector<rtc::ArrayView<float>> dest); |
| 55 |
| 56 void ProcessStream(const AudioFrame* src, AudioFrame* dest); |
| 57 |
| 58 // Meant to be called before ProcessStream if the source signal |
| 59 // passed to ProcessStream has been recorded from a microphone with |
| 60 // known gain. |
| 61 void NotifyAudioDeviceLevel(int level); |
| 62 |
| 63 private: |
| 64 // Computes scaling factor based on both the recorded real device |
| 65 // level, gain curve (which depends on |mapping_kind_) and the |
| 66 // current level. |
| 67 float ComputeCompoundScalingFactor(); |
| 68 |
| 69 // Compute scaling factor based on current gain curve, which depends |
| 70 // on |mapping_kind_|. |
| 71 float GetScalingFactor(int level) const; |
| 72 |
| 73 int level_ = 0; |
| 74 rtc::Optional<int> real_device_level_; |
| 75 const LevelToScalingMappingKind mapping_kind_; |
| 76 }; |
| 77 } // namespace webrtc |
| 78 |
| 79 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_ |
OLD | NEW |