[Scummvm-cvs-logs] SF.net SVN: scummvm:[50029] tools/trunk

criezy at users.sourceforge.net criezy at users.sourceforge.net
Fri Jun 18 23:03:41 CEST 2010


Revision: 50029
          http://scummvm.svn.sourceforge.net/scummvm/?rev=50029&view=rev
Author:   criezy
Date:     2010-06-18 21:03:40 +0000 (Fri, 18 Jun 2010)

Log Message:
-----------
Add option to compress MP3 in constant bit rate. This has only been added to the command line tool for the moment (i.e. the option is not available in the GUI yet). Also fix a but that meant encoding in VBR was always using the default target bit rate (64 kb/s) and ignoring the one given by the user.

Modified Paths:
--------------
    tools/trunk/compress.cpp
    tools/trunk/compress.h

Modified: tools/trunk/compress.cpp
===================================================================
--- tools/trunk/compress.cpp	2010-06-18 18:55:17 UTC (rev 50028)
+++ tools/trunk/compress.cpp	2010-06-18 21:03:40 UTC (rev 50029)
@@ -45,7 +45,7 @@
 	int32 minBitr;
 	int32 maxBitr;
 	uint32 targetBitr;
-	bool abr;
+	CompressionType type;
 	uint32 algqual;
 	uint32 vbrqual;
 	bool silent;
@@ -72,7 +72,7 @@
 	uint8 bitsPerSample;
 };
 
-lameparams lameparms = { -1, -1, 32, false, algqualDef, vbrqualDef, 0, "lame" };
+lameparams lameparms = { -1, -1, 32, VBR, algqualDef, vbrqualDef, 0, "lame" };
 oggencparams oggparms = { -1, -1, -1, (float)oggqualDef, 0 };
 flaccparams flacparms = { flacCompressDef, flacBlocksizeDef, false, false };
 rawtype	rawAudioType = { false, false, 8 };
@@ -140,15 +140,19 @@
 			tmp += sprintf(tmp, "-s %d ", rawSamplerate);
 		}
 
-		if (lameparms.abr)
-			tmp += sprintf(tmp, "--abr %d ", lameparms.targetBitr);
-		else
-			tmp += sprintf(tmp, "--vbr-new -V %d ", lameparms.vbrqual);
+		if (lameparms.type == CBR)
+			tmp += sprintf(tmp, "--cbr -b %d ", lameparms.targetBitr);
+		else {
+			if (lameparms.type == ABR)
+				tmp += sprintf(tmp, "--abr %d ", lameparms.targetBitr);
+			else
+				tmp += sprintf(tmp, "--vbr-new -V %d ", lameparms.vbrqual);
 
-		if (lameparms.minBitr != -1)
-			tmp += sprintf(tmp, "-b %d ", lameparms.minBitr);
-		if (lameparms.maxBitr != -1)
-			tmp += sprintf(tmp, "-B %d ", lameparms.maxBitr);
+			if (lameparms.minBitr != -1)
+				tmp += sprintf(tmp, "-b %d ", lameparms.minBitr);
+			if (lameparms.maxBitr != -1)
+				tmp += sprintf(tmp, "-B %d ", lameparms.maxBitr);
+		}
 
 		/* Explicitly specify a target sample rate, to work around a bug (?)
 		* in newer lame versions (>= 3.95) which causes it to malfunction
@@ -784,9 +788,18 @@
 }
 
 void CompressionTool::setMp3CompressionType(const std::string& arg) {
-	lameparms.abr = (arg == "ABR");
+	if (arg == "CBR")
+		lameparms.type = CBR;
+	else if (arg == "ABR")
+		lameparms.type = ABR;
+	else
+		lameparms.type = VBR;
 }
 
+void CompressionTool::setMp3CompressionType(CompressionType type) {
+	lameparms.type = type;
+}
+
 void CompressionTool::setMp3MpegQuality(const std::string& arg) {
 	lameparms.algqual = atoi(arg.c_str());
 	
@@ -798,13 +811,13 @@
 }
 
 void CompressionTool::setMp3TargetBitrate(const std::string& arg) {
-	lameparms.minBitr = atoi(arg.c_str());
+	lameparms.targetBitr = atoi(arg.c_str());
 	
 	if (lameparms.targetBitr == 0 && arg != "0")
-		throw ToolException("Minimum bitrate (-b) must be a number.");
+		throw ToolException("Target bitrate must be a number.");
 	
 	if (lameparms.targetBitr < 8 || lameparms.targetBitr > 160)
-		throw ToolException("Minimum bitrate out of bounds (-b), must be between 8 and 160.");
+		throw ToolException("Target bitrate out of bounds, must be between 8 and 160.");
 }
 
 void CompressionTool::setMp3MinBitrate(const std::string& arg) {
@@ -917,14 +930,20 @@
 		_arguments.pop_front();
 
 		if (arg == "--vbr") {
-			lameparms.abr = 0;
+			lameparms.type = VBR;
 		} else if (arg == "--abr") {
 			if (_arguments.empty())
 				throw ToolException("Could not parse command line options, expected target bitrate after --abr");
-			lameparms.abr = 1;
+			lameparms.type = VBR;
 			setMp3TargetBitrate(_arguments.front());
 			_arguments.pop_front();
-
+		} else if (arg == "--cbr") {
+			if (_arguments.empty())
+				throw ToolException("Could not parse command line options, expected target bitrate after --cbr");
+			lameparms.type = CBR;
+			setMp3TargetBitrate(_arguments.front());
+			_arguments.pop_front();
+			
 		} else if (arg == "--lame-path") {
 			if (_arguments.empty())
 				throw ToolException("Could not parse command line options, expected value after --lame-path");
@@ -1139,6 +1158,7 @@
 		os << " -B <rate>    <rate> is the maximum bitrate (default:unset)\n";
 		os << " --vbr        LAME uses the VBR mode (default)\n";
 		os << " --abr <rate> LAME uses the ABR mode with the given target bitrate\n";
+		os << " --cbr <rate> LAME uses the CBR mode with the given bitrate\n";
 		os << " -V <value>   specifies the value (0 - 9) of VBR quality (0=best) (default:" << vbrqualDef << ")\n";
 		os << " -q <value>   specifies the MPEG algorithm quality (0-9; 0=best) (default:" << algqualDef << ")\n";
 		os << " --silent     the output of LAME is hidden (default:disabled)\n";

Modified: tools/trunk/compress.h
===================================================================
--- tools/trunk/compress.h	2010-06-18 18:55:17 UTC (rev 50028)
+++ tools/trunk/compress.h	2010-06-18 21:03:40 UTC (rev 50029)
@@ -60,6 +60,12 @@
 	AUDIO_ALL = AUDIO_VORBIS | AUDIO_FLAC | AUDIO_MP3
 };
 
+enum CompressionType {
+	CBR,
+	ABR,
+	VBR
+};
+
 const char *audio_extensions(AudioFormat format);
 int compression_format(AudioFormat format);
 
@@ -89,6 +95,7 @@
 	// mp3 settings
 	void setMp3LamePath(const std::string&);
 	void setMp3CompressionType(const std::string&);
+	void setMp3CompressionType(CompressionType);
 	void setMp3MpegQuality(const std::string&);
 	void setMp3TargetBitrate(const std::string&);
 	void setMp3MinBitrate(const std::string&);


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list