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

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: 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 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 {
peah-webrtc 2017/05/23 22:13:20 I really think we should put as little implementat
AleBzk 2017/06/22 10:16:00 Done.
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.
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(ChannelBuffer<float>* buffer);
70
71 // Simulates the analog gain.
72 // If |real_device_level| is a valid level, the unmodified mic signal is
73 // virtually restored. To skip the latter step set |real_device_level| to
74 // an empty value.
75 void SimulateAnalogGain(AudioFrame* buffer);
76
77 protected:
78 // Abstract methods required by SimulateAnalogGain().
79 virtual void ModifySampleInt16(int16_t* sample) = 0;
80 virtual void ModifySampleFloat(float* sample) = 0;
81
82 int16_t ClipSampleInt16(int16_t sample);
83 float ClipSampleFloat(float sample);
84
85 private:
86 // Mic level to simulate.
87 int mic_level_;
88
89 // Optional undo mic level.
90 rtc::Optional<int> undo_mic_level_;
91 };
92
93 } // namespace test
94 } // namespace webrtc
95
96 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_FAKE_RECORDING_DEVICE_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698