blob: af8bf3187a7cb2a6f5c17003969e7d9d29f6b8f5 [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.
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +000032DEFINE_string(input_file, "input", "The name of the input stream file.");
Yves Gerey665174f2018-06-19 15:03:05 +020033DEFINE_string(output_file,
34 "ref_out",
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000035 "The name of the reference output stream file.");
Yves Gerey665174f2018-06-19 15:03:05 +020036DEFINE_string(reverse_file,
37 "reverse",
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000038 "The name of the reverse input stream file.");
39DEFINE_string(delay_file, "delay.int32", "The name of the delay file.");
40DEFINE_string(drift_file, "drift.int32", "The name of the drift file.");
41DEFINE_string(level_file, "level.int32", "The name of the level file.");
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +000042DEFINE_string(keypress_file, "keypress.bool", "The name of the keypress file.");
Sam Zackrissonf61475d2018-05-11 11:34:49 +020043DEFINE_string(callorder_file,
44 "callorder",
45 "The name of the render/capture call order file.");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +000046DEFINE_string(settings_file, "settings.txt", "The name of the settings file.");
Yves Gerey665174f2018-06-19 15:03:05 +020047DEFINE_bool(full, false, "Unpack the full set of files (normally not needed).");
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +000048DEFINE_bool(raw, false, "Write raw data instead of a WAV file.");
Bjorn Volcker40a6d592015-05-06 10:51:34 +020049DEFINE_bool(text,
50 false,
51 "Write non-audio files as text files instead of binary files.");
oprypin6e09d872017-08-31 03:21:39 -070052DEFINE_bool(help, false, "Print this message.");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000053
Yves Gerey665174f2018-06-19 15:03:05 +020054#define PRINT_CONFIG(field_name) \
55 if (msg.has_##field_name()) { \
Minyue13b96ba2015-10-03 00:39:14 +020056 fprintf(settings_file, " " #field_name ": %d\n", msg.field_name()); \
57 }
58
Alex Loiko5feb30e2018-04-16 13:52:32 +020059#define PRINT_CONFIG_FLOAT(field_name) \
60 if (msg.has_##field_name()) { \
61 fprintf(settings_file, " " #field_name ": %f\n", msg.field_name()); \
62 }
63
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000064namespace webrtc {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000065
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000066using audioproc::Event;
67using audioproc::ReverseStream;
68using audioproc::Stream;
69using audioproc::Init;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000070
Sam Zackrissonf61475d2018-05-11 11:34:49 +020071namespace {
72
Yves Gerey665174f2018-06-19 15:03:05 +020073void WriteData(const void* data,
74 size_t size,
75 FILE* file,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000076 const std::string& filename) {
77 if (fwrite(data, size, 1, file) != 1) {
78 printf("Error when writing to %s\n", filename.c_str());
79 exit(1);
80 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000081}
82
Sam Zackrissonf61475d2018-05-11 11:34:49 +020083void WriteCallOrderData(const bool render_call,
84 FILE* file,
85 const std::string& filename) {
86 const char call_type = render_call ? 'r' : 'c';
87 WriteData(&call_type, sizeof(call_type), file, filename.c_str());
88}
89
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +020090bool WritingCallOrderFile() {
91 return FLAG_full;
92}
93
Sam Zackrissonf61475d2018-05-11 11:34:49 +020094} // namespace
95
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000096int do_main(int argc, char* argv[]) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000097 std::string program_name = argv[0];
Yves Gerey665174f2018-06-19 15:03:05 +020098 std::string usage =
99 "Commandline tool to unpack audioproc debug files.\n"
100 "Example usage:\n" +
101 program_name + " debug_dump.pb\n";
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000102
Yves Gerey665174f2018-06-19 15:03:05 +0200103 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
104 argc < 2) {
oprypin6e09d872017-08-31 03:21:39 -0700105 printf("%s", usage.c_str());
106 if (FLAG_help) {
107 rtc::FlagList::Print(nullptr, false);
108 return 0;
109 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000110 return 1;
111 }
112
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000113 FILE* debug_file = OpenFile(argv[1], "rb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000114
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000115 Event event_msg;
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000116 int frame_count = 0;
pkasting25702cb2016-01-08 13:50:27 -0800117 size_t reverse_samples_per_channel = 0;
118 size_t input_samples_per_channel = 0;
119 size_t output_samples_per_channel = 0;
Peter Kasting69558702016-01-12 16:26:35 -0800120 size_t num_reverse_channels = 0;
121 size_t num_input_channels = 0;
122 size_t num_output_channels = 0;
kwiberg62eaacf2016-02-17 06:39:05 -0800123 std::unique_ptr<WavWriter> reverse_wav_file;
124 std::unique_ptr<WavWriter> input_wav_file;
125 std::unique_ptr<WavWriter> output_wav_file;
126 std::unique_ptr<RawFile> reverse_raw_file;
127 std::unique_ptr<RawFile> input_raw_file;
128 std::unique_ptr<RawFile> output_raw_file;
Minyue13b96ba2015-10-03 00:39:14 +0200129
Jonas Olsson366a50c2018-09-06 13:41:30 +0200130 rtc::StringBuilder callorder_raw_name;
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200131 callorder_raw_name << FLAG_callorder_file << ".char";
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200132 FILE* callorder_char_file = WritingCallOrderFile()
133 ? OpenFile(callorder_raw_name.str(), "wb")
134 : nullptr;
oprypin6e09d872017-08-31 03:21:39 -0700135 FILE* settings_file = OpenFile(FLAG_settings_file, "wb");
Minyue13b96ba2015-10-03 00:39:14 +0200136
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000137 while (ReadMessageFromFile(debug_file, &event_msg)) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000138 if (event_msg.type() == Event::REVERSE_STREAM) {
139 if (!event_msg.has_reverse_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000140 printf("Corrupt input file: ReverseStream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000141 return 1;
142 }
143
144 const ReverseStream msg = event_msg.reverse_stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000145 if (msg.has_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700146 if (FLAG_raw && !reverse_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200147 reverse_raw_file.reset(
148 new RawFile(std::string(FLAG_reverse_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000149 }
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000150 // TODO(aluebs): Replace "num_reverse_channels *
151 // reverse_samples_per_channel" with "msg.data().size() /
152 // sizeof(int16_t)" and so on when this fix in audio_processing has made
153 // it into stable: https://webrtc-codereview.appspot.com/15299004/
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000154 WriteIntData(reinterpret_cast<const int16_t*>(msg.data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000155 num_reverse_channels * reverse_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200156 reverse_wav_file.get(), reverse_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000157 } else if (msg.channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700158 if (FLAG_raw && !reverse_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200159 reverse_raw_file.reset(
160 new RawFile(std::string(FLAG_reverse_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000161 }
kwiberg62eaacf2016-02-17 06:39:05 -0800162 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200163 new const float*[num_reverse_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800164 for (size_t i = 0; i < num_reverse_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000165 data[i] = reinterpret_cast<const float*>(msg.channel(i).data());
166 }
Yves Gerey665174f2018-06-19 15:03:05 +0200167 WriteFloatData(data.get(), reverse_samples_per_channel,
168 num_reverse_channels, reverse_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000169 reverse_raw_file.get());
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000170 }
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200171 if (FLAG_full) {
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200172 if (WritingCallOrderFile()) {
173 WriteCallOrderData(true /* render_call */, callorder_char_file,
174 FLAG_callorder_file);
175 }
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200176 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000177 } else if (event_msg.type() == Event::STREAM) {
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000178 frame_count++;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000179 if (!event_msg.has_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000180 printf("Corrupt input file: Stream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000181 return 1;
182 }
183
184 const Stream msg = event_msg.stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000185 if (msg.has_input_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700186 if (FLAG_raw && !input_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200187 input_raw_file.reset(
188 new RawFile(std::string(FLAG_input_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000189 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000190 WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000191 num_input_channels * input_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200192 input_wav_file.get(), input_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000193 } else if (msg.input_channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700194 if (FLAG_raw && !input_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200195 input_raw_file.reset(
196 new RawFile(std::string(FLAG_input_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000197 }
kwiberg62eaacf2016-02-17 06:39:05 -0800198 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200199 new const float*[num_input_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800200 for (size_t i = 0; i < num_input_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000201 data[i] = reinterpret_cast<const float*>(msg.input_channel(i).data());
202 }
Yves Gerey665174f2018-06-19 15:03:05 +0200203 WriteFloatData(data.get(), input_samples_per_channel,
204 num_input_channels, input_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000205 input_raw_file.get());
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000206 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000207
208 if (msg.has_output_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700209 if (FLAG_raw && !output_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200210 output_raw_file.reset(
211 new RawFile(std::string(FLAG_output_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000212 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000213 WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000214 num_output_channels * output_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200215 output_wav_file.get(), output_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000216 } else if (msg.output_channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700217 if (FLAG_raw && !output_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200218 output_raw_file.reset(
219 new RawFile(std::string(FLAG_output_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000220 }
kwiberg62eaacf2016-02-17 06:39:05 -0800221 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200222 new const float*[num_output_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800223 for (size_t i = 0; i < num_output_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000224 data[i] =
225 reinterpret_cast<const float*>(msg.output_channel(i).data());
226 }
Yves Gerey665174f2018-06-19 15:03:05 +0200227 WriteFloatData(data.get(), output_samples_per_channel,
228 num_output_channels, output_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000229 output_raw_file.get());
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000230 }
231
oprypin6e09d872017-08-31 03:21:39 -0700232 if (FLAG_full) {
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200233 if (WritingCallOrderFile()) {
234 WriteCallOrderData(false /* render_call */, callorder_char_file,
235 FLAG_callorder_file);
236 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000237 if (msg.has_delay()) {
oprypin6e09d872017-08-31 03:21:39 -0700238 static FILE* delay_file = OpenFile(FLAG_delay_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000239 int32_t delay = msg.delay();
oprypin6e09d872017-08-31 03:21:39 -0700240 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200241 fprintf(delay_file, "%d\n", delay);
242 } else {
oprypin6e09d872017-08-31 03:21:39 -0700243 WriteData(&delay, sizeof(delay), delay_file, FLAG_delay_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200244 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000245 }
246
247 if (msg.has_drift()) {
oprypin6e09d872017-08-31 03:21:39 -0700248 static FILE* drift_file = OpenFile(FLAG_drift_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000249 int32_t drift = msg.drift();
oprypin6e09d872017-08-31 03:21:39 -0700250 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200251 fprintf(drift_file, "%d\n", drift);
252 } else {
oprypin6e09d872017-08-31 03:21:39 -0700253 WriteData(&drift, sizeof(drift), drift_file, FLAG_drift_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200254 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000255 }
256
257 if (msg.has_level()) {
oprypin6e09d872017-08-31 03:21:39 -0700258 static FILE* level_file = OpenFile(FLAG_level_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000259 int32_t level = msg.level();
oprypin6e09d872017-08-31 03:21:39 -0700260 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200261 fprintf(level_file, "%d\n", level);
262 } else {
oprypin6e09d872017-08-31 03:21:39 -0700263 WriteData(&level, sizeof(level), level_file, FLAG_level_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200264 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000265 }
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000266
267 if (msg.has_keypress()) {
oprypin6e09d872017-08-31 03:21:39 -0700268 static FILE* keypress_file = OpenFile(FLAG_keypress_file, "wb");
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000269 bool keypress = msg.keypress();
oprypin6e09d872017-08-31 03:21:39 -0700270 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200271 fprintf(keypress_file, "%d\n", keypress);
272 } else {
273 WriteData(&keypress, sizeof(keypress), keypress_file,
oprypin6e09d872017-08-31 03:21:39 -0700274 FLAG_keypress_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200275 }
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000276 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000277 }
Minyue13b96ba2015-10-03 00:39:14 +0200278 } else if (event_msg.type() == Event::CONFIG) {
279 if (!event_msg.has_config()) {
280 printf("Corrupt input file: Config missing.\n");
281 return 1;
282 }
283 const audioproc::Config msg = event_msg.config();
284
285 fprintf(settings_file, "APM re-config at frame: %d\n", frame_count);
286
287 PRINT_CONFIG(aec_enabled);
288 PRINT_CONFIG(aec_delay_agnostic_enabled);
289 PRINT_CONFIG(aec_drift_compensation_enabled);
290 PRINT_CONFIG(aec_extended_filter_enabled);
291 PRINT_CONFIG(aec_suppression_level);
292 PRINT_CONFIG(aecm_enabled);
293 PRINT_CONFIG(aecm_comfort_noise_enabled);
294 PRINT_CONFIG(aecm_routing_mode);
295 PRINT_CONFIG(agc_enabled);
296 PRINT_CONFIG(agc_mode);
297 PRINT_CONFIG(agc_limiter_enabled);
298 PRINT_CONFIG(noise_robust_agc_enabled);
299 PRINT_CONFIG(hpf_enabled);
300 PRINT_CONFIG(ns_enabled);
301 PRINT_CONFIG(ns_level);
302 PRINT_CONFIG(transient_suppression_enabled);
Alex Loiko5feb30e2018-04-16 13:52:32 +0200303 PRINT_CONFIG(pre_amplifier_enabled);
304 PRINT_CONFIG_FLOAT(pre_amplifier_fixed_gain_factor);
305
peah7789fe72016-04-15 01:19:44 -0700306 if (msg.has_experiments_description()) {
307 fprintf(settings_file, " experiments_description: %s\n",
308 msg.experiments_description().c_str());
309 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000310 } else if (event_msg.type() == Event::INIT) {
311 if (!event_msg.has_init()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000312 printf("Corrupt input file: Init missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000313 return 1;
314 }
315
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000316 const Init msg = event_msg.init();
317 // These should print out zeros if they're missing.
318 fprintf(settings_file, "Init at frame: %d\n", frame_count);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000319 int input_sample_rate = msg.sample_rate();
320 fprintf(settings_file, " Input sample rate: %d\n", input_sample_rate);
321 int output_sample_rate = msg.output_sample_rate();
322 fprintf(settings_file, " Output sample rate: %d\n", output_sample_rate);
323 int reverse_sample_rate = msg.reverse_sample_rate();
Yves Gerey665174f2018-06-19 15:03:05 +0200324 fprintf(settings_file, " Reverse sample rate: %d\n",
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000325 reverse_sample_rate);
326 num_input_channels = msg.num_input_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800327 fprintf(settings_file, " Input channels: %" PRIuS "\n",
328 num_input_channels);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000329 num_output_channels = msg.num_output_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800330 fprintf(settings_file, " Output channels: %" PRIuS "\n",
331 num_output_channels);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000332 num_reverse_channels = msg.num_reverse_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800333 fprintf(settings_file, " Reverse channels: %" PRIuS "\n",
334 num_reverse_channels);
Minyue Li656d6092018-08-10 15:38:52 +0200335 if (msg.has_timestamp_ms()) {
336 const int64_t timestamp = msg.timestamp_ms();
337 fprintf(settings_file, " Timestamp in millisecond: %" PRId64 "\n",
338 timestamp);
339 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000340
341 fprintf(settings_file, "\n");
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000342
343 if (reverse_sample_rate == 0) {
344 reverse_sample_rate = input_sample_rate;
345 }
346 if (output_sample_rate == 0) {
347 output_sample_rate = input_sample_rate;
348 }
349
pkasting25702cb2016-01-08 13:50:27 -0800350 reverse_samples_per_channel =
351 static_cast<size_t>(reverse_sample_rate / 100);
Yves Gerey665174f2018-06-19 15:03:05 +0200352 input_samples_per_channel = static_cast<size_t>(input_sample_rate / 100);
pkasting25702cb2016-01-08 13:50:27 -0800353 output_samples_per_channel =
354 static_cast<size_t>(output_sample_rate / 100);
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000355
oprypin6e09d872017-08-31 03:21:39 -0700356 if (!FLAG_raw) {
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000357 // The WAV files need to be reset every time, because they cant change
358 // their sample rate or number of channels.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200359 rtc::StringBuilder reverse_name;
oprypin6e09d872017-08-31 03:21:39 -0700360 reverse_name << FLAG_reverse_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200361 reverse_wav_file.reset(new WavWriter(
362 reverse_name.str(), reverse_sample_rate, num_reverse_channels));
Jonas Olsson366a50c2018-09-06 13:41:30 +0200363 rtc::StringBuilder input_name;
oprypin6e09d872017-08-31 03:21:39 -0700364 input_name << FLAG_input_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200365 input_wav_file.reset(new WavWriter(input_name.str(), input_sample_rate,
andrew@webrtc.orga3ed7132014-10-31 21:51:03 +0000366 num_input_channels));
Jonas Olsson366a50c2018-09-06 13:41:30 +0200367 rtc::StringBuilder output_name;
oprypin6e09d872017-08-31 03:21:39 -0700368 output_name << FLAG_output_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200369 output_wav_file.reset(new WavWriter(
370 output_name.str(), output_sample_rate, num_output_channels));
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200371
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200372 if (WritingCallOrderFile()) {
373 rtc::StringBuilder callorder_name;
374 callorder_name << FLAG_callorder_file << frame_count << ".char";
375 callorder_char_file = OpenFile(callorder_name.str(), "wb");
376 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000377 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000378 }
379 }
380
381 return 0;
382}
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000383
384} // namespace webrtc
385
386int main(int argc, char* argv[]) {
387 return webrtc::do_main(argc, argv);
388}