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_DCA.h"
25 #include "Model_Settings.h"
31 static int index2bitrate(const int index
)
33 return (index
< 8) ? ((index
+ 1) * 32) : ((index
< 12) ? ((index
- 3) * 64) : ((index
< 24) ? (index
- 7) * 128 : (index
- 15) * 256));
36 ///////////////////////////////////////////////////////////////////////////////
38 ///////////////////////////////////////////////////////////////////////////////
40 class DCAEncoderInfo
: public AbstractEncoderInfo
42 virtual bool isModeSupported(int mode
) const
46 case SettingsModel::VBRMode
:
47 case SettingsModel::ABRMode
:
50 case SettingsModel::CBRMode
:
54 throw "Bad RC mode specified!";
58 virtual int valueCount(int mode
) const
62 case SettingsModel::VBRMode
:
63 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 case SettingsModel::ABRMode
:
82 case SettingsModel::CBRMode
:
83 return qBound(32, index2bitrate(index
), 4096);
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 case SettingsModel::CBRMode
:
102 throw "Bad RC mode specified!";
106 virtual const char *description(void) const
108 static const char* s_description
= "dcaenc-2 by Alexander E. Patrakov";
109 return s_description
;
112 static const g_dcaEncoderInfo
;
114 ///////////////////////////////////////////////////////////////////////////////
115 // Encoder implementation
116 ///////////////////////////////////////////////////////////////////////////////
118 DCAEncoder::DCAEncoder(void)
120 m_binary(lamexp_lookup_tool("dcaenc.exe"))
122 if(m_binary
.isEmpty())
124 throw "Error initializing DCA encoder. Tool 'dcaenc.exe' is not registred!";
128 DCAEncoder::~DCAEncoder(void)
132 bool DCAEncoder::encode(const QString
&sourceFile
, const AudioFileModel_MetaInfo
&metaInfo
, const unsigned int duration
, const QString
&outputFile
, volatile bool *abortFlag
)
137 args
<< "-i" << QDir::toNativeSeparators(sourceFile
);
138 args
<< "-o" << QDir::toNativeSeparators(outputFile
);
139 args
<< "-b" << QString::number(qBound(32, index2bitrate(m_configBitrate
), 4096));
141 if(!startProcess(process
, m_binary
, args
))
146 bool bTimeout
= false;
147 bool bAborted
= false;
148 int prevProgress
= -1;
150 QRegExp
regExp("\\[(\\d+)\\.(\\d+)%\\]");
152 while(process
.state() != QProcess::NotRunning
)
158 emit
messageLogged("\nABORTED BY USER !!!");
161 process
.waitForReadyRead(m_processTimeoutInterval
);
162 if(!process
.bytesAvailable() && process
.state() == QProcess::Running
)
165 qWarning("DCAENC process timed out <-- killing!");
166 emit
messageLogged("\nPROCESS TIMEOUT !!!");
170 while(process
.bytesAvailable() > 0)
172 QByteArray line
= process
.readLine();
173 QString text
= QString::fromUtf8(line
.constData()).simplified();
174 if(regExp
.lastIndexIn(text
) >= 0)
177 int progress
= regExp
.cap(1).toInt(&ok
);
178 if(ok
&& (progress
> prevProgress
))
180 emit
statusUpdated(progress
);
181 prevProgress
= qMin(progress
+ 2, 99);
184 else if(!text
.isEmpty())
186 emit
messageLogged(text
);
191 process
.waitForFinished();
192 if(process
.state() != QProcess::NotRunning
)
195 process
.waitForFinished(-1);
198 emit
statusUpdated(100);
199 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", process
.exitCode()));
201 if(bTimeout
|| bAborted
|| process
.exitCode() != EXIT_SUCCESS
)
209 QString
DCAEncoder::extension(void)
214 bool DCAEncoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
216 if(containerType
.compare("Wave", Qt::CaseInsensitive
) == 0)
218 if(formatType
.compare("PCM", Qt::CaseInsensitive
) == 0)
227 const unsigned int *DCAEncoder::supportedChannelCount(void)
229 static const unsigned int supportedChannels
[] = {1, 2, 4, 5, 6, NULL
};
230 return supportedChannels
;
233 const unsigned int *DCAEncoder::supportedSamplerates(void)
235 static const unsigned int supportedRates
[] = {48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, NULL
};
236 return supportedRates
;
239 const unsigned int *DCAEncoder::supportedBitdepths(void)
241 static const unsigned int supportedBPS
[] = {16, 32, NULL
};
245 const AbstractEncoderInfo
*DCAEncoder::getEncoderInfo(void)
247 return &g_dcaEncoderInfo
;