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

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

Issue 1907223003: Extension and refactoring of the audioproc_f tool to be a fully fledged tool for audio processing m… (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: Rebase with latest master Created 4 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) 2016 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_AUDIO_PROCESSING_SIMULATOR_H_
12 #define WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_PROCESSING_SIMULATOR_H_
13
14 #include <algorithm>
15 #include <limits>
16 #include <memory>
17 #include <string>
18
19 #include "webrtc/base/timeutils.h"
20 #include "webrtc/base/constructormagic.h"
21 #include "webrtc/base/optional.h"
22 #include "webrtc/common_audio/channel_buffer.h"
23 #include "webrtc/modules/audio_processing/include/audio_processing.h"
24 #include "webrtc/modules/audio_processing/test/test_utils.h"
25
26 namespace webrtc {
27 namespace test {
28
29 // Holds all the parameters available for controlling the simulation.
30 struct SimulationSettings {
31 rtc::Optional<int> stream_delay;
32 rtc::Optional<int> stream_drift_samples;
33 rtc::Optional<int> output_sample_rate_hz;
34 rtc::Optional<int> output_num_channels;
35 rtc::Optional<int> reverse_output_sample_rate_hz;
36 rtc::Optional<int> reverse_output_num_channels;
37 rtc::Optional<std::string> microphone_positions;
38 int target_angle_degrees = 90;
39 rtc::Optional<std::string> output_filename;
40 rtc::Optional<std::string> reverse_output_filename;
41 rtc::Optional<std::string> input_filename;
42 rtc::Optional<std::string> reverse_input_filename;
43 rtc::Optional<bool> use_aec;
44 rtc::Optional<bool> use_aecm;
45 rtc::Optional<bool> use_agc;
46 rtc::Optional<bool> use_hpf;
47 rtc::Optional<bool> use_ns;
48 rtc::Optional<bool> use_ts;
49 rtc::Optional<bool> use_bf;
50 rtc::Optional<bool> use_ie;
51 rtc::Optional<bool> use_vad;
52 rtc::Optional<bool> use_le;
53 rtc::Optional<bool> use_all;
54 rtc::Optional<int> aec_suppression_level;
55 rtc::Optional<bool> use_delay_agnostic;
56 rtc::Optional<bool> use_extended_filter;
57 rtc::Optional<bool> use_drift_compensation;
58 rtc::Optional<bool> use_aec3;
59 rtc::Optional<int> aecm_routing_mode;
60 rtc::Optional<bool> use_aecm_comfort_noise;
61 rtc::Optional<int> agc_mode;
62 rtc::Optional<int> agc_target_level;
63 rtc::Optional<bool> use_agc_limiter;
64 rtc::Optional<int> agc_compression_gain;
65 rtc::Optional<int> vad_likelihood;
66 rtc::Optional<int> ns_level;
67 rtc::Optional<bool> use_refined_adaptive_filter;
68 bool report_performance = false;
69 bool report_bitexactness = false;
70 bool use_verbose_logging = false;
71 bool discard_all_settings_in_aecdump = true;
72 rtc::Optional<std::string> aec_dump_input_filename;
73 rtc::Optional<std::string> aec_dump_output_filename;
74 bool fixed_interface = false;
75 bool store_intermediate_output = false;
76 };
77
78 // Holds a few statistics about a series of TickIntervals.
79 struct TickIntervalStats {
80 TickIntervalStats() : min(std::numeric_limits<int64_t>::max()) {}
81 int64_t sum;
82 int64_t max;
83 int64_t min;
84 };
85
86 // Copies samples present in a ChannelBuffer into an AudioFrame.
87 void CopyToAudioFrame(const ChannelBuffer<float>& src, AudioFrame* dest);
88
89 // Provides common functionality for performing audioprocessing simulations.
90 class AudioProcessingSimulator {
91 public:
92 static const int kChunksPerSecond = 1000 / AudioProcessing::kChunkSizeMs;
93
94 explicit AudioProcessingSimulator(const SimulationSettings& settings)
95 : settings_(settings) {}
96 virtual ~AudioProcessingSimulator() {}
97
98 // Processes the data in the input.
99 virtual void Process() = 0;
100
101 // Returns the execution time of all AudioProcessing calls.
102 const TickIntervalStats& proc_time() const { return proc_time_; }
103
104 // Reports whether the processed recording was bitexact.
105 bool OutputWasBitexact() { return bitexact_output_; }
106
107 size_t get_num_process_stream_calls() { return num_process_stream_calls_; }
108 size_t get_num_reverse_process_stream_calls() {
109 return num_reverse_process_stream_calls_;
110 }
111
112 protected:
113 // RAII class for execution time measurement. Updates the provided
114 // TickIntervalStats based on the time between ScopedTimer creation and
115 // leaving the enclosing scope.
116 class ScopedTimer {
117 public:
118 explicit ScopedTimer(TickIntervalStats* proc_time)
119 : proc_time_(proc_time), start_time_(rtc::TimeNanos()) {}
120
121 ~ScopedTimer();
122
123 private:
124 TickIntervalStats* const proc_time_;
125 int64_t start_time_;
126 };
127
128 TickIntervalStats* mutable_proc_time() { return &proc_time_; }
129 void ProcessStream(bool fixed_interface);
130 void ProcessReverseStream(bool fixed_interface);
131 void CreateAudioProcessor();
132 void DestroyAudioProcessor();
133 void SetupBuffersConfigsOutputs(int input_sample_rate_hz,
134 int output_sample_rate_hz,
135 int reverse_input_sample_rate_hz,
136 int reverse_output_sample_rate_hz,
137 int input_num_channels,
138 int output_num_channels,
139 int reverse_input_num_channels,
140 int reverse_output_num_channels);
141
142 const SimulationSettings settings_;
143 std::unique_ptr<AudioProcessing> ap_;
144
145 std::unique_ptr<ChannelBuffer<float>> in_buf_;
146 std::unique_ptr<ChannelBuffer<float>> out_buf_;
147 std::unique_ptr<ChannelBuffer<float>> reverse_in_buf_;
148 std::unique_ptr<ChannelBuffer<float>> reverse_out_buf_;
149 StreamConfig in_config_;
150 StreamConfig out_config_;
151 StreamConfig reverse_in_config_;
152 StreamConfig reverse_out_config_;
153 std::unique_ptr<ChannelBufferWavReader> buffer_reader_;
154 std::unique_ptr<ChannelBufferWavReader> reverse_buffer_reader_;
155 AudioFrame rev_frame_;
156 AudioFrame fwd_frame_;
157 bool bitexact_output_ = true;
158
159 private:
160 void SetupOutput();
161
162 size_t num_process_stream_calls_ = 0;
163 size_t num_reverse_process_stream_calls_ = 0;
164 size_t output_reset_counter_ = 0;
165 std::unique_ptr<ChannelBufferWavWriter> buffer_writer_;
166 std::unique_ptr<ChannelBufferWavWriter> reverse_buffer_writer_;
167 TickIntervalStats proc_time_;
168
169 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioProcessingSimulator);
170 };
171
172 } // namespace test
173 } // namespace webrtc
174
175 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_PROCESSING_SIMULATOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698