| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2011 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
| 5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
| 6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 // Commandline tool to unpack audioproc debug files. | 11 // Commandline tool to unpack audioproc debug files. |
| 12 // | 12 // |
| 13 // The debug files are dumped as protobuf blobs. For analysis, it's necessary | 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. | 14 // to unpack the file into its component parts: audio and other data. |
| 15 | 15 |
| 16 #include <stdio.h> | 16 #include <stdio.h> |
| 17 | 17 |
| 18 #include "gflags/gflags.h" | 18 #include "gflags/gflags.h" |
| 19 #include "webrtc/audio_processing/debug.pb.h" | 19 #include "webrtc/audio_processing/debug.pb.h" |
| 20 #include "webrtc/base/format_macros.h" |
| 20 #include "webrtc/base/scoped_ptr.h" | 21 #include "webrtc/base/scoped_ptr.h" |
| 21 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" | 22 #include "webrtc/modules/audio_processing/test/protobuf_utils.h" |
| 22 #include "webrtc/modules/audio_processing/test/test_utils.h" | 23 #include "webrtc/modules/audio_processing/test/test_utils.h" |
| 23 #include "webrtc/typedefs.h" | 24 #include "webrtc/typedefs.h" |
| 24 | 25 |
| 25 // TODO(andrew): unpack more of the data. | 26 // TODO(andrew): unpack more of the data. |
| 26 DEFINE_string(input_file, "input", "The name of the input stream file."); | 27 DEFINE_string(input_file, "input", "The name of the input stream file."); |
| 27 DEFINE_string(output_file, "ref_out", | 28 DEFINE_string(output_file, "ref_out", |
| 28 "The name of the reference output stream file."); | 29 "The name of the reference output stream file."); |
| 29 DEFINE_string(reverse_file, "reverse", | 30 DEFINE_string(reverse_file, "reverse", |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 | 65 |
| 65 if (argc < 2) { | 66 if (argc < 2) { |
| 66 printf("%s", google::ProgramUsage()); | 67 printf("%s", google::ProgramUsage()); |
| 67 return 1; | 68 return 1; |
| 68 } | 69 } |
| 69 | 70 |
| 70 FILE* debug_file = OpenFile(argv[1], "rb"); | 71 FILE* debug_file = OpenFile(argv[1], "rb"); |
| 71 | 72 |
| 72 Event event_msg; | 73 Event event_msg; |
| 73 int frame_count = 0; | 74 int frame_count = 0; |
| 74 int reverse_samples_per_channel = 0; | 75 size_t reverse_samples_per_channel = 0; |
| 75 int input_samples_per_channel = 0; | 76 size_t input_samples_per_channel = 0; |
| 76 int output_samples_per_channel = 0; | 77 size_t output_samples_per_channel = 0; |
| 77 int num_reverse_channels = 0; | 78 size_t num_reverse_channels = 0; |
| 78 int num_input_channels = 0; | 79 size_t num_input_channels = 0; |
| 79 int num_output_channels = 0; | 80 size_t num_output_channels = 0; |
| 80 rtc::scoped_ptr<WavWriter> reverse_wav_file; | 81 rtc::scoped_ptr<WavWriter> reverse_wav_file; |
| 81 rtc::scoped_ptr<WavWriter> input_wav_file; | 82 rtc::scoped_ptr<WavWriter> input_wav_file; |
| 82 rtc::scoped_ptr<WavWriter> output_wav_file; | 83 rtc::scoped_ptr<WavWriter> output_wav_file; |
| 83 rtc::scoped_ptr<RawFile> reverse_raw_file; | 84 rtc::scoped_ptr<RawFile> reverse_raw_file; |
| 84 rtc::scoped_ptr<RawFile> input_raw_file; | 85 rtc::scoped_ptr<RawFile> input_raw_file; |
| 85 rtc::scoped_ptr<RawFile> output_raw_file; | 86 rtc::scoped_ptr<RawFile> output_raw_file; |
| 86 while (ReadMessageFromFile(debug_file, &event_msg)) { | 87 while (ReadMessageFromFile(debug_file, &event_msg)) { |
| 87 if (event_msg.type() == Event::REVERSE_STREAM) { | 88 if (event_msg.type() == Event::REVERSE_STREAM) { |
| 88 if (!event_msg.has_reverse_stream()) { | 89 if (!event_msg.has_reverse_stream()) { |
| 89 printf("Corrupt input file: ReverseStream missing.\n"); | 90 printf("Corrupt input file: ReverseStream missing.\n"); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 102 WriteIntData(reinterpret_cast<const int16_t*>(msg.data().data()), | 103 WriteIntData(reinterpret_cast<const int16_t*>(msg.data().data()), |
| 103 num_reverse_channels * reverse_samples_per_channel, | 104 num_reverse_channels * reverse_samples_per_channel, |
| 104 reverse_wav_file.get(), | 105 reverse_wav_file.get(), |
| 105 reverse_raw_file.get()); | 106 reverse_raw_file.get()); |
| 106 } else if (msg.channel_size() > 0) { | 107 } else if (msg.channel_size() > 0) { |
| 107 if (FLAGS_raw && !reverse_raw_file) { | 108 if (FLAGS_raw && !reverse_raw_file) { |
| 108 reverse_raw_file.reset(new RawFile(FLAGS_reverse_file + ".float")); | 109 reverse_raw_file.reset(new RawFile(FLAGS_reverse_file + ".float")); |
| 109 } | 110 } |
| 110 rtc::scoped_ptr<const float* []> data( | 111 rtc::scoped_ptr<const float* []> data( |
| 111 new const float* [num_reverse_channels]); | 112 new const float* [num_reverse_channels]); |
| 112 for (int i = 0; i < num_reverse_channels; ++i) { | 113 for (size_t i = 0; i < num_reverse_channels; ++i) { |
| 113 data[i] = reinterpret_cast<const float*>(msg.channel(i).data()); | 114 data[i] = reinterpret_cast<const float*>(msg.channel(i).data()); |
| 114 } | 115 } |
| 115 WriteFloatData(data.get(), | 116 WriteFloatData(data.get(), |
| 116 reverse_samples_per_channel, | 117 reverse_samples_per_channel, |
| 117 num_reverse_channels, | 118 num_reverse_channels, |
| 118 reverse_wav_file.get(), | 119 reverse_wav_file.get(), |
| 119 reverse_raw_file.get()); | 120 reverse_raw_file.get()); |
| 120 } | 121 } |
| 121 } else if (event_msg.type() == Event::STREAM) { | 122 } else if (event_msg.type() == Event::STREAM) { |
| 122 frame_count++; | 123 frame_count++; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 133 WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()), | 134 WriteIntData(reinterpret_cast<const int16_t*>(msg.input_data().data()), |
| 134 num_input_channels * input_samples_per_channel, | 135 num_input_channels * input_samples_per_channel, |
| 135 input_wav_file.get(), | 136 input_wav_file.get(), |
| 136 input_raw_file.get()); | 137 input_raw_file.get()); |
| 137 } else if (msg.input_channel_size() > 0) { | 138 } else if (msg.input_channel_size() > 0) { |
| 138 if (FLAGS_raw && !input_raw_file) { | 139 if (FLAGS_raw && !input_raw_file) { |
| 139 input_raw_file.reset(new RawFile(FLAGS_input_file + ".float")); | 140 input_raw_file.reset(new RawFile(FLAGS_input_file + ".float")); |
| 140 } | 141 } |
| 141 rtc::scoped_ptr<const float* []> data( | 142 rtc::scoped_ptr<const float* []> data( |
| 142 new const float* [num_input_channels]); | 143 new const float* [num_input_channels]); |
| 143 for (int i = 0; i < num_input_channels; ++i) { | 144 for (size_t i = 0; i < num_input_channels; ++i) { |
| 144 data[i] = reinterpret_cast<const float*>(msg.input_channel(i).data()); | 145 data[i] = reinterpret_cast<const float*>(msg.input_channel(i).data()); |
| 145 } | 146 } |
| 146 WriteFloatData(data.get(), | 147 WriteFloatData(data.get(), |
| 147 input_samples_per_channel, | 148 input_samples_per_channel, |
| 148 num_input_channels, | 149 num_input_channels, |
| 149 input_wav_file.get(), | 150 input_wav_file.get(), |
| 150 input_raw_file.get()); | 151 input_raw_file.get()); |
| 151 } | 152 } |
| 152 | 153 |
| 153 if (msg.has_output_data()) { | 154 if (msg.has_output_data()) { |
| 154 if (FLAGS_raw && !output_raw_file) { | 155 if (FLAGS_raw && !output_raw_file) { |
| 155 output_raw_file.reset(new RawFile(FLAGS_output_file + ".pcm")); | 156 output_raw_file.reset(new RawFile(FLAGS_output_file + ".pcm")); |
| 156 } | 157 } |
| 157 WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()), | 158 WriteIntData(reinterpret_cast<const int16_t*>(msg.output_data().data()), |
| 158 num_output_channels * output_samples_per_channel, | 159 num_output_channels * output_samples_per_channel, |
| 159 output_wav_file.get(), | 160 output_wav_file.get(), |
| 160 output_raw_file.get()); | 161 output_raw_file.get()); |
| 161 } else if (msg.output_channel_size() > 0) { | 162 } else if (msg.output_channel_size() > 0) { |
| 162 if (FLAGS_raw && !output_raw_file) { | 163 if (FLAGS_raw && !output_raw_file) { |
| 163 output_raw_file.reset(new RawFile(FLAGS_output_file + ".float")); | 164 output_raw_file.reset(new RawFile(FLAGS_output_file + ".float")); |
| 164 } | 165 } |
| 165 rtc::scoped_ptr<const float* []> data( | 166 rtc::scoped_ptr<const float* []> data( |
| 166 new const float* [num_output_channels]); | 167 new const float* [num_output_channels]); |
| 167 for (int i = 0; i < num_output_channels; ++i) { | 168 for (size_t i = 0; i < num_output_channels; ++i) { |
| 168 data[i] = | 169 data[i] = |
| 169 reinterpret_cast<const float*>(msg.output_channel(i).data()); | 170 reinterpret_cast<const float*>(msg.output_channel(i).data()); |
| 170 } | 171 } |
| 171 WriteFloatData(data.get(), | 172 WriteFloatData(data.get(), |
| 172 output_samples_per_channel, | 173 output_samples_per_channel, |
| 173 num_output_channels, | 174 num_output_channels, |
| 174 output_wav_file.get(), | 175 output_wav_file.get(), |
| 175 output_raw_file.get()); | 176 output_raw_file.get()); |
| 176 } | 177 } |
| 177 | 178 |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 229 fprintf(settings_file, "Init at frame: %d\n", frame_count); | 230 fprintf(settings_file, "Init at frame: %d\n", frame_count); |
| 230 int input_sample_rate = msg.sample_rate(); | 231 int input_sample_rate = msg.sample_rate(); |
| 231 fprintf(settings_file, " Input sample rate: %d\n", input_sample_rate); | 232 fprintf(settings_file, " Input sample rate: %d\n", input_sample_rate); |
| 232 int output_sample_rate = msg.output_sample_rate(); | 233 int output_sample_rate = msg.output_sample_rate(); |
| 233 fprintf(settings_file, " Output sample rate: %d\n", output_sample_rate); | 234 fprintf(settings_file, " Output sample rate: %d\n", output_sample_rate); |
| 234 int reverse_sample_rate = msg.reverse_sample_rate(); | 235 int reverse_sample_rate = msg.reverse_sample_rate(); |
| 235 fprintf(settings_file, | 236 fprintf(settings_file, |
| 236 " Reverse sample rate: %d\n", | 237 " Reverse sample rate: %d\n", |
| 237 reverse_sample_rate); | 238 reverse_sample_rate); |
| 238 num_input_channels = msg.num_input_channels(); | 239 num_input_channels = msg.num_input_channels(); |
| 239 fprintf(settings_file, " Input channels: %d\n", num_input_channels); | 240 fprintf(settings_file, " Input channels: %" PRIuS "\n", |
| 241 num_input_channels); |
| 240 num_output_channels = msg.num_output_channels(); | 242 num_output_channels = msg.num_output_channels(); |
| 241 fprintf(settings_file, " Output channels: %d\n", num_output_channels); | 243 fprintf(settings_file, " Output channels: %" PRIuS "\n", |
| 244 num_output_channels); |
| 242 num_reverse_channels = msg.num_reverse_channels(); | 245 num_reverse_channels = msg.num_reverse_channels(); |
| 243 fprintf(settings_file, " Reverse channels: %d\n", num_reverse_channels); | 246 fprintf(settings_file, " Reverse channels: %" PRIuS "\n", |
| 247 num_reverse_channels); |
| 244 | 248 |
| 245 fprintf(settings_file, "\n"); | 249 fprintf(settings_file, "\n"); |
| 246 | 250 |
| 247 if (reverse_sample_rate == 0) { | 251 if (reverse_sample_rate == 0) { |
| 248 reverse_sample_rate = input_sample_rate; | 252 reverse_sample_rate = input_sample_rate; |
| 249 } | 253 } |
| 250 if (output_sample_rate == 0) { | 254 if (output_sample_rate == 0) { |
| 251 output_sample_rate = input_sample_rate; | 255 output_sample_rate = input_sample_rate; |
| 252 } | 256 } |
| 253 | 257 |
| 254 reverse_samples_per_channel = reverse_sample_rate / 100; | 258 reverse_samples_per_channel = |
| 255 input_samples_per_channel = input_sample_rate / 100; | 259 static_cast<size_t>(reverse_sample_rate / 100); |
| 256 output_samples_per_channel = output_sample_rate / 100; | 260 input_samples_per_channel = |
| 261 static_cast<size_t>(input_sample_rate / 100); |
| 262 output_samples_per_channel = |
| 263 static_cast<size_t>(output_sample_rate / 100); |
| 257 | 264 |
| 258 if (!FLAGS_raw) { | 265 if (!FLAGS_raw) { |
| 259 // The WAV files need to be reset every time, because they cant change | 266 // The WAV files need to be reset every time, because they cant change |
| 260 // their sample rate or number of channels. | 267 // their sample rate or number of channels. |
| 261 reverse_wav_file.reset(new WavWriter(FLAGS_reverse_file + ".wav", | 268 reverse_wav_file.reset(new WavWriter(FLAGS_reverse_file + ".wav", |
| 262 reverse_sample_rate, | 269 reverse_sample_rate, |
| 263 num_reverse_channels)); | 270 num_reverse_channels)); |
| 264 input_wav_file.reset(new WavWriter(FLAGS_input_file + ".wav", | 271 input_wav_file.reset(new WavWriter(FLAGS_input_file + ".wav", |
| 265 input_sample_rate, | 272 input_sample_rate, |
| 266 num_input_channels)); | 273 num_input_channels)); |
| 267 output_wav_file.reset(new WavWriter(FLAGS_output_file + ".wav", | 274 output_wav_file.reset(new WavWriter(FLAGS_output_file + ".wav", |
| 268 output_sample_rate, | 275 output_sample_rate, |
| 269 num_output_channels)); | 276 num_output_channels)); |
| 270 } | 277 } |
| 271 } | 278 } |
| 272 } | 279 } |
| 273 | 280 |
| 274 return 0; | 281 return 0; |
| 275 } | 282 } |
| 276 | 283 |
| 277 } // namespace webrtc | 284 } // namespace webrtc |
| 278 | 285 |
| 279 int main(int argc, char* argv[]) { | 286 int main(int argc, char* argv[]) { |
| 280 return webrtc::do_main(argc, argv); | 287 return webrtc::do_main(argc, argv); |
| 281 } | 288 } |
| OLD | NEW |