blob: 78d8a118e14d6f2632e553e103c00c8834c11f19 [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
Yves Gerey3e707812018-11-28 16:47:49 +010016#include <inttypes.h>
17#include <stdint.h>
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000018#include <stdio.h>
Yves Gerey3e707812018-11-28 16:47:49 +010019#include <stdlib.h>
kwiberg62eaacf2016-02-17 06:39:05 -080020#include <memory>
Yves Gerey3e707812018-11-28 16:47:49 +010021#include <string>
kwiberg62eaacf2016-02-17 06:39:05 -080022
Yves Gerey3e707812018-11-28 16:47:49 +010023#include "common_audio/wav_file.h"
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020024#include "modules/audio_processing/test/protobuf_utils.h"
25#include "modules/audio_processing/test/test_utils.h"
26#include "rtc_base/flags.h"
27#include "rtc_base/format_macros.h"
28#include "rtc_base/ignore_wundef.h"
Jonas Olsson366a50c2018-09-06 13:41:30 +020029#include "rtc_base/strings/string_builder.h"
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000030
kwiberg77eab702016-09-28 17:42:01 -070031RTC_PUSH_IGNORING_WUNDEF()
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020032#include "modules/audio_processing/debug.pb.h"
Yves Gerey3e707812018-11-28 16:47:49 +010033
kwiberg77eab702016-09-28 17:42:01 -070034RTC_POP_IGNORING_WUNDEF()
35
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000036// TODO(andrew): unpack more of the data.
Mirko Bonadei2dfa9982018-10-18 11:35:32 +020037WEBRTC_DEFINE_string(input_file, "input", "The name of the input stream file.");
38WEBRTC_DEFINE_string(output_file,
39 "ref_out",
40 "The name of the reference output stream file.");
41WEBRTC_DEFINE_string(reverse_file,
42 "reverse",
43 "The name of the reverse input stream file.");
44WEBRTC_DEFINE_string(delay_file, "delay.int32", "The name of the delay file.");
45WEBRTC_DEFINE_string(drift_file, "drift.int32", "The name of the drift file.");
46WEBRTC_DEFINE_string(level_file, "level.int32", "The name of the level file.");
47WEBRTC_DEFINE_string(keypress_file,
48 "keypress.bool",
49 "The name of the keypress file.");
50WEBRTC_DEFINE_string(callorder_file,
51 "callorder",
52 "The name of the render/capture call order file.");
53WEBRTC_DEFINE_string(settings_file,
54 "settings.txt",
55 "The name of the settings file.");
56WEBRTC_DEFINE_bool(full,
57 false,
58 "Unpack the full set of files (normally not needed).");
59WEBRTC_DEFINE_bool(raw, false, "Write raw data instead of a WAV file.");
60WEBRTC_DEFINE_bool(
61 text,
62 false,
63 "Write non-audio files as text files instead of binary files.");
64WEBRTC_DEFINE_bool(help, false, "Print this message.");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000065
Yves Gerey665174f2018-06-19 15:03:05 +020066#define PRINT_CONFIG(field_name) \
67 if (msg.has_##field_name()) { \
Minyue13b96ba2015-10-03 00:39:14 +020068 fprintf(settings_file, " " #field_name ": %d\n", msg.field_name()); \
69 }
70
Alex Loiko5feb30e2018-04-16 13:52:32 +020071#define PRINT_CONFIG_FLOAT(field_name) \
72 if (msg.has_##field_name()) { \
73 fprintf(settings_file, " " #field_name ": %f\n", msg.field_name()); \
74 }
75
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000076namespace webrtc {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000077
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000078using audioproc::Event;
79using audioproc::ReverseStream;
80using audioproc::Stream;
81using audioproc::Init;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000082
Sam Zackrissonf61475d2018-05-11 11:34:49 +020083namespace {
84
Yves Gerey665174f2018-06-19 15:03:05 +020085void WriteData(const void* data,
86 size_t size,
87 FILE* file,
andrew@webrtc.orga8b97372014-03-10 22:26:12 +000088 const std::string& filename) {
89 if (fwrite(data, size, 1, file) != 1) {
90 printf("Error when writing to %s\n", filename.c_str());
91 exit(1);
92 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +000093}
94
Sam Zackrissonf61475d2018-05-11 11:34:49 +020095void WriteCallOrderData(const bool render_call,
96 FILE* file,
97 const std::string& filename) {
98 const char call_type = render_call ? 'r' : 'c';
99 WriteData(&call_type, sizeof(call_type), file, filename.c_str());
100}
101
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200102bool WritingCallOrderFile() {
103 return FLAG_full;
104}
105
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200106} // namespace
107
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000108int do_main(int argc, char* argv[]) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000109 std::string program_name = argv[0];
Yves Gerey665174f2018-06-19 15:03:05 +0200110 std::string usage =
111 "Commandline tool to unpack audioproc debug files.\n"
112 "Example usage:\n" +
113 program_name + " debug_dump.pb\n";
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000114
Yves Gerey665174f2018-06-19 15:03:05 +0200115 if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help ||
116 argc < 2) {
oprypin6e09d872017-08-31 03:21:39 -0700117 printf("%s", usage.c_str());
118 if (FLAG_help) {
119 rtc::FlagList::Print(nullptr, false);
120 return 0;
121 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000122 return 1;
123 }
124
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000125 FILE* debug_file = OpenFile(argv[1], "rb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000126
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000127 Event event_msg;
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000128 int frame_count = 0;
pkasting25702cb2016-01-08 13:50:27 -0800129 size_t reverse_samples_per_channel = 0;
130 size_t input_samples_per_channel = 0;
131 size_t output_samples_per_channel = 0;
Peter Kasting69558702016-01-12 16:26:35 -0800132 size_t num_reverse_channels = 0;
133 size_t num_input_channels = 0;
134 size_t num_output_channels = 0;
kwiberg62eaacf2016-02-17 06:39:05 -0800135 std::unique_ptr<WavWriter> reverse_wav_file;
136 std::unique_ptr<WavWriter> input_wav_file;
137 std::unique_ptr<WavWriter> output_wav_file;
138 std::unique_ptr<RawFile> reverse_raw_file;
139 std::unique_ptr<RawFile> input_raw_file;
140 std::unique_ptr<RawFile> output_raw_file;
Minyue13b96ba2015-10-03 00:39:14 +0200141
Jonas Olsson366a50c2018-09-06 13:41:30 +0200142 rtc::StringBuilder callorder_raw_name;
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200143 callorder_raw_name << FLAG_callorder_file << ".char";
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200144 FILE* callorder_char_file = WritingCallOrderFile()
145 ? OpenFile(callorder_raw_name.str(), "wb")
146 : nullptr;
oprypin6e09d872017-08-31 03:21:39 -0700147 FILE* settings_file = OpenFile(FLAG_settings_file, "wb");
Minyue13b96ba2015-10-03 00:39:14 +0200148
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000149 while (ReadMessageFromFile(debug_file, &event_msg)) {
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000150 if (event_msg.type() == Event::REVERSE_STREAM) {
151 if (!event_msg.has_reverse_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000152 printf("Corrupt input file: ReverseStream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000153 return 1;
154 }
155
156 const ReverseStream msg = event_msg.reverse_stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000157 if (msg.has_data()) {
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) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000161 }
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000162 // TODO(aluebs): Replace "num_reverse_channels *
163 // reverse_samples_per_channel" with "msg.data().size() /
164 // sizeof(int16_t)" and so on when this fix in audio_processing has made
165 // it into stable: https://webrtc-codereview.appspot.com/15299004/
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000166 WriteIntData(reinterpret_cast<const int16_t*>(msg.data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000167 num_reverse_channels * reverse_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200168 reverse_wav_file.get(), reverse_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000169 } else if (msg.channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700170 if (FLAG_raw && !reverse_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200171 reverse_raw_file.reset(
172 new RawFile(std::string(FLAG_reverse_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000173 }
kwiberg62eaacf2016-02-17 06:39:05 -0800174 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200175 new const float*[num_reverse_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800176 for (size_t i = 0; i < num_reverse_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000177 data[i] = reinterpret_cast<const float*>(msg.channel(i).data());
178 }
Yves Gerey665174f2018-06-19 15:03:05 +0200179 WriteFloatData(data.get(), reverse_samples_per_channel,
180 num_reverse_channels, reverse_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000181 reverse_raw_file.get());
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000182 }
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200183 if (FLAG_full) {
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200184 if (WritingCallOrderFile()) {
185 WriteCallOrderData(true /* render_call */, callorder_char_file,
186 FLAG_callorder_file);
187 }
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200188 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000189 } else if (event_msg.type() == Event::STREAM) {
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000190 frame_count++;
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000191 if (!event_msg.has_stream()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000192 printf("Corrupt input file: Stream missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000193 return 1;
194 }
195
196 const Stream msg = event_msg.stream();
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000197 if (msg.has_input_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700198 if (FLAG_raw && !input_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200199 input_raw_file.reset(
200 new RawFile(std::string(FLAG_input_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000201 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000202 WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000203 num_input_channels * input_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200204 input_wav_file.get(), input_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000205 } else if (msg.input_channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700206 if (FLAG_raw && !input_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200207 input_raw_file.reset(
208 new RawFile(std::string(FLAG_input_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000209 }
kwiberg62eaacf2016-02-17 06:39:05 -0800210 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200211 new const float*[num_input_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800212 for (size_t i = 0; i < num_input_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000213 data[i] = reinterpret_cast<const float*>(msg.input_channel(i).data());
214 }
Yves Gerey665174f2018-06-19 15:03:05 +0200215 WriteFloatData(data.get(), input_samples_per_channel,
216 num_input_channels, input_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000217 input_raw_file.get());
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000218 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000219
220 if (msg.has_output_data()) {
oprypin6e09d872017-08-31 03:21:39 -0700221 if (FLAG_raw && !output_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200222 output_raw_file.reset(
223 new RawFile(std::string(FLAG_output_file) + ".pcm"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000224 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000225 WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()),
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000226 num_output_channels * output_samples_per_channel,
Yves Gerey665174f2018-06-19 15:03:05 +0200227 output_wav_file.get(), output_raw_file.get());
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000228 } else if (msg.output_channel_size() > 0) {
oprypin6e09d872017-08-31 03:21:39 -0700229 if (FLAG_raw && !output_raw_file) {
Yves Gerey665174f2018-06-19 15:03:05 +0200230 output_raw_file.reset(
231 new RawFile(std::string(FLAG_output_file) + ".float"));
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000232 }
kwiberg62eaacf2016-02-17 06:39:05 -0800233 std::unique_ptr<const float* []> data(
Yves Gerey665174f2018-06-19 15:03:05 +0200234 new const float*[num_output_channels]);
Peter Kasting69558702016-01-12 16:26:35 -0800235 for (size_t i = 0; i < num_output_channels; ++i) {
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000236 data[i] =
237 reinterpret_cast<const float*>(msg.output_channel(i).data());
238 }
Yves Gerey665174f2018-06-19 15:03:05 +0200239 WriteFloatData(data.get(), output_samples_per_channel,
240 num_output_channels, output_wav_file.get(),
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000241 output_raw_file.get());
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000242 }
243
oprypin6e09d872017-08-31 03:21:39 -0700244 if (FLAG_full) {
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200245 if (WritingCallOrderFile()) {
246 WriteCallOrderData(false /* render_call */, callorder_char_file,
247 FLAG_callorder_file);
248 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000249 if (msg.has_delay()) {
oprypin6e09d872017-08-31 03:21:39 -0700250 static FILE* delay_file = OpenFile(FLAG_delay_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000251 int32_t delay = msg.delay();
oprypin6e09d872017-08-31 03:21:39 -0700252 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200253 fprintf(delay_file, "%d\n", delay);
254 } else {
oprypin6e09d872017-08-31 03:21:39 -0700255 WriteData(&delay, sizeof(delay), delay_file, FLAG_delay_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200256 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000257 }
258
259 if (msg.has_drift()) {
oprypin6e09d872017-08-31 03:21:39 -0700260 static FILE* drift_file = OpenFile(FLAG_drift_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000261 int32_t drift = msg.drift();
oprypin6e09d872017-08-31 03:21:39 -0700262 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200263 fprintf(drift_file, "%d\n", drift);
264 } else {
oprypin6e09d872017-08-31 03:21:39 -0700265 WriteData(&drift, sizeof(drift), drift_file, FLAG_drift_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200266 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000267 }
268
269 if (msg.has_level()) {
oprypin6e09d872017-08-31 03:21:39 -0700270 static FILE* level_file = OpenFile(FLAG_level_file, "wb");
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000271 int32_t level = msg.level();
oprypin6e09d872017-08-31 03:21:39 -0700272 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200273 fprintf(level_file, "%d\n", level);
274 } else {
oprypin6e09d872017-08-31 03:21:39 -0700275 WriteData(&level, sizeof(level), level_file, FLAG_level_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200276 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000277 }
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000278
279 if (msg.has_keypress()) {
oprypin6e09d872017-08-31 03:21:39 -0700280 static FILE* keypress_file = OpenFile(FLAG_keypress_file, "wb");
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000281 bool keypress = msg.keypress();
oprypin6e09d872017-08-31 03:21:39 -0700282 if (FLAG_text) {
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200283 fprintf(keypress_file, "%d\n", keypress);
284 } else {
285 WriteData(&keypress, sizeof(keypress), keypress_file,
oprypin6e09d872017-08-31 03:21:39 -0700286 FLAG_keypress_file);
Bjorn Volcker40a6d592015-05-06 10:51:34 +0200287 }
andrew@webrtc.orgce8e0772014-02-12 15:28:30 +0000288 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000289 }
Minyue13b96ba2015-10-03 00:39:14 +0200290 } else if (event_msg.type() == Event::CONFIG) {
291 if (!event_msg.has_config()) {
292 printf("Corrupt input file: Config missing.\n");
293 return 1;
294 }
295 const audioproc::Config msg = event_msg.config();
296
297 fprintf(settings_file, "APM re-config at frame: %d\n", frame_count);
298
299 PRINT_CONFIG(aec_enabled);
300 PRINT_CONFIG(aec_delay_agnostic_enabled);
301 PRINT_CONFIG(aec_drift_compensation_enabled);
302 PRINT_CONFIG(aec_extended_filter_enabled);
303 PRINT_CONFIG(aec_suppression_level);
304 PRINT_CONFIG(aecm_enabled);
305 PRINT_CONFIG(aecm_comfort_noise_enabled);
306 PRINT_CONFIG(aecm_routing_mode);
307 PRINT_CONFIG(agc_enabled);
308 PRINT_CONFIG(agc_mode);
309 PRINT_CONFIG(agc_limiter_enabled);
310 PRINT_CONFIG(noise_robust_agc_enabled);
311 PRINT_CONFIG(hpf_enabled);
312 PRINT_CONFIG(ns_enabled);
313 PRINT_CONFIG(ns_level);
314 PRINT_CONFIG(transient_suppression_enabled);
Alex Loiko5feb30e2018-04-16 13:52:32 +0200315 PRINT_CONFIG(pre_amplifier_enabled);
316 PRINT_CONFIG_FLOAT(pre_amplifier_fixed_gain_factor);
317
peah7789fe72016-04-15 01:19:44 -0700318 if (msg.has_experiments_description()) {
319 fprintf(settings_file, " experiments_description: %s\n",
320 msg.experiments_description().c_str());
321 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000322 } else if (event_msg.type() == Event::INIT) {
323 if (!event_msg.has_init()) {
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000324 printf("Corrupt input file: Init missing.\n");
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000325 return 1;
326 }
327
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000328 const Init msg = event_msg.init();
329 // These should print out zeros if they're missing.
330 fprintf(settings_file, "Init at frame: %d\n", frame_count);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000331 int input_sample_rate = msg.sample_rate();
332 fprintf(settings_file, " Input sample rate: %d\n", input_sample_rate);
333 int output_sample_rate = msg.output_sample_rate();
334 fprintf(settings_file, " Output sample rate: %d\n", output_sample_rate);
335 int reverse_sample_rate = msg.reverse_sample_rate();
Yves Gerey665174f2018-06-19 15:03:05 +0200336 fprintf(settings_file, " Reverse sample rate: %d\n",
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000337 reverse_sample_rate);
338 num_input_channels = msg.num_input_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800339 fprintf(settings_file, " Input channels: %" PRIuS "\n",
340 num_input_channels);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000341 num_output_channels = msg.num_output_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800342 fprintf(settings_file, " Output channels: %" PRIuS "\n",
343 num_output_channels);
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000344 num_reverse_channels = msg.num_reverse_channels();
Peter Kasting69558702016-01-12 16:26:35 -0800345 fprintf(settings_file, " Reverse channels: %" PRIuS "\n",
346 num_reverse_channels);
Minyue Li656d6092018-08-10 15:38:52 +0200347 if (msg.has_timestamp_ms()) {
348 const int64_t timestamp = msg.timestamp_ms();
349 fprintf(settings_file, " Timestamp in millisecond: %" PRId64 "\n",
350 timestamp);
351 }
andrew@webrtc.orgcd824382011-11-11 19:13:36 +0000352
353 fprintf(settings_file, "\n");
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000354
355 if (reverse_sample_rate == 0) {
356 reverse_sample_rate = input_sample_rate;
357 }
358 if (output_sample_rate == 0) {
359 output_sample_rate = input_sample_rate;
360 }
361
pkasting25702cb2016-01-08 13:50:27 -0800362 reverse_samples_per_channel =
363 static_cast<size_t>(reverse_sample_rate / 100);
Yves Gerey665174f2018-06-19 15:03:05 +0200364 input_samples_per_channel = static_cast<size_t>(input_sample_rate / 100);
pkasting25702cb2016-01-08 13:50:27 -0800365 output_samples_per_channel =
366 static_cast<size_t>(output_sample_rate / 100);
aluebs@webrtc.orgbac07262014-09-03 13:39:01 +0000367
oprypin6e09d872017-08-31 03:21:39 -0700368 if (!FLAG_raw) {
aluebs@webrtc.org021e76f2014-09-04 18:12:00 +0000369 // The WAV files need to be reset every time, because they cant change
370 // their sample rate or number of channels.
Jonas Olsson366a50c2018-09-06 13:41:30 +0200371 rtc::StringBuilder reverse_name;
oprypin6e09d872017-08-31 03:21:39 -0700372 reverse_name << FLAG_reverse_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200373 reverse_wav_file.reset(new WavWriter(
374 reverse_name.str(), reverse_sample_rate, num_reverse_channels));
Jonas Olsson366a50c2018-09-06 13:41:30 +0200375 rtc::StringBuilder input_name;
oprypin6e09d872017-08-31 03:21:39 -0700376 input_name << FLAG_input_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200377 input_wav_file.reset(new WavWriter(input_name.str(), input_sample_rate,
andrew@webrtc.orga3ed7132014-10-31 21:51:03 +0000378 num_input_channels));
Jonas Olsson366a50c2018-09-06 13:41:30 +0200379 rtc::StringBuilder output_name;
oprypin6e09d872017-08-31 03:21:39 -0700380 output_name << FLAG_output_file << frame_count << ".wav";
Yves Gerey665174f2018-06-19 15:03:05 +0200381 output_wav_file.reset(new WavWriter(
382 output_name.str(), output_sample_rate, num_output_channels));
Sam Zackrissonf61475d2018-05-11 11:34:49 +0200383
Per Åhgrenc1bfe1a2018-09-21 16:23:50 +0200384 if (WritingCallOrderFile()) {
385 rtc::StringBuilder callorder_name;
386 callorder_name << FLAG_callorder_file << frame_count << ".char";
387 callorder_char_file = OpenFile(callorder_name.str(), "wb");
388 }
aluebs@webrtc.org841f58f2014-09-02 07:51:51 +0000389 }
andrew@webrtc.orgcb181212011-10-26 00:27:17 +0000390 }
391 }
392
393 return 0;
394}
andrew@webrtc.orga8b97372014-03-10 22:26:12 +0000395
396} // namespace webrtc
397
398int main(int argc, char* argv[]) {
399 return webrtc::do_main(argc, argv);
400}