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

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

Issue 2561843003: Added functionality for simulating custom orders of the stream API calls in audioproc_f (Closed)
Patch Set: Changes in response to reviewer comments Created 4 years 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
« no previous file with comments | « webrtc/modules/audio_processing/test/wav_based_simulator.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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>
14 #include <iostream>
15
13 #include "webrtc/base/checks.h" 16 #include "webrtc/base/checks.h"
17 #include "webrtc/modules/audio_processing/test/test_utils.h"
14 #include "webrtc/test/testsupport/trace_to_stderr.h" 18 #include "webrtc/test/testsupport/trace_to_stderr.h"
15 19
16 namespace webrtc { 20 namespace webrtc {
17 namespace test { 21 namespace test {
18 22
23 std::vector<WavBasedSimulator::SimulationEventType>
24 WavBasedSimulator::GetCustomEventChain(const std::string& filename) {
25 std::vector<WavBasedSimulator::SimulationEventType> call_chain;
26 FILE* stream = OpenFile(filename.c_str(), "r");
27
28 RTC_CHECK(stream) << "Could not open the custom call order file, reverting "
29 "to using the default call order";
30
31 char c;
32 size_t num_read = fread(&c, sizeof(char), 1, stream);
33 while (num_read > 0) {
34 switch (c) {
35 case 'r':
36 call_chain.push_back(SimulationEventType::kProcessReverseStream);
37 break;
38 case 'c':
39 call_chain.push_back(SimulationEventType::kProcessStream);
40 break;
41 case '\n':
42 break;
43 default:
44 FATAL() << "Incorrect custom call order file, reverting to using the "
45 "default call order";
46 fclose(stream);
47 return WavBasedSimulator::GetDefaultEventChain();
48 }
49
50 num_read = fread(&c, sizeof(char), 1, stream);
51 }
52
53 fclose(stream);
54 return call_chain;
55 }
56
19 WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings) 57 WavBasedSimulator::WavBasedSimulator(const SimulationSettings& settings)
20 : AudioProcessingSimulator(settings) {} 58 : AudioProcessingSimulator(settings) {}
21 59
22 WavBasedSimulator::~WavBasedSimulator() = default; 60 WavBasedSimulator::~WavBasedSimulator() = default;
23 61
24 std::vector<WavBasedSimulator::SimulationEventType> 62 std::vector<WavBasedSimulator::SimulationEventType>
25 WavBasedSimulator::GetDefaultEventChain() const { 63 WavBasedSimulator::GetDefaultEventChain() {
26 std::vector<WavBasedSimulator::SimulationEventType> call_chain(2); 64 std::vector<WavBasedSimulator::SimulationEventType> call_chain(2);
27 call_chain[0] = SimulationEventType::kProcessStream; 65 call_chain[0] = SimulationEventType::kProcessStream;
28 call_chain[1] = SimulationEventType::kProcessReverseStream; 66 call_chain[1] = SimulationEventType::kProcessReverseStream;
29 return call_chain; 67 return call_chain;
30 } 68 }
31 69
32 void WavBasedSimulator::PrepareProcessStreamCall() { 70 void WavBasedSimulator::PrepareProcessStreamCall() {
33 if (settings_.fixed_interface) { 71 if (settings_.fixed_interface) {
34 CopyToAudioFrame(*in_buf_, &fwd_frame_); 72 CopyToAudioFrame(*in_buf_, &fwd_frame_);
35 } 73 }
(...skipping 16 matching lines...) Expand all
52 CopyToAudioFrame(*reverse_in_buf_, &rev_frame_); 90 CopyToAudioFrame(*reverse_in_buf_, &rev_frame_);
53 } 91 }
54 } 92 }
55 93
56 void WavBasedSimulator::Process() { 94 void WavBasedSimulator::Process() {
57 std::unique_ptr<test::TraceToStderr> trace_to_stderr; 95 std::unique_ptr<test::TraceToStderr> trace_to_stderr;
58 if (settings_.use_verbose_logging) { 96 if (settings_.use_verbose_logging) {
59 trace_to_stderr.reset(new test::TraceToStderr(true)); 97 trace_to_stderr.reset(new test::TraceToStderr(true));
60 } 98 }
61 99
62 call_chain_ = GetDefaultEventChain(); 100 if (settings_.custom_call_order_filename) {
101 call_chain_ = WavBasedSimulator::GetCustomEventChain(
102 *settings_.custom_call_order_filename);
103 } else {
104 call_chain_ = WavBasedSimulator::GetDefaultEventChain();
105 }
63 CreateAudioProcessor(); 106 CreateAudioProcessor();
64 107
65 Initialize(); 108 Initialize();
66 109
67 bool samples_left_to_process = true; 110 bool samples_left_to_process = true;
68 int call_chain_index = 0; 111 int call_chain_index = 0;
69 int num_forward_chunks_processed = 0; 112 int num_forward_chunks_processed = 0;
70 const int kOneBykChunksPerSecond = 113 const int kOneBykChunksPerSecond =
71 1.f / AudioProcessingSimulator::kChunksPerSecond; 114 1.f / AudioProcessingSimulator::kChunksPerSecond;
72 while (samples_left_to_process) { 115 while (samples_left_to_process) {
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 } 197 }
155 198
156 SetupBuffersConfigsOutputs( 199 SetupBuffersConfigsOutputs(
157 input_sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz, 200 input_sample_rate_hz, output_sample_rate_hz, reverse_sample_rate_hz,
158 reverse_output_sample_rate_hz, input_num_channels, output_num_channels, 201 reverse_output_sample_rate_hz, input_num_channels, output_num_channels,
159 reverse_num_channels, reverse_output_num_channels); 202 reverse_num_channels, reverse_output_num_channels);
160 } 203 }
161 204
162 } // namespace test 205 } // namespace test
163 } // namespace webrtc 206 } // namespace webrtc
OLDNEW
« no previous file with comments | « webrtc/modules/audio_processing/test/wav_based_simulator.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698