OLD | NEW |
(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/constructormagic.h" |
| 20 #include "webrtc/base/optional.h" |
| 21 #include "webrtc/common_audio/channel_buffer.h" |
| 22 #include "webrtc/modules/audio_processing/include/audio_processing.h" |
| 23 #include "webrtc/modules/audio_processing/test/test_utils.h" |
| 24 #include "webrtc/system_wrappers/include/tick_util.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 TickInterval sum; |
| 82 TickInterval max; |
| 83 TickInterval 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_(TickTime::Now()) {} |
| 120 |
| 121 ~ScopedTimer(); |
| 122 |
| 123 private: |
| 124 TickIntervalStats* const proc_time_; |
| 125 TickTime start_time_; |
| 126 }; |
| 127 |
| 128 TickIntervalStats* mutable_proc_time() { return &proc_time_; } |
| 129 |
| 130 private: |
| 131 void SetupOutput(); |
| 132 |
| 133 size_t num_process_stream_calls_ = 0; |
| 134 size_t num_reverse_process_stream_calls_ = 0; |
| 135 size_t output_reset_counter_ = 0; |
| 136 std::unique_ptr<ChannelBufferWavWriter> buffer_writer_; |
| 137 std::unique_ptr<ChannelBufferWavWriter> reverse_buffer_writer_; |
| 138 |
| 139 protected: |
| 140 void ProcessStream(bool fixed_interface); |
| 141 void ProcessReverseStream(bool fixed_interface); |
| 142 void CreateAudioProcessor(); |
| 143 void DestroyAudioProcessor(); |
| 144 void SetupBuffersConfigsOutputs(int input_sample_rate_hz, |
| 145 int output_sample_rate_hz, |
| 146 int reverse_input_sample_rate_hz, |
| 147 int reverse_output_sample_rate_hz, |
| 148 int input_num_channels, |
| 149 int output_num_channels, |
| 150 int reverse_input_num_channels, |
| 151 int reverse_output_num_channels); |
| 152 |
| 153 const SimulationSettings& settings_; |
| 154 std::unique_ptr<AudioProcessing> ap_; |
| 155 |
| 156 std::unique_ptr<ChannelBuffer<float>> in_buf_; |
| 157 std::unique_ptr<ChannelBuffer<float>> out_buf_; |
| 158 std::unique_ptr<ChannelBuffer<float>> reverse_in_buf_; |
| 159 std::unique_ptr<ChannelBuffer<float>> reverse_out_buf_; |
| 160 StreamConfig in_config_; |
| 161 StreamConfig out_config_; |
| 162 StreamConfig reverse_in_config_; |
| 163 StreamConfig reverse_out_config_; |
| 164 std::unique_ptr<ChannelBufferWavReader> buffer_reader_; |
| 165 std::unique_ptr<ChannelBufferWavReader> reverse_buffer_reader_; |
| 166 AudioFrame rev_frame_; |
| 167 AudioFrame fwd_frame_; |
| 168 bool bitexact_output_ = true; |
| 169 |
| 170 private: |
| 171 TickIntervalStats proc_time_; |
| 172 |
| 173 RTC_DISALLOW_IMPLICIT_CONSTRUCTORS(AudioProcessingSimulator); |
| 174 }; |
| 175 |
| 176 } // namespace test |
| 177 } // namespace webrtc |
| 178 |
| 179 #endif // WEBRTC_MODULES_AUDIO_PROCESSING_TEST_AUDIO_PROCESSING_SIMULATOR_H_ |
OLD | NEW |