1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2014 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_AAC_FHG.h"
26 #include "Model_Settings.h"
32 static int index2bitrate(const int index
)
34 return (index
< 32) ? ((index
+ 1) * 8) : ((index
- 15) * 16);
37 ///////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
41 class FHGAACEncoderInfo
: public AbstractEncoderInfo
43 virtual bool isModeSupported(int mode
) const
47 case SettingsModel::VBRMode
:
48 case SettingsModel::CBRMode
:
51 case SettingsModel::ABRMode
:
55 THROW("Bad RC mode specified!");
59 virtual int valueCount(int mode
) const
63 case SettingsModel::VBRMode
:
66 case SettingsModel::ABRMode
:
67 case SettingsModel::CBRMode
:
71 THROW("Bad RC mode specified!");
75 virtual int valueAt(int mode
, int index
) const
79 case SettingsModel::VBRMode
:
80 return qBound(1, index
+ 1, 6);
82 case SettingsModel::ABRMode
:
83 case SettingsModel::CBRMode
:
84 return qBound(8, index2bitrate(index
), 576);
87 THROW("Bad RC mode specified!");
91 virtual int valueType(int mode
) const
95 case SettingsModel::VBRMode
:
96 return TYPE_QUALITY_LEVEL_INT
;
98 case SettingsModel::ABRMode
:
99 return TYPE_APPROX_BITRATE
;
101 case SettingsModel::CBRMode
:
105 THROW("Bad RC mode specified!");
109 virtual const char *description(void) const
111 static const char* s_description
= "fhgaacenc/Winamp (\x0C2\x0A9 Nullsoft)";
112 return s_description
;
115 static const g_fhgAacEncoderInfo
;
117 ///////////////////////////////////////////////////////////////////////////////
118 // Encoder implementation
119 ///////////////////////////////////////////////////////////////////////////////
121 FHGAACEncoder::FHGAACEncoder(void)
123 m_binary_enc(lamexp_lookup_tool("fhgaacenc.exe")),
124 m_binary_dll(lamexp_lookup_tool("enc_fhgaac.dll"))
126 if(m_binary_enc
.isEmpty() || m_binary_dll
.isEmpty())
128 THROW("Error initializing FhgAacEnc. Tool 'fhgaacenc.exe' is not registred!");
134 FHGAACEncoder::~FHGAACEncoder(void)
138 bool FHGAACEncoder::encode(const QString
&sourceFile
, const AudioFileModel_MetaInfo
&metaInfo
, const unsigned int duration
, const QString
&outputFile
, volatile bool *abortFlag
)
143 int maxBitrate
= 576;
145 if(m_configRCMode
== SettingsModel::CBRMode
)
147 switch(m_configProfile
)
150 args
<< "--profile" << "lc"; //Forces use of LC AAC profile
154 args
<< "--profile" << "he"; //Forces use of HE AAC profile
158 args
<< "--profile" << "hev2"; //Forces use of HEv2 AAC profile
163 switch(m_configRCMode
)
165 case SettingsModel::CBRMode
:
166 args
<< "--cbr" << QString::number(qBound(8, index2bitrate(m_configBitrate
), maxBitrate
));
168 case SettingsModel::VBRMode
:
169 args
<< "--vbr" << QString::number(qBound(1, m_configBitrate
+ 1, 6));
172 THROW("Bad rate-control mode!");
176 args
<< "--dll" << m_binary_dll
;
178 if(!m_configCustomParams
.isEmpty()) args
<< m_configCustomParams
.split(" ", QString::SkipEmptyParts
);
180 args
<< QDir::toNativeSeparators(sourceFile
);
181 args
<< QDir::toNativeSeparators(outputFile
);
183 if(!startProcess(process
, m_binary_enc
, args
))
188 bool bTimeout
= false;
189 bool bAborted
= false;
190 int prevProgress
= -1;
192 QRegExp
regExp("Progress:\\s*(\\d+)%");
194 while(process
.state() != QProcess::NotRunning
)
200 emit
messageLogged("\nABORTED BY USER !!!");
203 process
.waitForReadyRead(m_processTimeoutInterval
);
204 if(!process
.bytesAvailable() && process
.state() == QProcess::Running
)
207 qWarning("FhgAacEnc process timed out <-- killing!");
208 emit
messageLogged("\nPROCESS TIMEOUT !!!");
212 while(process
.bytesAvailable() > 0)
214 QByteArray line
= process
.readLine();
215 QString text
= QString::fromUtf8(line
.constData()).simplified();
216 if(regExp
.lastIndexIn(text
) >= 0)
219 int progress
= regExp
.cap(1).toInt(&ok
);
220 if(ok
&& (progress
> prevProgress
))
222 emit
statusUpdated(progress
);
223 prevProgress
= qMin(progress
+ 2, 99);
226 else if(!text
.isEmpty())
228 emit
messageLogged(text
);
233 process
.waitForFinished();
234 if(process
.state() != QProcess::NotRunning
)
237 process
.waitForFinished(-1);
240 emit
statusUpdated(100);
241 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", process
.exitCode()));
243 if(bTimeout
|| bAborted
|| process
.exitCode() != EXIT_SUCCESS
)
251 QString
FHGAACEncoder::extension(void)
256 bool FHGAACEncoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
258 if(containerType
.compare("Wave", Qt::CaseInsensitive
) == 0)
260 if(formatType
.compare("PCM", Qt::CaseInsensitive
) == 0)
269 const unsigned int *FHGAACEncoder::supportedChannelCount(void)
271 static const unsigned int supportedChannels
[] = {1, 2, 4, 5, 6, NULL
};
272 return supportedChannels
;
275 const unsigned int *FHGAACEncoder::supportedSamplerates(void)
277 static const unsigned int supportedRates
[] = {192000, 96000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 6000, NULL
};
278 return supportedRates
;
281 const unsigned int *FHGAACEncoder::supportedBitdepths(void)
283 static const unsigned int supportedBPS
[] = {16, 24, NULL
};
287 void FHGAACEncoder::setProfile(int profile
)
289 m_configProfile
= profile
;
292 const AbstractEncoderInfo
*FHGAACEncoder::getEncoderInfo(void)
294 return &g_fhgAacEncoderInfo
;