blob: 142b49730a36170b6576174a5b731228fd657ba3 [file] [log] [blame]
andrew@webrtc.orgcb181212011-10-26 00:27:17 +00001/*
2 * Copyright (c) 2011 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// Commandline tool to unpack audioproc debug files.
12//
13// The debug files are dumped as protobuf blobs. For analysis, it's necessary
14// to unpack the file into its component parts: audio and other data.
15
16#include <stdio.h>
17
kwiberg62eaacf2016-02-17 06:39:05 -080018#include <memory>
19
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020020#include "modules/audio_processing/test/protobuf_utils.h"
21#include "modules/audio_processing/test/test_utils.h"
22#include "rtc_base/flags.h"
23#include "rtc_base/format_macros.h"
24#include "rtc_base/ignore_wundef.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020025#include "rtc_base/strings/string_builder.h"
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000026
kwiberg77eab702016-09-28 17:42:01 -070027RTC_PUSH_IGNORING_WUNDEF()
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020028#include "modules/audio_processing/debug.pb.h"
kwiberg77eab702016-09-28 17:42:01 -070029RTC_POP_IGNORING_WUNDEF()
30
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000031// TODO(andrew): unpack more of the data.
Mirko Bonadei2dfa9982018-10-18 11:35:32 +020032WEBRTC_DEFINE_string(input_file, "input", "The name of the input stream file.");
33WEBRTC_DEFINE_string(output_file,
34 "ref_out",
35 "The name of the reference output stream file.");
36WEBRTC_DEFINE_string(reverse_file,
37 "reverse",
38 "The name of the reverse input stream file.");
39WEBRTC_DEFINE_string(delay_file, "delay.int32", "The name of the delay file.");
40WEBRTC_DEFINE_string(drift_file, "drift.int32", "The name of the drift file.");
41WEBRTC_DEFINE_string(level_file, "level.int32", "The name of the level file.");
42WEBRTC_DEFINE_string(keypress_file,
43 "keypress.bool",
44 "The name of the keypress file.");
45WEBRTC_DEFINE_string(callorder_file,
46 "callorder",
47 "The name of the render/capture call order file.");
48WEBRTC_DEFINE_string(settings_file,
49 "settings.txt",
50 "The name of the settings file.");
51WEBRTC_DEFINE_bool(full,
52 false,
53 "Unpack the full set of files (normally not needed).");
54WEBRTC_DEFINE_bool(raw, false, "Write raw data instead of a WAV file.");
55WEBRTC_DEFINE_bool(
56 text,
57 false,
58 "Write non-audio files as text files instead of binary files.");
59WEBRTC_DEFINE_bool(help, false, "Print this message.");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000060
Yves Gerey665174f2018-06-19 15:03:05 +020061#define PRINT_CONFIG(field_name) \
62 if (msg.has_##field_name()) { \
Minyue13b96ba2015-10-03 00:39:14 +020063 fprintf(settings_file, " " #field_name ": %d\n", msg.field_name()); \
64 }
65
Alex Loiko5feb30e2018-04-16 13:52:32 +020066#define PRINT_CONFIG_FLOAT(field_name) \
67 if (msg.has_##field_name()) { \
68 fprintf(settings_file, " " #field_name ": %f\n", msg.field_name()); \
69 }
70
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000071namespace webrtc {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000072
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000073using audioproc::Event;
74using audioproc::ReverseStream;
75using audioproc::Stream;
76using audioproc::Init;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000077
Sam Zackrissonf61475d2018-05-11 11:34:49 +020078namespace {
79
Yves Gerey665174f2018-06-19 15:03:05 +020080void WriteData(const void* data,
81 size_t size,
82 FILE* file,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000083 const std::string& filename) {
84 if (fwrite(data, size, 1, file) != 1) {
85 printf("Error when writing to %s\n", filename.c_str());
86 exit(1);
87 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000088}
89
Sam Zackrissonf61475d2018-05-11 11:34:49 +020090void WriteCallOrderData(const bool render_call,
91 FILE* file,
92 const std::string& filename) {
93 const char call_type = render_call ? 'r' : 'c';
94 WriteData(&call_type, sizeof(call_type), file, filename.c_str());
95}
96
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +020097bool WritingCallOrderFile() {
98 return FLAG_full;
99}
100
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200101} // namespace
102
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000103int do_main(int argc, char* argv[]) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000104 std::string program_name = argv[0];
Yves Gerey665174f2018-06-19 15:03:05 +0200105 std::string usage =
106 "Commandline tool to unpack audioproc debug files.\n"
107 "Example usage:\n" +
108 program_name + " debug_dump.pb\n";
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000109
Yves Gerey665174f2018-06-19 15:03:05 +0200110 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
111 argc < 2) {
oprypin6e09d872017-08-31 03:21:39 -0700112 printf("%s", usage.c_str());
113 if (FLAG_help) {
114 rtc::FlagList::Print(nullptr, false);
115 return 0;
116 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000117 return 1;
118 }
119
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000120 FILE* debug_file = OpenFile(argv[1], "rb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000121
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000122 Event event_msg;
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000123 int frame_count = 0;
pkasting25702cb2016-01-08 13:50:27 -0800124 size_t reverse_samples_per_channel = 0;
125 size_t input_samples_per_channel = 0;
126 size_t output_samples_per_channel = 0;
Peter Kasting69558702016-01-12 16:26:35 -0800127 size_t num_reverse_channels = 0;
128 size_t num_input_channels = 0;
129 size_t num_output_channels = 0;
kwiberg62eaacf2016-02-17 06:39:05 -0800130 std::unique_ptr<WavWriter> reverse_wav_file;
131 std::unique_ptr<WavWriter> input_wav_file;
132 std::unique_ptr<WavWriter> output_wav_file;
133 std::unique_ptr<RawFile> reverse_raw_file;
134 std::unique_ptr<RawFile> input_raw_file;
135 std::unique_ptr<RawFile> output_raw_file;
Minyue13b96ba2015-10-03 00:39:14 +0200136
Jonas Olsson366a50c2018-09-06 13:41:30 +0200137 rtc::StringBuilder callorder_raw_name;
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200138 callorder_raw_name << FLAG_callorder_file << ".char";
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200139 FILE* callorder_char_file = WritingCallOrderFile()
140 ? OpenFile(callorder_raw_name.str(), "wb")
141 : nullptr;
oprypin6e09d872017-08-31 03:21:39 -0700142 FILE* settings_file = OpenFile(FLAG_settings_file, "wb");
Minyue13b96ba2015-10-03 00:39:14 +0200143
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000144 while (ReadMessageFromFile(debug_file, &event_msg)) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000145 if (event_msg.type() == Event::REVERSE_STREAM) {
146 if (!event_msg.has_reverse_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000147 printf("Corrupt input file: ReverseStream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000148 return 1;
149 }
150
151 const ReverseStream msg = event_msg.reverse_stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000152 if (msg.has_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700153 if (FLAG_raw && !reverse_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200154 reverse_raw_file.reset(
155 new RawFile(std::string(FLAG_reverse_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000156 }
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000157 // TODO(aluebs): Replace "num_reverse_channels *
158 // reverse_samples_per_channel" with "msg.data().size() /
159 // sizeof(int16_t)" and so on when this fix in audio_processing has made
160 // it into stable: https://webrtc-codereview.appspot.com/15299004/
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000161 WriteIntData(reinterpret_cast<const int16_t*>(msg.data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000162 num_reverse_channels * reverse_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200163 reverse_wav_file.get(), reverse_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000164 } else if (msg.channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700165 if (FLAG_raw && !reverse_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200166 reverse_raw_file.reset(
167 new RawFile(std::string(FLAG_reverse_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000168 }
kwiberg62eaacf2016-02-17 06:39:05 -0800169 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200170 new const float*[num_reverse_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800171 for (size_t i = 0; i < num_reverse_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000172 data[i] = reinterpret_cast<const float*>(msg.channel(i).data());
173 }
Yves Gerey665174f2018-06-19 15:03:05 +0200174 WriteFloatData(data.get(), reverse_samples_per_channel,
175 num_reverse_channels, reverse_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000176 reverse_raw_file.get());
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000177 }
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200178 if (FLAG_full) {
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200179 if (WritingCallOrderFile()) {
180 WriteCallOrderData(true /* render_call */, callorder_char_file,
181 FLAG_callorder_file);
182 }
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200183 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000184 } else if (event_msg.type() == Event::STREAM) {
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000185 frame_count++;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000186 if (!event_msg.has_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000187 printf("Corrupt input file: Stream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000188 return 1;
189 }
190
191 const Stream msg = event_msg.stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000192 if (msg.has_input_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700193 if (FLAG_raw && !input_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200194 input_raw_file.reset(
195 new RawFile(std::string(FLAG_input_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000196 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000197 WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000198 num_input_channels * input_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200199 input_wav_file.get(), input_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000200 } else if (msg.input_channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700201 if (FLAG_raw && !input_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200202 input_raw_file.reset(
203 new RawFile(std::string(FLAG_input_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000204 }
kwiberg62eaacf2016-02-17 06:39:05 -0800205 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200206 new const float*[num_input_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800207 for (size_t i = 0; i < num_input_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000208 data[i] = reinterpret_cast<const float*>(msg.input_channel(i).data());
209 }
Yves Gerey665174f2018-06-19 15:03:05 +0200210 WriteFloatData(data.get(), input_samples_per_channel,
211 num_input_channels, input_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000212 input_raw_file.get());
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000213 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000214
215 if (msg.has_output_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700216 if (FLAG_raw && !output_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200217 output_raw_file.reset(
218 new RawFile(std::string(FLAG_output_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000219 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000220 WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000221 num_output_channels * output_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200222 output_wav_file.get(), output_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000223 } else if (msg.output_channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700224 if (FLAG_raw && !output_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200225 output_raw_file.reset(
226 new RawFile(std::string(FLAG_output_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000227 }
kwiberg62eaacf2016-02-17 06:39:05 -0800228 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200229 new const float*[num_output_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800230 for (size_t i = 0; i < num_output_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000231 data[i] =
232 reinterpret_cast<const float*>(msg.output_channel(i).data());
233 }
Yves Gerey665174f2018-06-19 15:03:05 +0200234 WriteFloatData(data.get(), output_samples_per_channel,
235 num_output_channels, output_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000236 output_raw_file.get());
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000237 }
238
oprypin6e09d872017-08-31 03:21:39 -0700239 if (FLAG_full) {
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200240 if (WritingCallOrderFile()) {
241 WriteCallOrderData(false /* render_call */, callorder_char_file,
242 FLAG_callorder_file);
243 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000244 if (msg.has_delay()) {
oprypin6e09d872017-08-31 03:21:39 -0700245 static FILE* delay_file = OpenFile(FLAG_delay_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000246 int32_t delay = msg.delay();
oprypin6e09d872017-08-31 03:21:39 -0700247 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200248 fprintf(delay_file, "%d\n", delay);
249 } else {
oprypin6e09d872017-08-31 03:21:39 -0700250 WriteData(&delay, sizeof(delay), delay_file, FLAG_delay_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200251 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000252 }
253
254 if (msg.has_drift()) {
oprypin6e09d872017-08-31 03:21:39 -0700255 static FILE* drift_file = OpenFile(FLAG_drift_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000256 int32_t drift = msg.drift();
oprypin6e09d872017-08-31 03:21:39 -0700257 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200258 fprintf(drift_file, "%d\n", drift);
259 } else {
oprypin6e09d872017-08-31 03:21:39 -0700260 WriteData(&drift, sizeof(drift), drift_file, FLAG_drift_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200261 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000262 }
263
264 if (msg.has_level()) {
oprypin6e09d872017-08-31 03:21:39 -0700265 static FILE* level_file = OpenFile(FLAG_level_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000266 int32_t level = msg.level();
oprypin6e09d872017-08-31 03:21:39 -0700267 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200268 fprintf(level_file, "%d\n", level);
269 } else {
oprypin6e09d872017-08-31 03:21:39 -0700270 WriteData(&level, sizeof(level), level_file, FLAG_level_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200271 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000272 }
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000273
274 if (msg.has_keypress()) {
oprypin6e09d872017-08-31 03:21:39 -0700275 static FILE* keypress_file = OpenFile(FLAG_keypress_file, "wb");
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000276 bool keypress = msg.keypress();
oprypin6e09d872017-08-31 03:21:39 -0700277 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200278 fprintf(keypress_file, "%d\n", keypress);
279 } else {
280 WriteData(&keypress, sizeof(keypress), keypress_file,
oprypin6e09d872017-08-31 03:21:39 -0700281 FLAG_keypress_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200282 }
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000283 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000284 }
Minyue13b96ba2015-10-03 00:39:14 +0200285 } else if (event_msg.type() == Event::CONFIG) {
286 if (!event_msg.has_config()) {
287 printf("Corrupt input file: Config missing.\n");
288 return 1;
289 }
290 const audioproc::Config msg = event_msg.config();
291
292 fprintf(settings_file, "APM re-config at frame: %d\n", frame_count);
293
294 PRINT_CONFIG(aec_enabled);
295 PRINT_CONFIG(aec_delay_agnostic_enabled);
296 PRINT_CONFIG(aec_drift_compensation_enabled);
297 PRINT_CONFIG(aec_extended_filter_enabled);
298 PRINT_CONFIG(aec_suppression_level);
299 PRINT_CONFIG(aecm_enabled);
300 PRINT_CONFIG(aecm_comfort_noise_enabled);
301 PRINT_CONFIG(aecm_routing_mode);
302 PRINT_CONFIG(agc_enabled);
303 PRINT_CONFIG(agc_mode);
304 PRINT_CONFIG(agc_limiter_enabled);
305 PRINT_CONFIG(noise_robust_agc_enabled);
306 PRINT_CONFIG(hpf_enabled);
307 PRINT_CONFIG(ns_enabled);
308 PRINT_CONFIG(ns_level);
309 PRINT_CONFIG(transient_suppression_enabled);
Alex Loiko5feb30e2018-04-16 13:52:32 +0200310 PRINT_CONFIG(pre_amplifier_enabled);
311 PRINT_CONFIG_FLOAT(pre_amplifier_fixed_gain_factor);
312
peah7789fe72016-04-15 01:19:44 -0700313 if (msg.has_experiments_description()) {
314 fprintf(settings_file, " experiments_description: %s\n",
315 msg.experiments_description().c_str());
316 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000317 } else if (event_msg.type() == Event::INIT) {
318 if (!event_msg.has_init()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000319 printf("Corrupt input file: Init missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000320 return 1;
321 }
322
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000323 const Init msg = event_msg.init();
324 // These should print out zeros if they're missing.
325 fprintf(settings_file, "Init at frame: %d\n", frame_count);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000326 int input_sample_rate = msg.sample_rate();
327 fprintf(settings_file, " Input sample rate: %d\n", input_sample_rate);
328 int output_sample_rate = msg.output_sample_rate();
329 fprintf(settings_file, " Output sample rate: %d\n", output_sample_rate);
330 int reverse_sample_rate = msg.reverse_sample_rate();
Yves Gerey665174f2018-06-19 15:03:05 +0200331 fprintf(settings_file, " Reverse sample rate: %d\n",
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000332 reverse_sample_rate);
333 num_input_channels = msg.num_input_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800334 fprintf(settings_file, " Input channels: %" PRIuS "\n",
335 num_input_channels);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000336 num_output_channels = msg.num_output_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800337 fprintf(settings_file, " Output channels: %" PRIuS "\n",
338 num_output_channels);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000339 num_reverse_channels = msg.num_reverse_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800340 fprintf(settings_file, " Reverse channels: %" PRIuS "\n",
341 num_reverse_channels);
Minyue Li656d6092018-08-10 15:38:52 +0200342 if (msg.has_timestamp_ms()) {
343 const int64_t timestamp = msg.timestamp_ms();
344 fprintf(settings_file, " Timestamp in millisecond: %" PRId64 "\n",
345 timestamp);
346 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000347
348 fprintf(settings_file, "\n");
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000349
350 if (reverse_sample_rate == 0) {
351 reverse_sample_rate = input_sample_rate;
352 }
353 if (output_sample_rate == 0) {
354 output_sample_rate = input_sample_rate;
355 }
356
pkasting25702cb2016-01-08 13:50:27 -0800357 reverse_samples_per_channel =
358 static_cast<size_t>(reverse_sample_rate / 100);
Yves Gerey665174f2018-06-19 15:03:05 +0200359 input_samples_per_channel = static_cast<size_t>(input_sample_rate / 100);
pkasting25702cb2016-01-08 13:50:27 -0800360 output_samples_per_channel =
361 static_cast<size_t>(output_sample_rate / 100);
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000362
oprypin6e09d872017-08-31 03:21:39 -0700363 if (!FLAG_raw) {
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000364 // The WAV files need to be reset every time, because they cant change
365 // their sample rate or number of channels.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200366 rtc::StringBuilder reverse_name;
oprypin6e09d872017-08-31 03:21:39 -0700367 reverse_name << FLAG_reverse_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200368 reverse_wav_file.reset(new WavWriter(
369 reverse_name.str(), reverse_sample_rate, num_reverse_channels));
Jonas Olsson366a50c2018-09-06 13:41:30 +0200370 rtc::StringBuilder input_name;
oprypin6e09d872017-08-31 03:21:39 -0700371 input_name << FLAG_input_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200372 input_wav_file.reset(new WavWriter(input_name.str(), input_sample_rate,
andrew@webrtc.orga3ed7132014-10-31 21:51:03 +0000373 num_input_channels));
Jonas Olsson366a50c2018-09-06 13:41:30 +0200374 rtc::StringBuilder output_name;
oprypin6e09d872017-08-31 03:21:39 -0700375 output_name << FLAG_output_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200376 output_wav_file.reset(new WavWriter(
377 output_name.str(), output_sample_rate, num_output_channels));
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200378
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200379 if (WritingCallOrderFile()) {
380 rtc::StringBuilder callorder_name;
381 callorder_name << FLAG_callorder_file << frame_count << ".char";
382 callorder_char_file = OpenFile(callorder_name.str(), "wb");
383 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000384 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000385 }
386 }
387
388 return 0;
389}
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000390
391} // namespace webrtc
392
393int main(int argc, char* argv[]) {
394 return webrtc::do_main(argc, argv);
395}