andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 1 | /* |
| 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 | |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 18 | #include <memory> |
| 19 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 20 | #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 Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 25 | #include "rtc_base/strings/string_builder.h" |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 26 | |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 27 | RTC_PUSH_IGNORING_WUNDEF() |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 28 | #include "modules/audio_processing/debug.pb.h" |
kwiberg | 77eab70 | 2016-09-28 17:42:01 -0700 | [diff] [blame] | 29 | RTC_POP_IGNORING_WUNDEF() |
| 30 | |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 31 | // TODO(andrew): unpack more of the data. |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 32 | DEFINE_string(input_file, "input", "The name of the input stream file."); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 33 | DEFINE_string(output_file, |
| 34 | "ref_out", |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 35 | "The name of the reference output stream file."); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 36 | DEFINE_string(reverse_file, |
| 37 | "reverse", |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 38 | "The name of the reverse input stream file."); |
| 39 | DEFINE_string(delay_file, "delay.int32", "The name of the delay file."); |
| 40 | DEFINE_string(drift_file, "drift.int32", "The name of the drift file."); |
| 41 | DEFINE_string(level_file, "level.int32", "The name of the level file."); |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 42 | DEFINE_string(keypress_file, "keypress.bool", "The name of the keypress file."); |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 43 | DEFINE_string(callorder_file, |
| 44 | "callorder", |
| 45 | "The name of the render/capture call order file."); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 46 | DEFINE_string(settings_file, "settings.txt", "The name of the settings file."); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 47 | DEFINE_bool(full, false, "Unpack the full set of files (normally not needed)."); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 48 | DEFINE_bool(raw, false, "Write raw data instead of a WAV file."); |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 49 | DEFINE_bool(text, |
| 50 | false, |
| 51 | "Write non-audio files as text files instead of binary files."); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 52 | DEFINE_bool(help, false, "Print this message."); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 53 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 54 | #define PRINT_CONFIG(field_name) \ |
| 55 | if (msg.has_##field_name()) { \ |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 56 | fprintf(settings_file, " " #field_name ": %d\n", msg.field_name()); \ |
| 57 | } |
| 58 | |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 59 | #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.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 64 | namespace webrtc { |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 65 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 66 | using audioproc::Event; |
| 67 | using audioproc::ReverseStream; |
| 68 | using audioproc::Stream; |
| 69 | using audioproc::Init; |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 70 | |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 71 | namespace { |
| 72 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 73 | void WriteData(const void* data, |
| 74 | size_t size, |
| 75 | FILE* file, |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 76 | 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.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 83 | void 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 | |
| 90 | } // namespace |
| 91 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 92 | int do_main(int argc, char* argv[]) { |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 93 | std::string program_name = argv[0]; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 94 | std::string usage = |
| 95 | "Commandline tool to unpack audioproc debug files.\n" |
| 96 | "Example usage:\n" + |
| 97 | program_name + " debug_dump.pb\n"; |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 98 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 99 | if (rtc::FlagList::SetFlagsFromCommandLine(&argc, argv, true) || FLAG_help || |
| 100 | argc < 2) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 101 | printf("%s", usage.c_str()); |
| 102 | if (FLAG_help) { |
| 103 | rtc::FlagList::Print(nullptr, false); |
| 104 | return 0; |
| 105 | } |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 106 | return 1; |
| 107 | } |
| 108 | |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 109 | FILE* debug_file = OpenFile(argv[1], "rb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 110 | |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 111 | Event event_msg; |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 112 | int frame_count = 0; |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 113 | size_t reverse_samples_per_channel = 0; |
| 114 | size_t input_samples_per_channel = 0; |
| 115 | size_t output_samples_per_channel = 0; |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 116 | size_t num_reverse_channels = 0; |
| 117 | size_t num_input_channels = 0; |
| 118 | size_t num_output_channels = 0; |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 119 | std::unique_ptr<WavWriter> reverse_wav_file; |
| 120 | std::unique_ptr<WavWriter> input_wav_file; |
| 121 | std::unique_ptr<WavWriter> output_wav_file; |
| 122 | std::unique_ptr<RawFile> reverse_raw_file; |
| 123 | std::unique_ptr<RawFile> input_raw_file; |
| 124 | std::unique_ptr<RawFile> output_raw_file; |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 125 | |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 126 | rtc::StringBuilder callorder_raw_name; |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 127 | callorder_raw_name << FLAG_callorder_file << ".char"; |
| 128 | FILE* callorder_char_file = OpenFile(callorder_raw_name.str(), "wb"); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 129 | FILE* settings_file = OpenFile(FLAG_settings_file, "wb"); |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 130 | |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 131 | while (ReadMessageFromFile(debug_file, &event_msg)) { |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 132 | if (event_msg.type() == Event::REVERSE_STREAM) { |
| 133 | if (!event_msg.has_reverse_stream()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 134 | printf("Corrupt input file: ReverseStream missing.\n"); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 135 | return 1; |
| 136 | } |
| 137 | |
| 138 | const ReverseStream msg = event_msg.reverse_stream(); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 139 | if (msg.has_data()) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 140 | if (FLAG_raw && !reverse_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 141 | reverse_raw_file.reset( |
| 142 | new RawFile(std::string(FLAG_reverse_file) + ".pcm")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 143 | } |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 144 | // TODO(aluebs): Replace "num_reverse_channels * |
| 145 | // reverse_samples_per_channel" with "msg.data().size() / |
| 146 | // sizeof(int16_t)" and so on when this fix in audio_processing has made |
| 147 | // it into stable: https://webrtc-codereview.appspot.com/15299004/ |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 148 | WriteIntData(reinterpret_cast<const int16_t*>(msg.data().data()), |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 149 | num_reverse_channels * reverse_samples_per_channel, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 150 | reverse_wav_file.get(), reverse_raw_file.get()); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 151 | } else if (msg.channel_size() > 0) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 152 | if (FLAG_raw && !reverse_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 153 | reverse_raw_file.reset( |
| 154 | new RawFile(std::string(FLAG_reverse_file) + ".float")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 155 | } |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 156 | std::unique_ptr<const float* []> data( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 157 | new const float*[num_reverse_channels]); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 158 | for (size_t i = 0; i < num_reverse_channels; ++i) { |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 159 | data[i] = reinterpret_cast<const float*>(msg.channel(i).data()); |
| 160 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 161 | WriteFloatData(data.get(), reverse_samples_per_channel, |
| 162 | num_reverse_channels, reverse_wav_file.get(), |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 163 | reverse_raw_file.get()); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 164 | } |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 165 | if (FLAG_full) { |
| 166 | WriteCallOrderData(true /* render_call */, callorder_char_file, |
| 167 | FLAG_callorder_file); |
| 168 | } |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 169 | } else if (event_msg.type() == Event::STREAM) { |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 170 | frame_count++; |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 171 | if (!event_msg.has_stream()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 172 | printf("Corrupt input file: Stream missing.\n"); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 173 | return 1; |
| 174 | } |
| 175 | |
| 176 | const Stream msg = event_msg.stream(); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 177 | if (msg.has_input_data()) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 178 | if (FLAG_raw && !input_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 179 | input_raw_file.reset( |
| 180 | new RawFile(std::string(FLAG_input_file) + ".pcm")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 181 | } |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 182 | WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()), |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 183 | num_input_channels * input_samples_per_channel, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 184 | input_wav_file.get(), input_raw_file.get()); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 185 | } else if (msg.input_channel_size() > 0) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 186 | if (FLAG_raw && !input_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 187 | input_raw_file.reset( |
| 188 | new RawFile(std::string(FLAG_input_file) + ".float")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 189 | } |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 190 | std::unique_ptr<const float* []> data( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 191 | new const float*[num_input_channels]); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 192 | for (size_t i = 0; i < num_input_channels; ++i) { |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 193 | data[i] = reinterpret_cast<const float*>(msg.input_channel(i).data()); |
| 194 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 195 | WriteFloatData(data.get(), input_samples_per_channel, |
| 196 | num_input_channels, input_wav_file.get(), |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 197 | input_raw_file.get()); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 198 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 199 | |
| 200 | if (msg.has_output_data()) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 201 | if (FLAG_raw && !output_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 202 | output_raw_file.reset( |
| 203 | new RawFile(std::string(FLAG_output_file) + ".pcm")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 204 | } |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 205 | WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()), |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 206 | num_output_channels * output_samples_per_channel, |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 207 | output_wav_file.get(), output_raw_file.get()); |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 208 | } else if (msg.output_channel_size() > 0) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 209 | if (FLAG_raw && !output_raw_file) { |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 210 | output_raw_file.reset( |
| 211 | new RawFile(std::string(FLAG_output_file) + ".float")); |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 212 | } |
kwiberg | 62eaacf | 2016-02-17 06:39:05 -0800 | [diff] [blame] | 213 | std::unique_ptr<const float* []> data( |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 214 | new const float*[num_output_channels]); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 215 | for (size_t i = 0; i < num_output_channels; ++i) { |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 216 | data[i] = |
| 217 | reinterpret_cast<const float*>(msg.output_channel(i).data()); |
| 218 | } |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 219 | WriteFloatData(data.get(), output_samples_per_channel, |
| 220 | num_output_channels, output_wav_file.get(), |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 221 | output_raw_file.get()); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 222 | } |
| 223 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 224 | if (FLAG_full) { |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 225 | WriteCallOrderData(false /* render_call */, callorder_char_file, |
| 226 | FLAG_callorder_file); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 227 | if (msg.has_delay()) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 228 | static FILE* delay_file = OpenFile(FLAG_delay_file, "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 229 | int32_t delay = msg.delay(); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 230 | if (FLAG_text) { |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 231 | fprintf(delay_file, "%d\n", delay); |
| 232 | } else { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 233 | WriteData(&delay, sizeof(delay), delay_file, FLAG_delay_file); |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 234 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | if (msg.has_drift()) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 238 | static FILE* drift_file = OpenFile(FLAG_drift_file, "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 239 | int32_t drift = msg.drift(); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 240 | if (FLAG_text) { |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 241 | fprintf(drift_file, "%d\n", drift); |
| 242 | } else { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 243 | WriteData(&drift, sizeof(drift), drift_file, FLAG_drift_file); |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 244 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 245 | } |
| 246 | |
| 247 | if (msg.has_level()) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 248 | static FILE* level_file = OpenFile(FLAG_level_file, "wb"); |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 249 | int32_t level = msg.level(); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 250 | if (FLAG_text) { |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 251 | fprintf(level_file, "%d\n", level); |
| 252 | } else { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 253 | WriteData(&level, sizeof(level), level_file, FLAG_level_file); |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 254 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 255 | } |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 256 | |
| 257 | if (msg.has_keypress()) { |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 258 | static FILE* keypress_file = OpenFile(FLAG_keypress_file, "wb"); |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 259 | bool keypress = msg.keypress(); |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 260 | if (FLAG_text) { |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 261 | fprintf(keypress_file, "%d\n", keypress); |
| 262 | } else { |
| 263 | WriteData(&keypress, sizeof(keypress), keypress_file, |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 264 | FLAG_keypress_file); |
Bjorn Volcker | 40a6d59 | 2015-05-06 10:51:34 +0200 | [diff] [blame] | 265 | } |
andrew@webrtc.org | ce8e077 | 2014-02-12 15:28:30 +0000 | [diff] [blame] | 266 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 267 | } |
Minyue | 13b96ba | 2015-10-03 00:39:14 +0200 | [diff] [blame] | 268 | } else if (event_msg.type() == Event::CONFIG) { |
| 269 | if (!event_msg.has_config()) { |
| 270 | printf("Corrupt input file: Config missing.\n"); |
| 271 | return 1; |
| 272 | } |
| 273 | const audioproc::Config msg = event_msg.config(); |
| 274 | |
| 275 | fprintf(settings_file, "APM re-config at frame: %d\n", frame_count); |
| 276 | |
| 277 | PRINT_CONFIG(aec_enabled); |
| 278 | PRINT_CONFIG(aec_delay_agnostic_enabled); |
| 279 | PRINT_CONFIG(aec_drift_compensation_enabled); |
| 280 | PRINT_CONFIG(aec_extended_filter_enabled); |
| 281 | PRINT_CONFIG(aec_suppression_level); |
| 282 | PRINT_CONFIG(aecm_enabled); |
| 283 | PRINT_CONFIG(aecm_comfort_noise_enabled); |
| 284 | PRINT_CONFIG(aecm_routing_mode); |
| 285 | PRINT_CONFIG(agc_enabled); |
| 286 | PRINT_CONFIG(agc_mode); |
| 287 | PRINT_CONFIG(agc_limiter_enabled); |
| 288 | PRINT_CONFIG(noise_robust_agc_enabled); |
| 289 | PRINT_CONFIG(hpf_enabled); |
| 290 | PRINT_CONFIG(ns_enabled); |
| 291 | PRINT_CONFIG(ns_level); |
| 292 | PRINT_CONFIG(transient_suppression_enabled); |
Alex Loiko | 5feb30e | 2018-04-16 13:52:32 +0200 | [diff] [blame] | 293 | PRINT_CONFIG(pre_amplifier_enabled); |
| 294 | PRINT_CONFIG_FLOAT(pre_amplifier_fixed_gain_factor); |
| 295 | |
peah | 7789fe7 | 2016-04-15 01:19:44 -0700 | [diff] [blame] | 296 | if (msg.has_experiments_description()) { |
| 297 | fprintf(settings_file, " experiments_description: %s\n", |
| 298 | msg.experiments_description().c_str()); |
| 299 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 300 | } else if (event_msg.type() == Event::INIT) { |
| 301 | if (!event_msg.has_init()) { |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 302 | printf("Corrupt input file: Init missing.\n"); |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 303 | return 1; |
| 304 | } |
| 305 | |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 306 | const Init msg = event_msg.init(); |
| 307 | // These should print out zeros if they're missing. |
| 308 | fprintf(settings_file, "Init at frame: %d\n", frame_count); |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 309 | int input_sample_rate = msg.sample_rate(); |
| 310 | fprintf(settings_file, " Input sample rate: %d\n", input_sample_rate); |
| 311 | int output_sample_rate = msg.output_sample_rate(); |
| 312 | fprintf(settings_file, " Output sample rate: %d\n", output_sample_rate); |
| 313 | int reverse_sample_rate = msg.reverse_sample_rate(); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 314 | fprintf(settings_file, " Reverse sample rate: %d\n", |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 315 | reverse_sample_rate); |
| 316 | num_input_channels = msg.num_input_channels(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 317 | fprintf(settings_file, " Input channels: %" PRIuS "\n", |
| 318 | num_input_channels); |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 319 | num_output_channels = msg.num_output_channels(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 320 | fprintf(settings_file, " Output channels: %" PRIuS "\n", |
| 321 | num_output_channels); |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 322 | num_reverse_channels = msg.num_reverse_channels(); |
Peter Kasting | 6955870 | 2016-01-12 16:26:35 -0800 | [diff] [blame] | 323 | fprintf(settings_file, " Reverse channels: %" PRIuS "\n", |
| 324 | num_reverse_channels); |
Minyue Li | 656d609 | 2018-08-10 15:38:52 +0200 | [diff] [blame] | 325 | if (msg.has_timestamp_ms()) { |
| 326 | const int64_t timestamp = msg.timestamp_ms(); |
| 327 | fprintf(settings_file, " Timestamp in millisecond: %" PRId64 "\n", |
| 328 | timestamp); |
| 329 | } |
andrew@webrtc.org | cd82438 | 2011-11-11 19:13:36 +0000 | [diff] [blame] | 330 | |
| 331 | fprintf(settings_file, "\n"); |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 332 | |
| 333 | if (reverse_sample_rate == 0) { |
| 334 | reverse_sample_rate = input_sample_rate; |
| 335 | } |
| 336 | if (output_sample_rate == 0) { |
| 337 | output_sample_rate = input_sample_rate; |
| 338 | } |
| 339 | |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 340 | reverse_samples_per_channel = |
| 341 | static_cast<size_t>(reverse_sample_rate / 100); |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 342 | input_samples_per_channel = static_cast<size_t>(input_sample_rate / 100); |
pkasting | 25702cb | 2016-01-08 13:50:27 -0800 | [diff] [blame] | 343 | output_samples_per_channel = |
| 344 | static_cast<size_t>(output_sample_rate / 100); |
aluebs@webrtc.org | bac0726 | 2014-09-03 13:39:01 +0000 | [diff] [blame] | 345 | |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 346 | if (!FLAG_raw) { |
aluebs@webrtc.org | 021e76f | 2014-09-04 18:12:00 +0000 | [diff] [blame] | 347 | // The WAV files need to be reset every time, because they cant change |
| 348 | // their sample rate or number of channels. |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 349 | rtc::StringBuilder reverse_name; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 350 | reverse_name << FLAG_reverse_file << frame_count << ".wav"; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 351 | reverse_wav_file.reset(new WavWriter( |
| 352 | reverse_name.str(), reverse_sample_rate, num_reverse_channels)); |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 353 | rtc::StringBuilder input_name; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 354 | input_name << FLAG_input_file << frame_count << ".wav"; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 355 | input_wav_file.reset(new WavWriter(input_name.str(), input_sample_rate, |
andrew@webrtc.org | a3ed713 | 2014-10-31 21:51:03 +0000 | [diff] [blame] | 356 | num_input_channels)); |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 357 | rtc::StringBuilder output_name; |
oprypin | 6e09d87 | 2017-08-31 03:21:39 -0700 | [diff] [blame] | 358 | output_name << FLAG_output_file << frame_count << ".wav"; |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 359 | output_wav_file.reset(new WavWriter( |
| 360 | output_name.str(), output_sample_rate, num_output_channels)); |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 361 | |
Jonas Olsson | 366a50c | 2018-09-06 13:41:30 +0200 | [diff] [blame^] | 362 | rtc::StringBuilder callorder_name; |
Sam Zackrisson | f61475d | 2018-05-11 11:34:49 +0200 | [diff] [blame] | 363 | callorder_name << FLAG_callorder_file << frame_count << ".char"; |
| 364 | callorder_char_file = OpenFile(callorder_name.str(), "wb"); |
aluebs@webrtc.org | 841f58f | 2014-09-02 07:51:51 +0000 | [diff] [blame] | 365 | } |
andrew@webrtc.org | cb18121 | 2011-10-26 00:27:17 +0000 | [diff] [blame] | 366 | } |
| 367 | } |
| 368 | |
| 369 | return 0; |
| 370 | } |
andrew@webrtc.org | a8b9737 | 2014-03-10 22:26:12 +0000 | [diff] [blame] | 371 | |
| 372 | } // namespace webrtc |
| 373 | |
| 374 | int main(int argc, char* argv[]) { |
| 375 | return webrtc::do_main(argc, argv); |
| 376 | } |