diff --git a/compress.cpp b/compress.cpp index 8634f3df..98484877 100644 --- a/compress.cpp +++ b/compress.cpp @@ -882,10 +882,14 @@ bool CompressionTool::processFlacParms(){ // The old code can be removed once all tools have been converted CompressionTool::CompressionTool(const std::string &name, ToolType type) : Tool(name, type) { + _supportedFormats = AUDIO_ALL; _format = AUDIO_MP3; } void CompressionTool::parseAudioArguments() { + if (_supportedFormats == AUDIO_NONE) + return; + _format = AUDIO_MP3; if (_arguments.front() == "--mp3") @@ -978,3 +982,32 @@ std::string CompressionTool::getHelp() const { return os.str(); } + +const char *audio_extensions(AudioFormat format) { + switch(format) { + case AUDIO_MP3: + return ".mp3"; + case AUDIO_VORBIS: + return ".ogg"; + case AUDIO_FLAC: + return ".fla"; + case AUDIO_NONE: + default: + return ".unk"; + } +} + +CompressionFormat compression_format(AudioFormat format) { + switch(format) { + case AUDIO_MP3: + return COMPRESSION_MP3; + case AUDIO_VORBIS: + return COMPRESSION_OGG; + case AUDIO_FLAC: + return COMPRESSION_FLAC; + case AUDIO_NONE: + default: + throw ToolException("Unknown compression format"); + } +} + diff --git a/compress.h b/compress.h index 142fe6e9..26d04384 100644 --- a/compress.h +++ b/compress.h @@ -33,23 +33,20 @@ #include #endif -/* We use string constants here, so we can insert the - * constants directly into literals - * These are given integer definitions below - */ +enum { + /* These are the defaults parameters for the Lame invocation */ + minBitrDef = 24, + maxBitrDef = 64, + algqualDef = 2, + vbrqualDef = 4, -/* These are the defaults parameters for the Lame invocation */ -#define minBitrDef 24 -#define maxBitrDef 64 -#define algqualDef 2 -#define vbrqualDef 4 + /* The default for oggenc invocation is to use the --quality option only */ + oggqualDef = 3, -/* The default for oggenc invocation is to use the --quality option only */ -#define oggqualDef 3 - -/* These are the default parameters for the FLAC invocation */ -#define flacCompressDef 8 -#define flacBlocksizeDef 1152 + /* These are the default parameters for the FLAC invocation */ + flacCompressDef = 8, + flacBlocksizeDef = 1152 +}; #define TEMP_WAV "tempfile.wav" #define TEMP_RAW "tempfile.raw" @@ -59,9 +56,35 @@ +/** + * Different audio formats. + * You can bitwise them to represent several formats. + */ +enum AudioFormat { + AUDIO_NONE = 0, + AUDIO_VORBIS = 1, + AUDIO_FLAC = 2, + AUDIO_MP3 = 4, + AUDIO_ALL = AUDIO_VORBIS | AUDIO_FLAC | AUDIO_MP3 +}; + /** - * Compression tool - * A tool, which can compress to either MP3, Vorbis or FLAC formats + * Another enum, which cannot be ORed. + * These are the values written to the output files. + */ +enum CompressionFormat { + COMPRESSION_NONE = 0, + COMPRESSION_MP3 = 1, + COMPRESSION_OGG = 2, + COMPRESSION_FLAC = 3 +}; + +const char *audio_extensions(AudioFormat format); +CompressionFormat compression_format(AudioFormat format); + + +/** + * A tool, which can compress to either MP3, Vorbis or FLAC formats. */ class CompressionTool : public Tool { public: @@ -70,7 +93,11 @@ public: virtual std::string getHelp() const; void parseAudioArguments(); -public: + +protected: + /** Formats supported by this tool. */ + AudioFormat _supportedFormats; + AudioFormat _format; // Settings @@ -85,13 +112,13 @@ public: // flac std::string _flacCompressionLevel; std::string _flacBlockSize; - + // vorbis std::string _oggQuality; std::string _oggMinBitrate; std::string _oggAvgBitrate; std::string _oggMaxBitrate; - + public: bool processMp3Parms(); bool processOggParms(); @@ -107,6 +134,8 @@ public: /* * Stuff which is in compress.cpp + * + * TODO: What is this? Document it? */ const extern char *tempEncoded; diff --git a/tool.cpp b/tool.cpp index 6835a22b..964e5658 100644 --- a/tool.cpp +++ b/tool.cpp @@ -33,7 +33,6 @@ Tool::Tool(const std::string &name, ToolType type) { _type = type; _outputToDirectory = true; - _supportedFormats = AUDIO_ALL; _supportsProgressBar = false; _internalPrint = standardPrint; @@ -67,8 +66,7 @@ int Tool::run(const std::deque &args) { } // Read standard arguments - if (_supportedFormats != AUDIO_NONE) - parseAudioArguments(); + parseAudioArguments(); parseOutputArguments(); // Read tool specific arguments parseExtraArguments(); diff --git a/tool.h b/tool.h index 8b0c6e88..28b64129 100644 --- a/tool.h +++ b/tool.h @@ -210,8 +210,6 @@ protected: /** If this tools outputs to a directory, not a file. */ bool _outputToDirectory; - /** Formats supported by this tool. */ - AudioFormat _supportedFormats; /** If this tool can display output progress in % */ bool _supportsProgressBar; diff --git a/util.cpp b/util.cpp index 2b5da68f..c3bc9b4f 100644 --- a/util.cpp +++ b/util.cpp @@ -28,34 +28,6 @@ #define vsnprintf _vsnprintf #endif -const char *audio_extensions(AudioFormat format) { - switch(format) { - case AUDIO_MP3: - return ".mp3"; - case AUDIO_VORBIS: - return ".ogg"; - case AUDIO_FLAC: - return ".fla"; - case AUDIO_NONE: - default: - return ".unk"; - } -} - -CompressionFormat compression_format(AudioFormat format) { - switch(format) { - case AUDIO_MP3: - return COMPRESSION_MP3; - case AUDIO_VORBIS: - return COMPRESSION_OGG; - case AUDIO_FLAC: - return COMPRESSION_FLAC; - case AUDIO_NONE: - default: - throw ToolException("Unknown compression format"); - } -} - void error(const char *s, ...) { char buf[1024]; va_list va; diff --git a/util.h b/util.h index 223afad0..e829853b 100644 --- a/util.h +++ b/util.h @@ -43,17 +43,13 @@ #include #include - /* * GCC specific stuff */ #if defined(__GNUC__) - #define GCC_PACK __attribute__((packed)) - #define NORETURN __attribute__((__noreturn__)) - #define GCC_PRINTF(x,y) __attribute__((format(printf, x, y))) + #define GCC_PACK __attribute__((packed)) #else - #define GCC_PACK - #define GCC_PRINTF(x,y) + #define GCC_PACK #endif #ifndef ARRAYSIZE @@ -143,31 +139,4 @@ void warning(const char *s, ...); void debug(int level, const char *s, ...); void notice(const char *s, ...); - -/** - * Different audio formats - * You can bitwise them to represent several formats - */ -enum AudioFormat { - AUDIO_NONE = 0, - AUDIO_VORBIS = 1, - AUDIO_FLAC = 2, - AUDIO_MP3 = 4, - AUDIO_ALL = AUDIO_VORBIS | AUDIO_FLAC | AUDIO_MP3 -}; - -/** - * Another enum, which cannot be ORed - * These are the values written to the output files - */ -enum CompressionFormat { - COMPRESSION_NONE = 0, - COMPRESSION_MP3 = 1, - COMPRESSION_OGG = 2, - COMPRESSION_FLAC = 3 -}; - -const char *audio_extensions(AudioFormat format); -CompressionFormat compression_format(AudioFormat format); - #endif