1 /* ScummVM Tools
2  *
3  * ScummVM Tools is the legal property of its developers, whose
4  * names are too numerous to list here. Please refer to the
5  * COPYRIGHT file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21 
22 #ifndef COMPRESS_H
23 #define COMPRESS_H
24 
25 #include "tool.h"
26 
27 
28 enum {
29 	/* These are the defaults parameters for the Lame invocation */
30 	algqualDef	= 2,
31 	vbrqualDef	= 4,
32 
33 	/* The default for oggenc invocation is to use the --quality option only */
34 	oggqualDef	= 3,
35 
36 	/* These are the default parameters for the FLAC invocation */
37 	flacCompressDef		= 8,
38 	flacBlocksizeDef	= 1152
39 };
40 
41 #define TEMP_WAV	"tempfile.wav"
42 #define TEMP_RAW	"tempfile.raw"
43 #define TEMP_MP3	"tempfile.mp3"
44 #define TEMP_OGG	"tempfile.ogg"
45 #define TEMP_FLAC	"tempfile.fla"
46 
47 
48 
49 /**
50  * Different audio formats.
51  * You can bitwise them to represent several formats.
52  */
53 enum AudioFormat {
54 	AUDIO_VORBIS = 1 << 0,
55 	AUDIO_FLAC   = 1 << 1,
56 	AUDIO_MP3    = 1 << 2,
57 
58 	AUDIO_NONE = 0,
59 	AUDIO_ALL = AUDIO_VORBIS | AUDIO_FLAC | AUDIO_MP3
60 };
61 
62 enum CompressionType {
63 	CBR,
64 	ABR,
65 	VBR
66 };
67 
68 const char *audio_extensions(AudioFormat format);
69 int compression_format(AudioFormat format);
70 
71 
72 /**
73  * A tool, which can compress to either MP3, Vorbis or FLAC formats.
74  */
75 class CompressionTool : public Tool {
76 public:
77 	CompressionTool(const std::string &name, ToolType type);
78 
79 	virtual std::string getHelp() const;
80 
81 	void parseAudioArguments();
82 
83 public:
84 	// FIXME: These vars should not be public, but the ToolGUI currently
85 	// accesses them directly. We should fix this.
86 
87 	/** Formats supported by this tool. */
88 	AudioFormat _supportedFormats;
89 
90 	AudioFormat _format;
91 
92 	// Settings
93 	// These functions are used by the GUI Tools and by CLI argument parsing functions
94 	// mp3 settings
95 	void setMp3LamePath(const std::string&);
96 	void setMp3CompressionType(const std::string&);
97 	void setMp3CompressionType(CompressionType);
98 	void setMp3MpegQuality(const std::string&);
99 	void setMp3TargetBitrate(const std::string&);
100 	void setMp3MinBitrate(const std::string&);
101 	void setMp3MaxBitrate(const std::string&);
102 	void unsetMp3MinBitrate();
103 	void unsetMp3MaxBitrate();
104 	void setMp3VBRQuality(const std::string&);
105 
106 	// flac
107 	void setFlacCompressionLevel(const std::string&);
108 	void setFlacBlockSize(const std::string&);
109 
110 	// vorbis
111 	void setOggQuality(const std::string&);
112 	void setOggMinBitrate(const std::string&);
113 	void setOggAvgBitrate(const std::string&);
114 	void setOggMaxBitrate(const std::string&);
115 	void unsetOggMinBitrate();
116 	void unsetOggMaxBitrate();
117 
118 
119 public:
120 	bool processMp3Parms();
121 	bool processOggParms();
122 	bool processFlacParms();
123 
124 	void setTempFileName();
125 
126 	void extractAndEncodeVOC(const char *outName, Common::File &input, AudioFormat compMode);
127 	void extractAndEncodeWAV(const char *outName, Common::File &input, AudioFormat compMode);
128 
129 	void extractAndEncodeAIFF(const char *inName, const char *outName, AudioFormat compMode);
130 
131 	void encodeAudio(const char *inname, bool rawInput, int rawSamplerate, const char *outname, AudioFormat compmode);
132 	void setRawAudioType(bool isLittleEndian, bool isStereo, uint8 bitsPerSample);
133 
134 protected:
135 
136 	void encodeRaw(const char *rawData, int length, int samplerate, const char *outname, AudioFormat compmode);
137 };
138 
139 /*
140  * Stuff which is in compress.cpp
141  *
142  * TODO: What is this? Document it?
143  */
144 const extern char *tempEncoded;
145 
146 #endif
147