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

Side by Side Diff: webrtc/modules/audio_processing/test/wav_based_simulator.cc

Issue 2834643002: audioproc_f with simulated mic analog gain (Closed)
Patch Set: FakeRecordingDevice interface simplified, UTs fixes, logs verbosity-- 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
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"
19 #include "webrtc/modules/audio_processing/test/fake_recording_device.h"
17 #include "webrtc/modules/audio_processing/test/test_utils.h" 20 #include "webrtc/modules/audio_processing/test/test_utils.h"
18 #include "webrtc/test/testsupport/trace_to_stderr.h" 21 #include "webrtc/test/testsupport/trace_to_stderr.h"
19 22
20 namespace webrtc { 23 namespace webrtc {
21 namespace test { 24 namespace test {
22 25
23 std::vector<WavBasedSimulator::SimulationEventType> 26 std::vector<WavBasedSimulator::SimulationEventType>
24 WavBasedSimulator::GetCustomEventChain(const std::string& filename) { 27 WavBasedSimulator::GetCustomEventChain(const std::string& filename) {
25 std::vector<WavBasedSimulator::SimulationEventType> call_chain; 28 std::vector<WavBasedSimulator::SimulationEventType> call_chain;
26 FILE* stream = OpenFile(filename.c_str(), "r"); 29 FILE* stream = OpenFile(filename.c_str(), "r");
(...skipping 21 matching lines...) Expand all
48 } 51 }
49 52
50 num_read = fread(&c, sizeof(char), 1, stream); 53 num_read = fread(&c, sizeof(char), 1, stream);
51 } 54 }
52 55
53 fclose(stream); 56 fclose(stream);
54 return call_chain; 57 return call_chain;
55 } 58 }
56 59
57 WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings) 60 WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings)
58 : AudioProcessingSimulator(settings) {} 61 : AudioProcessingSimulator(settings) {
62 // When a wav file is used, there is no information available about the mic
63 // gain level.
64 real_recording_device_level_ = FakeRecordingDevice::kRealDeviceLevelUnknown;
peah-webrtc 2017/05/05 20:25:21 This seems like exactly what to use Optional for.
AleBzk 2017/05/16 08:53:04 Done.
65 }
59 66
60 WavBasedSimulator::~WavBasedSimulator() = default; 67 WavBasedSimulator::~WavBasedSimulator() = default;
61 68
62 std::vector<WavBasedSimulator::SimulationEventType> 69 std::vector<WavBasedSimulator::SimulationEventType>
63 WavBasedSimulator::GetDefaultEventChain() { 70 WavBasedSimulator::GetDefaultEventChain() {
64 std::vector<WavBasedSimulator::SimulationEventType> call_chain(2); 71 std::vector<WavBasedSimulator::SimulationEventType> call_chain(2);
65 call_chain[0] = SimulationEventType::kProcessStream; 72 call_chain[0] = SimulationEventType::kProcessStream;
66 call_chain[1] = SimulationEventType::kProcessReverseStream; 73 call_chain[1] = SimulationEventType::kProcessReverseStream;
67 return call_chain; 74 return call_chain;
68 } 75 }
69 76
70 void WavBasedSimulator::PrepareProcessStreamCall() { 77 void WavBasedSimulator::PrepareProcessStreamCall() {
71 if (settings_.fixed_interface) { 78 if (settings_.fixed_interface) {
72 CopyToAudioFrame(*in_buf_, &fwd_frame_); 79 CopyToAudioFrame(*in_buf_, &fwd_frame_);
73 } 80 }
74 ap_->set_stream_key_pressed(settings_.use_ts && (*settings_.use_ts)); 81 ap_->set_stream_key_pressed(settings_.use_ts && (*settings_.use_ts));
75 82
76 RTC_CHECK_EQ(AudioProcessing::kNoError, 83 RTC_CHECK_EQ(AudioProcessing::kNoError,
77 ap_->set_stream_delay_ms( 84 ap_->set_stream_delay_ms(
78 settings_.stream_delay ? *settings_.stream_delay : 0)); 85 settings_.stream_delay ? *settings_.stream_delay : 0));
79 86
80 ap_->echo_cancellation()->set_stream_drift_samples( 87 ap_->echo_cancellation()->set_stream_drift_samples(
81 settings_.stream_drift_samples ? *settings_.stream_drift_samples : 0); 88 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 } 89 }
87 90
88 void WavBasedSimulator::PrepareReverseProcessStreamCall() { 91 void WavBasedSimulator::PrepareReverseProcessStreamCall() {
89 if (settings_.fixed_interface) { 92 if (settings_.fixed_interface) {
90 CopyToAudioFrame(*reverse_in_buf_, &rev_frame_); 93 CopyToAudioFrame(*reverse_in_buf_, &rev_frame_);
91 } 94 }
92 } 95 }
93 96
94 void WavBasedSimulator::Process() { 97 void WavBasedSimulator::Process() {
95 std::unique_ptr<test::TraceToStderr> trace_to_stderr; 98 std::unique_ptr<test::TraceToStderr> trace_to_stderr;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 } 139 }
137 140
138 DestroyAudioProcessor(); 141 DestroyAudioProcessor();
139 } 142 }
140 143
141 bool WavBasedSimulator::HandleProcessStreamCall() { 144 bool WavBasedSimulator::HandleProcessStreamCall() {
142 bool samples_left_to_process = buffer_reader_->Read(in_buf_.get()); 145 bool samples_left_to_process = buffer_reader_->Read(in_buf_.get());
143 if (samples_left_to_process) { 146 if (samples_left_to_process) {
144 PrepareProcessStreamCall(); 147 PrepareProcessStreamCall();
145 ProcessStream(settings_.fixed_interface); 148 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 } 149 }
151 return samples_left_to_process; 150 return samples_left_to_process;
152 } 151 }
153 152
154 bool WavBasedSimulator::HandleProcessReverseStreamCall() { 153 bool WavBasedSimulator::HandleProcessReverseStreamCall() {
155 bool samples_left_to_process = 154 bool samples_left_to_process =
156 reverse_buffer_reader_->Read(reverse_in_buf_.get()); 155 reverse_buffer_reader_->Read(reverse_in_buf_.get());
157 if (samples_left_to_process) { 156 if (samples_left_to_process) {
158 PrepareReverseProcessStreamCall(); 157 PrepareReverseProcessStreamCall();
159 ProcessReverseStream(settings_.fixed_interface); 158 ProcessReverseStream(settings_.fixed_interface);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 } 196 }
198 197
199 SetupBuffersConfigsOutputs( 198 SetupBuffersConfigsOutputs(
200 input_sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz, 199 input_sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz,
201 reverse_output_sample_rate_hz, input_num_channels, output_num_channels, 200 reverse_output_sample_rate_hz, input_num_channels, output_num_channels,
202 reverse_num_channels, reverse_output_num_channels); 201 reverse_num_channels, reverse_output_num_channels);
203 } 202 }
204 203
205 } // namespace test 204 } // namespace test
206 } // namespace webrtc 205 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698