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

Side by Side Diff: webrtc/modules/audio_processing/test/fake_recording_device.h

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 unified diff | Download patch
OLDNEW
(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 <memory>
16 #include <vector>
17
18 #include "webrtc/base/array_view.h"
19 #include "webrtc/base/checks.h"
20 #include "webrtc/common_audio/channel_buffer.h"
21 #include "webrtc/modules/include/module_common_types.h"
22
23 namespace webrtc {
24 namespace test {
25
26 // Abstract class for simulating a microphone with analog gain.
27 //
28 // The intended mode of operation is the following:
29 //
30 // auto fake_mic = FakeRecordingDeviceLinear(255);
31 //
32 // fake_mic.set_mic_level(170);
33 // fake_mic.set_mic_level(rtc::Optional<int>());
34 // fake_mic.SimulateAnalogGain(buffer);
35 //
36 // Simulate the microphone level 170.
37 //
38 // fake_mic.set_mic_level(170);
39 // fake_mic.set_mic_level(rtc::Optional<int>(30));
40 // fake_mic.SimulateAnalogGain(buffer);
41 //
42 // Virtually restore the unmodified microphone level knowing that the data in
43 // buffer has recorded from a microphone having 30 as level.
44 // Then, calling SimulateAnalogGain() will first "undo" the gain applied by the
45 // real microphone.
46 class FakeRecordingDevice {
47 public:
48 enum class DeviceKind { IDENTITY, LINEAR };
49
50 explicit FakeRecordingDevice(int initial_mic_level);
51 virtual ~FakeRecordingDevice() = 0;
52
53 // FakeRecordingDevice factory.
54 static std::unique_ptr<FakeRecordingDevice> GetFakeRecDevice(
55 DeviceKind kind, int initial_mic_level);
56
57 // Setter and getter for the mic level to simulate.
58 void set_mic_level(int level);
59 int mic_level() const;
60
61 // Setter and getter for the mic level to undo.
62 void set_undo_mic_level(rtc::Optional<int> level);
63 rtc::Optional<int> undo_mic_level() const;
64
65 // Simulates the analog gain on an std::vector<rtc::ArrayView<float>> buffer.
66 // If |real_device_level| is a valid level, the unmodified mic signal is
67 // virtually restored. To skip the latter step set |real_device_level| to
68 // an empty value.
69 void SimulateAnalogGain(std::vector<rtc::ArrayView<float>> buffer);
AleBzk 2017/05/23 13:56:41 @Per: thanks for your comments on keeping the API
70
71 // Simulates the analog gain on a ChannelBuffer<float> buffer.
72 // For further details, see the comment above.
73 void SimulateAnalogGain(ChannelBuffer<float>* buffer);
74
75 // Simulates the analog gain on an AudioFrame buffer (fixed point).
76 // For further details, see the comment above.
77 void SimulateAnalogGain(AudioFrame* buffer);
78
79 protected:
80 // Abstract methods required by SimulateAnalogGain().
81 virtual void ModifySampleInt16(int16_t* sample) = 0;
82 virtual void ModifySampleFloat(float* sample) = 0;
83
84 int16_t ClipSampleInt16(int16_t sample);
85 float ClipSampleFloat(float sample);
86
87 private:
88 // Mic level to simulate.
89 int mic_level_;
90
91 // Optional undo mic level.
92 rtc::Optional<int> undo_mic_level_;
93 };
94
95 } // namespace test
96 } // namespace webrtc
97
98 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698