1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2017 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Encoder_Vorbis.h"
26 #include "Model_Settings.h"
31 ///////////////////////////////////////////////////////////////////////////////
33 ///////////////////////////////////////////////////////////////////////////////
35 class VorbisEncoderInfo
: public AbstractEncoderInfo
37 virtual bool isModeSupported(int mode
) const
41 case SettingsModel::VBRMode
:
42 case SettingsModel::ABRMode
:
45 case SettingsModel::CBRMode
:
49 MUTILS_THROW("Bad RC mode specified!");
53 virtual int valueCount(int mode
) const
57 case SettingsModel::VBRMode
:
60 case SettingsModel::ABRMode
:
61 case SettingsModel::CBRMode
:
65 MUTILS_THROW("Bad RC mode specified!");
69 virtual int valueAt(int mode
, int index
) const
73 case SettingsModel::VBRMode
:
74 return qBound(-2, index
- 2, 10);
76 case SettingsModel::ABRMode
:
77 case SettingsModel::CBRMode
:
78 return qBound(32, (index
+ 4) * 8, 500);
81 MUTILS_THROW("Bad RC mode specified!");
85 virtual int valueType(int mode
) const
89 case SettingsModel::VBRMode
:
90 return TYPE_QUALITY_LEVEL_INT
;
92 case SettingsModel::ABRMode
:
93 return TYPE_APPROX_BITRATE
;
95 case SettingsModel::CBRMode
:
99 MUTILS_THROW("Bad RC mode specified!");
103 virtual const char *description(void) const
105 static const char* s_description
= "OggEnc2 Vorbis Encoder (aoTuV)";
106 return s_description
;
109 virtual const char *extension(void) const
111 static const char* s_extension
= "ogg";
115 virtual bool isResamplingSupported(void) const
120 static const g_vorbisEncoderInfo
;
122 ///////////////////////////////////////////////////////////////////////////////
123 // Encoder implementation
124 ///////////////////////////////////////////////////////////////////////////////
126 VorbisEncoder::VorbisEncoder(void)
128 m_binary(lamexp_tools_lookup(L1S("oggenc2.exe")))
130 if(m_binary
.isEmpty())
132 MUTILS_THROW("Error initializing Vorbis encoder. Tool 'oggenc2.exe' is not registred!");
135 m_configBitrateMaximum
= 0;
136 m_configBitrateMinimum
= 0;
137 m_configSamplingRate
= 0;
140 VorbisEncoder::~VorbisEncoder(void)
144 bool VorbisEncoder::encode(const QString
&sourceFile
, const AudioFileModel_MetaInfo
&metaInfo
, const unsigned int duration
, const unsigned int channels
, const QString
&outputFile
, QAtomicInt
&abortFlag
)
148 const QString baseName
= QFileInfo(outputFile
).fileName();
150 switch(m_configRCMode
)
152 case SettingsModel::VBRMode
:
153 args
<< L1S("-q") << QString::number(qBound(-2, m_configBitrate
- 2, 10));
155 case SettingsModel::ABRMode
:
156 args
<< L1S("-b") << QString::number(qBound(32, (m_configBitrate
+ 4) * 8, 500));
159 MUTILS_THROW("Bad rate-control mode!");
163 if((m_configBitrateMaximum
> 0) && (m_configBitrateMinimum
> 0) && (m_configBitrateMinimum
<= m_configBitrateMaximum
))
165 args
<< L1S("--min-bitrate") << QString::number(qBound(32, m_configBitrateMinimum
, 500));
166 args
<< L1S("--max-bitrate") << QString::number(qBound(32, m_configBitrateMaximum
, 500));
169 if(m_configSamplingRate
> 0)
171 args
<< L1S("--resample") << QString::number(m_configSamplingRate
) << L1S("--converter") << QString::number(0);
174 if (!metaInfo
.empty(false))
176 args
<< L1S("--discard-comments");
179 if(!metaInfo
.title().isEmpty()) args
<< L1S("-t") << cleanTag(metaInfo
.title());
180 if(!metaInfo
.artist().isEmpty()) args
<< L1S("-a") << cleanTag(metaInfo
.artist());
181 if(!metaInfo
.album().isEmpty()) args
<< L1S("-l") << cleanTag(metaInfo
.album());
182 if(!metaInfo
.genre().isEmpty()) args
<< L1S("-G") << cleanTag(metaInfo
.genre());
183 if(!metaInfo
.comment().isEmpty()) args
<< L1S("-c") << QString("comment=%1").arg(cleanTag(metaInfo
.comment()));
184 if(metaInfo
.year()) args
<< L1S("-d") << QString::number(metaInfo
.year());
185 if(metaInfo
.position()) args
<< L1S("-N") << QString::number(metaInfo
.position());
187 //args << "--tv" << QString().sprintf("Encoder=LameXP v%d.%02d.%04d [%s]", lamexp_version_major(), lamexp_version_minor(), lamexp_version_build(), lamexp_version_release());
189 if(!m_configCustomParams
.isEmpty()) args
<< m_configCustomParams
.split(" ", QString::SkipEmptyParts
);
191 args
<< L1S("-o") << QDir::toNativeSeparators(outputFile
);
192 args
<< QDir::toNativeSeparators(sourceFile
);
194 if(!startProcess(process
, m_binary
, args
))
199 int prevProgress
= -1;
200 QRegExp
regExp(L1S("\\[.*(\\d+)[.,](\\d+)%\\]"));
202 const result_t result
= awaitProcess(process
, abortFlag
, [this, &prevProgress
, ®Exp
](const QString
&text
)
204 if (regExp
.lastIndexIn(text
) >= 0)
207 if (MUtils::regexp_parse_int32(regExp
, newProgress
))
209 if (newProgress
> prevProgress
)
211 emit
statusUpdated(newProgress
);
212 prevProgress
= NEXT_PROGRESS(newProgress
);
220 return (result
== RESULT_SUCCESS
);
223 bool VorbisEncoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
225 if(containerType
.compare(L1S("Wave"), Qt::CaseInsensitive
) == 0)
227 if(formatType
.compare(L1S("PCM"), Qt::CaseInsensitive
) == 0)
232 else if(containerType
.compare(L1S("FLAC"), Qt::CaseInsensitive
) == 0)
234 if(formatType
.compare(L1S("FLAC"), Qt::CaseInsensitive
) == 0)
243 void VorbisEncoder::setBitrateLimits(int minimumBitrate
, int maximumBitrate
)
245 m_configBitrateMinimum
= minimumBitrate
;
246 m_configBitrateMaximum
= maximumBitrate
;
249 const AbstractEncoderInfo
*VorbisEncoder::getEncoderInfo(void)
251 return &g_vorbisEncoderInfo
;