OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #include "webrtc/modules/audio_processing/test/wav_based_simulator.h" | 11 #include "webrtc/modules/audio_processing/test/wav_based_simulator.h" |
12 | 12 |
13 #include <stdio.h> | 13 #include <stdio.h> |
14 #include <iostream> | 14 #include <iostream> |
| 15 #include <memory> |
| 16 #include <utility> |
15 | 17 |
16 #include "webrtc/base/checks.h" | 18 #include "webrtc/base/checks.h" |
17 #include "webrtc/modules/audio_processing/test/test_utils.h" | 19 #include "webrtc/modules/audio_processing/test/test_utils.h" |
18 #include "webrtc/test/testsupport/trace_to_stderr.h" | 20 #include "webrtc/test/testsupport/trace_to_stderr.h" |
19 | 21 |
20 namespace webrtc { | 22 namespace webrtc { |
21 namespace test { | 23 namespace test { |
22 | 24 |
23 std::vector<WavBasedSimulator::SimulationEventType> | 25 std::vector<WavBasedSimulator::SimulationEventType> |
24 WavBasedSimulator::GetCustomEventChain(const std::string& filename) { | 26 WavBasedSimulator::GetCustomEventChain(const std::string& filename) { |
(...skipping 23 matching lines...) Expand all Loading... |
48 } | 50 } |
49 | 51 |
50 num_read = fread(&c, sizeof(char), 1, stream); | 52 num_read = fread(&c, sizeof(char), 1, stream); |
51 } | 53 } |
52 | 54 |
53 fclose(stream); | 55 fclose(stream); |
54 return call_chain; | 56 return call_chain; |
55 } | 57 } |
56 | 58 |
57 WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings) | 59 WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings) |
58 : AudioProcessingSimulator(settings) {} | 60 : AudioProcessingSimulator(settings) {} |
59 | 61 |
60 WavBasedSimulator::~WavBasedSimulator() = default; | 62 WavBasedSimulator::~WavBasedSimulator() = default; |
61 | 63 |
62 std::vector<WavBasedSimulator::SimulationEventType> | 64 std::vector<WavBasedSimulator::SimulationEventType> |
63 WavBasedSimulator::GetDefaultEventChain() { | 65 WavBasedSimulator::GetDefaultEventChain() { |
64 std::vector<WavBasedSimulator::SimulationEventType> call_chain(2); | 66 std::vector<WavBasedSimulator::SimulationEventType> call_chain(2); |
65 call_chain[0] = SimulationEventType::kProcessStream; | 67 call_chain[0] = SimulationEventType::kProcessStream; |
66 call_chain[1] = SimulationEventType::kProcessReverseStream; | 68 call_chain[1] = SimulationEventType::kProcessReverseStream; |
67 return call_chain; | 69 return call_chain; |
68 } | 70 } |
69 | 71 |
70 void WavBasedSimulator::PrepareProcessStreamCall() { | 72 void WavBasedSimulator::PrepareProcessStreamCall() { |
71 if (settings_.fixed_interface) { | 73 if (settings_.fixed_interface) { |
72 CopyToAudioFrame(*in_buf_, &fwd_frame_); | 74 CopyToAudioFrame(*in_buf_, &fwd_frame_); |
73 } | 75 } |
74 ap_->set_stream_key_pressed(settings_.use_ts && (*settings_.use_ts)); | 76 ap_->set_stream_key_pressed(settings_.use_ts && (*settings_.use_ts)); |
75 | 77 |
76 RTC_CHECK_EQ(AudioProcessing::kNoError, | 78 RTC_CHECK_EQ(AudioProcessing::kNoError, |
77 ap_->set_stream_delay_ms( | 79 ap_->set_stream_delay_ms( |
78 settings_.stream_delay ? *settings_.stream_delay : 0)); | 80 settings_.stream_delay ? *settings_.stream_delay : 0)); |
79 | 81 |
80 ap_->echo_cancellation()->set_stream_drift_samples( | 82 ap_->echo_cancellation()->set_stream_drift_samples( |
81 settings_.stream_drift_samples ? *settings_.stream_drift_samples : 0); | 83 settings_.stream_drift_samples ? *settings_.stream_drift_samples : 0); |
82 | |
83 RTC_CHECK_EQ(AudioProcessing::kNoError, | |
84 ap_->gain_control()->set_stream_analog_level( | |
85 last_specified_microphone_level_)); | |
86 } | 84 } |
87 | 85 |
88 void WavBasedSimulator::PrepareReverseProcessStreamCall() { | 86 void WavBasedSimulator::PrepareReverseProcessStreamCall() { |
89 if (settings_.fixed_interface) { | 87 if (settings_.fixed_interface) { |
90 CopyToAudioFrame(*reverse_in_buf_, &rev_frame_); | 88 CopyToAudioFrame(*reverse_in_buf_, &rev_frame_); |
91 } | 89 } |
92 } | 90 } |
93 | 91 |
94 void WavBasedSimulator::Process() { | 92 void WavBasedSimulator::Process() { |
95 std::unique_ptr<test::TraceToStderr> trace_to_stderr; | 93 std::unique_ptr<test::TraceToStderr> trace_to_stderr; |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 } | 134 } |
137 | 135 |
138 DestroyAudioProcessor(); | 136 DestroyAudioProcessor(); |
139 } | 137 } |
140 | 138 |
141 bool WavBasedSimulator::HandleProcessStreamCall() { | 139 bool WavBasedSimulator::HandleProcessStreamCall() { |
142 bool samples_left_to_process = buffer_reader_->Read(in_buf_.get()); | 140 bool samples_left_to_process = buffer_reader_->Read(in_buf_.get()); |
143 if (samples_left_to_process) { | 141 if (samples_left_to_process) { |
144 PrepareProcessStreamCall(); | 142 PrepareProcessStreamCall(); |
145 ProcessStream(settings_.fixed_interface); | 143 ProcessStream(settings_.fixed_interface); |
146 // Call stream analog level to ensure that any side-effects are triggered. | |
147 (void)ap_->gain_control()->stream_analog_level(); | |
148 last_specified_microphone_level_ = | |
149 ap_->gain_control()->stream_analog_level(); | |
150 } | 144 } |
151 return samples_left_to_process; | 145 return samples_left_to_process; |
152 } | 146 } |
153 | 147 |
154 bool WavBasedSimulator::HandleProcessReverseStreamCall() { | 148 bool WavBasedSimulator::HandleProcessReverseStreamCall() { |
155 bool samples_left_to_process = | 149 bool samples_left_to_process = |
156 reverse_buffer_reader_->Read(reverse_in_buf_.get()); | 150 reverse_buffer_reader_->Read(reverse_in_buf_.get()); |
157 if (samples_left_to_process) { | 151 if (samples_left_to_process) { |
158 PrepareReverseProcessStreamCall(); | 152 PrepareReverseProcessStreamCall(); |
159 ProcessReverseStream(settings_.fixed_interface); | 153 ProcessReverseStream(settings_.fixed_interface); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 } | 191 } |
198 | 192 |
199 SetupBuffersConfigsOutputs( | 193 SetupBuffersConfigsOutputs( |
200 input_sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz, | 194 input_sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz, |
201 reverse_output_sample_rate_hz, input_num_channels, output_num_channels, | 195 reverse_output_sample_rate_hz, input_num_channels, output_num_channels, |
202 reverse_num_channels, reverse_output_num_channels); | 196 reverse_num_channels, reverse_output_num_channels); |
203 } | 197 } |
204 | 198 |
205 } // namespace test | 199 } // namespace test |
206 } // namespace webrtc | 200 } // namespace webrtc |
OLD | NEW |