From e9e5d176c307801d3e18329fbdf0809b83a2e47e Mon Sep 17 00:00:00 2001 From: Claudio Matsuoka Date: Wed, 15 Feb 2012 09:26:41 -0200 Subject: [PATCH] [xmp] Add option to write sound to file Signed-off-by: Claudio Matsuoka --- src/main.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main.c b/src/main.c index 9e709ea..62745e5 100644 --- a/src/main.c +++ b/src/main.c @@ -91,6 +91,7 @@ int main(int argc, char **argv) int i; int first; int skipprev; + FILE *f = NULL; #ifndef WIN32 struct timeval tv; struct timezone tz; @@ -113,6 +114,12 @@ int main(int argc, char **argv) if (options.silent) { sound = &sound_null; + } else if (options.out_file) { + f = fopen(options.out_file, "wb"); + if (f == NULL) { + perror(options.out_file); + exit(EXIT_FAILURE); + } } if (sound->init(44100, 2) < 0) { @@ -184,6 +191,10 @@ int main(int argc, char **argv) info_frame(&mi, &control, refresh_line); sound->play(mi.buffer, mi.buffer_size); + if (options.out_file) { + fwrite(mi.buffer, mi.buffer_size, 1, f); + } + read_command(handle, &control); if (control.display) { @@ -218,5 +229,9 @@ end: reset_tty(); sound->deinit(); + if (options.out_file) { + fclose(f); + } + exit(EXIT_SUCCESS); }