Unpack the full set of audioproc data.

Review URL: http://webrtc-codereview.appspot.com/276004

git-svn-id: http://webrtc.googlecode.com/svn/trunk@937 4adac7df-926f-26a2-2b94-8c16560cd09d
This commit is contained in:
andrew@webrtc.org 2011-11-11 19:13:36 +00:00
parent d71d480487
commit cd8243807e
2 changed files with 120 additions and 26 deletions

View File

@ -53,7 +53,7 @@
'sources': [ 'test/process_test.cc', ],
},
{
'target_name': 'unpack',
'target_name': 'unpack_aecdump',
'type': 'executable',
'dependencies': [
'audioproc_debug_proto',

View File

@ -25,12 +25,20 @@ using webrtc::scoped_array;
using webrtc::audioproc::Event;
using webrtc::audioproc::ReverseStream;
using webrtc::audioproc::Stream;
using webrtc::audioproc::Init;
// TODO(andrew): unpack more of the data.
DEFINE_string(input_file, "input.pcm", "The name of the input stream file.");
DEFINE_string(output_file, "output.pcm", "The name of the output stream file.");
DEFINE_string(reverse_file, "reverse.pcm", "The name of the reverse input "
"file.");
DEFINE_string(output_file, "ref_out.pcm",
"The name of the reference output stream file.");
DEFINE_string(reverse_file, "reverse.pcm",
"The name of the reverse input stream file.");
DEFINE_string(delay_file, "delay.int32", "The name of the delay file.");
DEFINE_string(drift_file, "drift.int32", "The name of the drift file.");
DEFINE_string(level_file, "level.int32", "The name of the level file.");
DEFINE_string(settings_file, "settings.txt", "The name of the settings file.");
DEFINE_bool(full, false,
"Unpack the full set of files (normally not needed).");
// TODO(andrew): move this to a helper class to share with process_test.cc?
// Returns true on success, false on error or end-of-file.
@ -69,10 +77,54 @@ int main(int argc, char* argv[]) {
}
FILE* debug_file = fopen(argv[1], "rb");
if (debug_file == NULL) {
printf("Unable to open %s\n", argv[1]);
return 1;
}
FILE* input_file = fopen(FLAGS_input_file.c_str(), "wb");
if (input_file == NULL) {
printf("Unable to open %s\n", FLAGS_input_file.c_str());
return 1;
}
FILE* output_file = fopen(FLAGS_output_file.c_str(), "wb");
if (output_file == NULL) {
printf("Unable to open %s\n", FLAGS_output_file.c_str());
return 1;
}
FILE* reverse_file = fopen(FLAGS_reverse_file.c_str(), "wb");
if (reverse_file == NULL) {
printf("Unable to open %s\n", FLAGS_reverse_file.c_str());
return 1;
}
FILE* settings_file = fopen(FLAGS_settings_file.c_str(), "wb");
if (settings_file == NULL) {
printf("Unable to open %s\n", FLAGS_settings_file.c_str());
return 1;
}
FILE* delay_file = NULL;
FILE* drift_file = NULL;
FILE* level_file = NULL;
if (FLAGS_full) {
delay_file = fopen(FLAGS_delay_file.c_str(), "wb");
if (delay_file == NULL) {
printf("Unable to open %s\n", FLAGS_delay_file.c_str());
return 1;
}
drift_file = fopen(FLAGS_drift_file.c_str(), "wb");
if (drift_file == NULL) {
printf("Unable to open %s\n", FLAGS_drift_file.c_str());
return 1;
}
level_file = fopen(FLAGS_level_file.c_str(), "wb");
if (level_file == NULL) {
printf("Unable to open %s\n", FLAGS_level_file.c_str());
return 1;
}
}
Event event_msg;
int frame_count = 0;
while (ReadMessageFromFile(debug_file, &event_msg)) {
if (event_msg.type() == Event::REVERSE_STREAM) {
if (!event_msg.has_reverse_stream()) {
@ -81,40 +133,82 @@ int main(int argc, char* argv[]) {
}
const ReverseStream msg = event_msg.reverse_stream();
if (!msg.has_data()) {
printf("Corrupted input file: ReverseStream::data missing.\n");
return 1;
}
if (fwrite(msg.data().data(), msg.data().size(), 1, reverse_file) != 1) {
printf("Error when writing to %s\n", FLAGS_reverse_file.c_str());
return 1;
if (msg.has_data()) {
if (fwrite(msg.data().data(), msg.data().size(), 1, reverse_file) !=
1) {
printf("Error when writing to %s\n", FLAGS_reverse_file.c_str());
return 1;
}
}
} else if (event_msg.type() == Event::STREAM) {
frame_count++;
if (!event_msg.has_stream()) {
printf("Corrupted input file: Stream missing.\n");
return 1;
}
const Stream msg = event_msg.stream();
if (!msg.has_input_data()) {
printf("Corrupted input file: Stream::input_data missing.\n");
return 1;
if (msg.has_input_data()) {
if (fwrite(msg.input_data().data(), msg.input_data().size(), 1,
input_file) != 1) {
printf("Error when writing to %s\n", FLAGS_input_file.c_str());
return 1;
}
}
if (fwrite(msg.input_data().data(), msg.input_data().size(), 1,
input_file) != 1) {
printf("Error when writing to %s\n", FLAGS_input_file.c_str());
if (msg.has_output_data()) {
if (fwrite(msg.output_data().data(), msg.output_data().size(), 1,
output_file) != 1) {
printf("Error when writing to %s\n", FLAGS_output_file.c_str());
return 1;
}
}
if (FLAGS_full) {
if (msg.has_delay()) {
int32_t delay = msg.delay();
if (fwrite(&delay, sizeof(int32_t), 1, delay_file) != 1) {
printf("Error when writing to %s\n", FLAGS_delay_file.c_str());
return 1;
}
}
if (msg.has_drift()) {
int32_t drift = msg.drift();
if (fwrite(&drift, sizeof(int32_t), 1, drift_file) != 1) {
printf("Error when writing to %s\n", FLAGS_drift_file.c_str());
return 1;
}
}
if (msg.has_level()) {
int32_t level = msg.level();
if (fwrite(&level, sizeof(int32_t), 1, level_file) != 1) {
printf("Error when writing to %s\n", FLAGS_level_file.c_str());
return 1;
}
}
}
} else if (event_msg.type() == Event::INIT) {
if (!event_msg.has_init()) {
printf("Corrupted input file: Init missing.\n");
return 1;
}
if (!msg.has_output_data()) {
printf("Corrupted input file: Stream::output_data missing.\n");
return 1;
}
if (fwrite(msg.output_data().data(), msg.output_data().size(), 1,
output_file) != 1) {
printf("Error when writing to %s\n", FLAGS_output_file.c_str());
return 1;
}
const Init msg = event_msg.init();
// These should print out zeros if they're missing.
fprintf(settings_file, "Init at frame: %d\n", frame_count);
fprintf(settings_file, " Sample rate: %d\n", msg.sample_rate());
fprintf(settings_file, " Device sample rate: %d\n",
msg.device_sample_rate());
fprintf(settings_file, " Input channels: %d\n",
msg.num_input_channels());
fprintf(settings_file, " Output channels: %d\n",
msg.num_output_channels());
fprintf(settings_file, " Reverse channels: %d\n",
msg.num_reverse_channels());
fprintf(settings_file, "\n");
}
}