1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Encoder_AAC_FHG.h"
25 #include "Model_Settings.h"
31 static int index2bitrate(const int index
)
33 return (index
< 32) ? ((index
+ 1) * 8) : ((index
- 15) * 16);
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
40 class FHGAACEncoderInfo
: public AbstractEncoderInfo
42 virtual bool isModeSupported(int mode
) const
46 case SettingsModel::VBRMode
:
47 case SettingsModel::CBRMode
:
50 case SettingsModel::ABRMode
:
54 throw "Bad RC mode specified!";
58 virtual int valueCount(int mode
) const
62 case SettingsModel::VBRMode
:
65 case SettingsModel::ABRMode
:
66 case SettingsModel::CBRMode
:
70 throw "Bad RC mode specified!";
74 virtual int valueAt(int mode
, int index
) const
78 case SettingsModel::VBRMode
:
79 return qBound(1, index
+ 1, 6);
81 case SettingsModel::ABRMode
:
82 case SettingsModel::CBRMode
:
83 return qBound(8, index2bitrate(index
), 576);
86 throw "Bad RC mode specified!";
90 virtual int valueType(int mode
) const
94 case SettingsModel::VBRMode
:
95 return TYPE_QUALITY_LEVEL_INT
;
97 case SettingsModel::ABRMode
:
98 return TYPE_APPROX_BITRATE
;
100 case SettingsModel::CBRMode
:
104 throw "Bad RC mode specified!";
108 virtual const char *description(void) const
110 static const char* s_description
= "fhgaacenc/Winamp (\x0C2\x0A9 Nullsoft)";
111 return s_description
;
114 static const g_fhgAacEncoderInfo
;
116 ///////////////////////////////////////////////////////////////////////////////
117 // Encoder implementation
118 ///////////////////////////////////////////////////////////////////////////////
120 FHGAACEncoder::FHGAACEncoder(void)
122 m_binary_enc(lamexp_lookup_tool("fhgaacenc.exe")),
123 m_binary_dll(lamexp_lookup_tool("enc_fhgaac.dll"))
125 if(m_binary_enc
.isEmpty() || m_binary_dll
.isEmpty())
127 throw "Error initializing FhgAacEnc. Tool 'fhgaacenc.exe' is not registred!";
133 FHGAACEncoder::~FHGAACEncoder(void)
137 bool FHGAACEncoder::encode(const QString
&sourceFile
, const AudioFileModel_MetaInfo
&metaInfo
, const unsigned int duration
, const QString
&outputFile
, volatile bool *abortFlag
)
142 int maxBitrate
= 576;
144 if(m_configRCMode
== SettingsModel::CBRMode
)
146 switch(m_configProfile
)
149 args
<< "--profile" << "lc"; //Forces use of LC AAC profile
153 args
<< "--profile" << "he"; //Forces use of HE AAC profile
157 args
<< "--profile" << "hev2"; //Forces use of HEv2 AAC profile
162 switch(m_configRCMode
)
164 case SettingsModel::CBRMode
:
165 args
<< "--cbr" << QString::number(qBound(8, index2bitrate(m_configBitrate
), maxBitrate
));
167 case SettingsModel::VBRMode
:
168 args
<< "--vbr" << QString::number(qBound(1, m_configBitrate
+ 1, 6));
171 throw "Bad rate-control mode!";
175 args
<< "--dll" << m_binary_dll
;
177 if(!m_configCustomParams
.isEmpty()) args
<< m_configCustomParams
.split(" ", QString::SkipEmptyParts
);
179 args
<< QDir::toNativeSeparators(sourceFile
);
180 args
<< QDir::toNativeSeparators(outputFile
);
182 if(!startProcess(process
, m_binary_enc
, args
))
187 bool bTimeout
= false;
188 bool bAborted
= false;
189 int prevProgress
= -1;
191 QRegExp
regExp("Progress:\\s*(\\d+)%");
193 while(process
.state() != QProcess::NotRunning
)
199 emit
messageLogged("\nABORTED BY USER !!!");
202 process
.waitForReadyRead(m_processTimeoutInterval
);
203 if(!process
.bytesAvailable() && process
.state() == QProcess::Running
)
206 qWarning("FhgAacEnc process timed out <-- killing!");
207 emit
messageLogged("\nPROCESS TIMEOUT !!!");
211 while(process
.bytesAvailable() > 0)
213 QByteArray line
= process
.readLine();
214 QString text
= QString::fromUtf8(line
.constData()).simplified();
215 if(regExp
.lastIndexIn(text
) >= 0)
218 int progress
= regExp
.cap(1).toInt(&ok
);
219 if(ok
&& (progress
> prevProgress
))
221 emit
statusUpdated(progress
);
222 prevProgress
= qMin(progress
+ 2, 99);
225 else if(!text
.isEmpty())
227 emit
messageLogged(text
);
232 process
.waitForFinished();
233 if(process
.state() != QProcess::NotRunning
)
236 process
.waitForFinished(-1);
239 emit
statusUpdated(100);
240 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", process
.exitCode()));
242 if(bTimeout
|| bAborted
|| process
.exitCode() != EXIT_SUCCESS
)
250 QString
FHGAACEncoder::extension(void)
255 bool FHGAACEncoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
257 if(containerType
.compare("Wave", Qt::CaseInsensitive
) == 0)
259 if(formatType
.compare("PCM", Qt::CaseInsensitive
) == 0)
268 const unsigned int *FHGAACEncoder::supportedChannelCount(void)
270 static const unsigned int supportedChannels
[] = {1, 2, 4, 5, 6, NULL
};
271 return supportedChannels
;
274 const unsigned int *FHGAACEncoder::supportedSamplerates(void)
276 static const unsigned int supportedRates
[] = {192000, 96000, 48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, 6000, NULL
};
277 return supportedRates
;
280 const unsigned int *FHGAACEncoder::supportedBitdepths(void)
282 static const unsigned int supportedBPS
[] = {16, 24, NULL
};
286 void FHGAACEncoder::setProfile(int profile
)
288 m_configProfile
= profile
;
291 const AbstractEncoderInfo
*FHGAACEncoder::getEncoderInfo(void)
293 return &g_fhgAacEncoderInfo
;