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

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

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: Changes in response to reviewer comments 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 #include "webrtc/modules/audio_processing/test/wav_based_simulator.h"
12
13 #include "webrtc/base/checks.h"
14 #include "webrtc/test/testsupport/trace_to_stderr.h"
15
16 namespace webrtc {
17 namespace test {
18
19 std::vector<WavBasedSimulator::SimulationEventType>
20 WavBasedSimulator::GetDefaultEventChain() const {
21 std::vector<WavBasedSimulator::SimulationEventType> call_chain(2);
22 call_chain[0] = SimulationEventType::kProcessStream;
23 call_chain[1] = SimulationEventType::kProcessReverseStream;
24 return call_chain;
25 }
26
27 void WavBasedSimulator::PrepareProcessStreamCall() {
28 if (settings_.fixed_interface) {
29 CopyToAudioFrame(*in_buf_, &fwd_frame_);
30 }
31 ap_->set_stream_key_pressed(true);
aluebs-webrtc 2016/04/30 02:08:05 Isn't there a setting for this? For example if the
peah-webrtc 2016/05/02 06:18:42 True. Done.
32
33 RTC_CHECK_EQ(AudioProcessing::kNoError,
34 ap_->set_stream_delay_ms(
35 settings_.stream_delay ? *settings_.stream_delay : 0));
36
37 ap_->echo_cancellation()->set_stream_drift_samples(
38 settings_.stream_drift_samples ? *settings_.stream_drift_samples : 0);
39
40 RTC_CHECK_EQ(AudioProcessing::kNoError,
41 ap_->gain_control()->set_stream_analog_level(
42 last_specified_microphone_level_));
aluebs-webrtc 2016/04/30 02:08:05 last_specified_microphone_level_ is never modified
peah-webrtc 2016/05/02 06:18:42 That is a mistake. The idea is to query the last l
aluebs-webrtc 2016/05/03 22:30:40 Maybe I am not familiar enough with this setting,
peah-webrtc 2016/05/09 11:37:31 I'm not sure how it works in APM but this is how p
aluebs-webrtc 2016/05/09 16:27:31 Sounds good.
peah-webrtc 2016/05/11 12:19:27 Acknowledged.
43 }
44
45 void WavBasedSimulator::PrepareReverseProcessStreamCall() {
46 if (settings_.fixed_interface) {
47 CopyToAudioFrame(*reverse_in_buf_, &rev_frame_);
48 }
49 }
50
51 void WavBasedSimulator::Process() {
52 std::unique_ptr<test::TraceToStderr> trace_to_stderr;
53 if (settings_.use_verbose_logging) {
54 trace_to_stderr.reset(new test::TraceToStderr(true));
55 }
56
57 call_chain_ = GetDefaultEventChain();
58 CreateAudioProcessor();
59
60 Initialize();
61
62 bool samples_left_to_process = true;
63 int call_chain_index = 0;
64 int num_forward_chunks_processed = 0;
65 while (samples_left_to_process) {
66 switch (call_chain_[call_chain_index]) {
aluebs-webrtc 2016/04/30 02:08:05 Do we really need this enum-function-vector-switch
peah-webrtc 2016/05/02 06:18:42 The idea is to simplify changing the default call-
aluebs-webrtc 2016/05/03 22:30:40 If you think this is a enough frequent use case to
peah-webrtc 2016/05/09 11:37:31 Acknowledged.
67 case SimulationEventType::kProcessStream:
68 samples_left_to_process = HandleProcessStreamCall();
69 ++num_forward_chunks_processed;
70 break;
71 case SimulationEventType::kProcessReverseStream:
72 if (settings_.reverse_input_filename) {
73 samples_left_to_process = HandleProcessReverseStreamCall();
74 }
75 break;
76 default:
77 RTC_CHECK(false);
78 }
79
80 call_chain_index = (call_chain_index + 1) % call_chain_.size();
81
82 if (trace_to_stderr) {
83 trace_to_stderr->SetTimeSeconds(
84 num_forward_chunks_processed * 1.f /
aluebs-webrtc 2016/04/30 02:08:05 You can cast to avoid a multiplication here.
peah-webrtc 2016/05/02 06:18:42 Done.
85 AudioProcessingSimulator::kChunksPerSecond);
86 }
87 }
88
89 DestroyAudioProcessor();
90 }
91
92 bool WavBasedSimulator::HandleProcessStreamCall() {
93 if (buffer_reader_->Read(in_buf_.get())) {
aluebs-webrtc 2016/04/30 02:08:05 I like functions with only one return statement:
peah-webrtc 2016/05/02 06:18:42 Nice! Done.
94 PrepareProcessStreamCall();
95 ProcessStream(settings_.fixed_interface);
aluebs-webrtc 2016/04/30 02:08:05 Why do we need to pass in this setting? Can't Audi
peah-webrtc 2016/05/02 06:18:42 It could for the wav-based simulation but it canno
aluebs-webrtc 2016/05/03 22:30:40 If that is the case, it makes sense to leave as is
peah-webrtc 2016/05/09 11:37:31 Acknowledged.
96 return true;
97 } else {
98 return false;
99 }
100 }
101
102 bool WavBasedSimulator::HandleProcessReverseStreamCall() {
103 if (reverse_buffer_reader_->Read(reverse_in_buf_.get())) {
104 PrepareReverseProcessStreamCall();
105 ProcessReverseStream(settings_.fixed_interface);
106 return true;
107 } else {
108 return false;
109 }
110 }
111
112 void WavBasedSimulator::Initialize() {
113 std::unique_ptr<WavReader> in_file(
114 new WavReader(settings_.input_filename->c_str()));
115 int input_sample_rate_hz = in_file->sample_rate();
116 int input_num_channels = in_file->num_channels();
117 buffer_reader_.reset(new ChannelBufferWavReader(std::move(in_file)));
118
119 int output_sample_rate_hz = settings_.output_sample_rate_hz
120 ? *settings_.output_sample_rate_hz
121 : input_sample_rate_hz;
122 int output_num_channels = settings_.output_num_channels
123 ? *settings_.output_num_channels
124 : input_num_channels;
125
126 int reverse_sample_rate_hz = 48000;
127 int reverse_num_channels = 1;
128 int reverse_output_sample_rate_hz = 48000;
129 int reverse_output_num_channels = 1;
130 if (settings_.reverse_input_filename) {
131 std::unique_ptr<WavReader> reverse_in_file(
132 new WavReader(settings_.reverse_input_filename->c_str()));
133 reverse_sample_rate_hz = reverse_in_file->sample_rate();
134 reverse_num_channels = reverse_in_file->num_channels();
135 reverse_buffer_reader_.reset(
136 new ChannelBufferWavReader(std::move(reverse_in_file)));
137
138 reverse_output_sample_rate_hz =
139 settings_.reverse_output_sample_rate_hz
140 ? *settings_.reverse_output_sample_rate_hz
141 : reverse_sample_rate_hz;
142 reverse_output_num_channels = settings_.reverse_output_num_channels
143 ? *settings_.reverse_output_num_channels
144 : reverse_num_channels;
145 }
146
147 SetupBuffersConfigsOutputs(
148 input_sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz,
149 reverse_output_sample_rate_hz, input_num_channels, output_num_channels,
150 reverse_num_channels, reverse_output_num_channels);
151 }
152
153 } // namespace test
154 } // namespace webrtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698