From 76751297ca2121209a859a02ca8f6f5fb6f5d786 Mon Sep 17 00:00:00 2001 From: CJ Kucera Date: Fri, 4 Jun 2021 19:25:55 -0500 Subject: [PATCH 1/5] First pass at supporting stdout output --- .gitignore | 3 ++ src/ww2ogg.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++-------- src/wwriff.cpp | 2 +- src/wwriff.h | 2 +- 4 files changed, 76 insertions(+), 15 deletions(-) diff --git a/.gitignore b/.gitignore index 0def275..2a999a0 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,6 @@ *.exe *.out *.app + +# Linux Executable +ww2ogg diff --git a/src/ww2ogg.cpp b/src/ww2ogg.cpp index 6ac328e..86f064e 100644 --- a/src/ww2ogg.cpp +++ b/src/ww2ogg.cpp @@ -5,6 +5,11 @@ #include "wwriff.h" #include "stdint.h" #include "errors.h" +#ifdef __unix__ +#include +#define _isatty isatty +#define _fileno fileno +#endif using namespace std; @@ -16,13 +21,17 @@ class ww2ogg_options bool inline_codebooks; bool full_setup; ForcePacketFormat force_packet_format; + bool quiet; + bool to_stdout; public: ww2ogg_options(void) : in_filename(""), out_filename(""), codebooks_filename("packed_codebooks.bin"), inline_codebooks(false), full_setup(false), - force_packet_format(kNoForcePacketFormat) + force_packet_format(kNoForcePacketFormat), + quiet(false), + to_stdout(false) {} void parse_args(int argc, char **argv); const string& get_in_filename(void) const {return in_filename;} @@ -31,19 +40,26 @@ class ww2ogg_options bool get_inline_codebooks(void) const {return inline_codebooks;} bool get_full_setup(void) const {return full_setup;} ForcePacketFormat get_force_packet_format(void) const {return force_packet_format;} + bool get_quiet(void) const {return quiet;} + bool get_to_stdout(void) const {return to_stdout;} }; +void header(void) +{ + cout << "Audiokinetic Wwise RIFF/RIFX Vorbis to Ogg Vorbis converter " VERSION " by hcs" << endl << endl; +} + void usage(void) { + header(); cout << endl; cout << "usage: ww2ogg input.wav [-o output.ogg] [--inline-codebooks] [--full-setup]" << endl << " [--mod-packets | --no-mod-packets]" << endl << - " [--pcb packed_codebooks.bin]" << endl << endl; + " [--pcb packed_codebooks.bin] [--quiet]" << endl << endl; } int main(int argc, char **argv) { - cout << "Audiokinetic Wwise RIFF/RIFX Vorbis to Ogg Vorbis converter " VERSION " by hcs" << endl << endl; ww2ogg_options opt; @@ -59,9 +75,17 @@ int main(int argc, char **argv) return 1; } + if (!opt.get_quiet()) + { + header(); + } + try { - cout << "Input: " << opt.get_in_filename() << endl; + if (!opt.get_quiet()) + { + cout << "Input: " << opt.get_in_filename() << endl; + } Wwise_RIFF_Vorbis ww(opt.get_in_filename(), opt.get_codebooks_filename(), opt.get_inline_codebooks(), @@ -69,23 +93,42 @@ int main(int argc, char **argv) opt.get_force_packet_format() ); - ww.print_info(); - cout << "Output: " << opt.get_out_filename() << endl; + if (!opt.get_quiet()) + { + ww.print_info(); + } - ofstream of(opt.get_out_filename().c_str(), ios::binary); - if (!of) throw File_open_error(opt.get_out_filename()); + if (opt.get_to_stdout()) + { +#if defined(_WIN32) || defined(_WIN64) + _setmode(_fileno(stdout), _O_BINARY); +#endif + ww.generate_ogg(cout); + } + else + { + if (!opt.get_quiet()) + { + cout << "Output: " << opt.get_out_filename() << endl; + } + ofstream of(opt.get_out_filename().c_str(), ios::binary); + if (!of) throw File_open_error(opt.get_out_filename()); + ww.generate_ogg(of); + } - ww.generate_ogg(of); - cout << "Done!" << endl << endl; + if (!opt.get_quiet()) + { + cout << "Done!" << endl << endl; + } } catch (const File_open_error& fe) { - cout << fe << endl; + cerr << fe << endl; return 1; } catch (const Parse_error& pe) { - cout << pe << endl; + cerr << pe << endl; return 1; } @@ -105,12 +148,21 @@ void ww2ogg_options::parse_args(int argc, char ** argv) throw Argument_error("-o needs an option"); } - if (set_output) + if (set_output or to_stdout) { throw Argument_error("only one output file at a time"); } out_filename = argv[++i]; + if (out_filename == "-") + { + if (_isatty(_fileno(stdout))) + { + throw Argument_error("STDOUT output is not supported when on a TTY"); + } + to_stdout = true; + quiet = true; + } set_output = true; } else if (!strcmp(argv[i], "--inline-codebooks")) @@ -150,6 +202,12 @@ void ww2ogg_options::parse_args(int argc, char ** argv) codebooks_filename = argv[++i]; } + else if (!strcmp(argv[i], "--quiet")) + { + // don't output any status messages to stdout (will be + // forced active if our output is stdout) + quiet = true; + } else { // assume anything else is an input file name diff --git a/src/wwriff.cpp b/src/wwriff.cpp index 2784319..b7d8be7 100644 --- a/src/wwriff.cpp +++ b/src/wwriff.cpp @@ -1017,7 +1017,7 @@ void Wwise_RIFF_Vorbis::generate_ogg_header(Bit_oggstream& os, bool * & mode_blo } } -void Wwise_RIFF_Vorbis::generate_ogg(ofstream& of) +void Wwise_RIFF_Vorbis::generate_ogg(ostream& of) { Bit_oggstream os(of); diff --git a/src/wwriff.h b/src/wwriff.h index 49e69f2..437838f 100644 --- a/src/wwriff.h +++ b/src/wwriff.h @@ -75,7 +75,7 @@ class Wwise_RIFF_Vorbis void print_info(void); - void generate_ogg(ofstream& of); + void generate_ogg(ostream& of); void generate_ogg_header(Bit_oggstream& os, bool * & mode_blockflag, int & mode_bits); void generate_ogg_header_with_triad(Bit_oggstream& os); }; From 53814dc0ba6279398ab3a39ecb883d3115b07ece Mon Sep 17 00:00:00 2001 From: CJ Kucera Date: Fri, 4 Jun 2021 23:26:30 -0500 Subject: [PATCH 2/5] Some docs for stdout output --- README.md | 5 +++++ src/ww2ogg.cpp | 7 +++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 558d9b6..a88c733 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,11 @@ You can also specify an output file with `-o`, as in `ww2ogg input.ogg -o output.ogg` +To output the file to stdout (such as to pipe it to revorb or other +audio-processing utilities), use `-o -`, as in + +`ww2ogg input.ogg -o - | revorb - output.ogg` + Troubleshooting -------------------------------------------------------------------------------- diff --git a/src/ww2ogg.cpp b/src/ww2ogg.cpp index 86f064e..bbc1ee0 100644 --- a/src/ww2ogg.cpp +++ b/src/ww2ogg.cpp @@ -51,11 +51,14 @@ void header(void) void usage(void) { - header(); cout << endl; + header(); cout << "usage: ww2ogg input.wav [-o output.ogg] [--inline-codebooks] [--full-setup]" << endl << " [--mod-packets | --no-mod-packets]" << endl << - " [--pcb packed_codebooks.bin] [--quiet]" << endl << endl; + " [--pcb packed_codebooks.bin] [--quiet]" << endl << + endl << + "Use \"-o -\" to send the ogg file to stdout. This will also" << endl << + "imply \"--quiet\"." << endl << endl; } int main(int argc, char **argv) From 173d56c9c627b8ce22c42c87f6e7ebb0f9344646 Mon Sep 17 00:00:00 2001 From: CJ Kucera Date: Fri, 4 Jun 2021 23:31:03 -0500 Subject: [PATCH 3/5] Probably need this for _O_BINARY on mingw32 --- src/ww2ogg.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/ww2ogg.cpp b/src/ww2ogg.cpp index bbc1ee0..c3543e9 100644 --- a/src/ww2ogg.cpp +++ b/src/ww2ogg.cpp @@ -10,6 +10,9 @@ #define _isatty isatty #define _fileno fileno #endif +#ifdef __MINGW32__ +#define +#endif using namespace std; From 85f2d112263bf0618887acba207cbb3e3fd6f6df Mon Sep 17 00:00:00 2001 From: CJ Kucera Date: Fri, 4 Jun 2021 23:36:20 -0500 Subject: [PATCH 4/5] Send argument errors to stderr --- src/ww2ogg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ww2ogg.cpp b/src/ww2ogg.cpp index c3543e9..1fd084c 100644 --- a/src/ww2ogg.cpp +++ b/src/ww2ogg.cpp @@ -75,7 +75,7 @@ int main(int argc, char **argv) } catch (const Argument_error& ae) { - cout << ae << endl; + cerr << ae << endl; usage(); return 1; From 7ba60246baf04354fa916250ce70c5dea95f5f43 Mon Sep 17 00:00:00 2001 From: CJ Kucera Date: Fri, 4 Jun 2021 23:37:23 -0500 Subject: [PATCH 5/5] Probably need to check for __MINGW32__ here, too --- src/ww2ogg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ww2ogg.cpp b/src/ww2ogg.cpp index 1fd084c..fc3e64e 100644 --- a/src/ww2ogg.cpp +++ b/src/ww2ogg.cpp @@ -106,7 +106,7 @@ int main(int argc, char **argv) if (opt.get_to_stdout()) { -#if defined(_WIN32) || defined(_WIN64) +#if defined(_WIN32) || defined(_WIN64) || defined(__MINGW32__) _setmode(_fileno(stdout), _O_BINARY); #endif ww.generate_ogg(cout);