1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2012 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 DCAEncoder::DCAEncoder(void)
33 m_binary(lamexp_lookup_tool("dcaenc.exe"))
35 if(m_binary
.isEmpty())
37 throw "Error initializing DCA encoder. Tool 'dcaenc.exe' is not registred!";
41 DCAEncoder::~DCAEncoder(void)
45 bool DCAEncoder::encode(const QString
&sourceFile
, const AudioFileModel
&metaInfo
, const QString
&outputFile
, volatile bool *abortFlag
)
50 int bitrate
= qBound(32, m_configBitrate
* 32, 6144);
52 args
<< "-i" << QDir::toNativeSeparators(sourceFile
);
53 args
<< "-o" << QDir::toNativeSeparators(outputFile
);
54 args
<< "-b" << QString::number(bitrate
);
56 if(!startProcess(process
, m_binary
, args
))
61 bool bTimeout
= false;
62 bool bAborted
= false;
63 int prevProgress
= -1;
65 QRegExp
regExp("\\[(\\d+)\\.(\\d+)%\\]");
67 while(process
.state() != QProcess::NotRunning
)
73 emit
messageLogged("\nABORTED BY USER !!!");
76 process
.waitForReadyRead(m_processTimeoutInterval
);
77 if(!process
.bytesAvailable() && process
.state() == QProcess::Running
)
80 qWarning("DCAENC process timed out <-- killing!");
81 emit
messageLogged("\nPROCESS TIMEOUT !!!");
85 while(process
.bytesAvailable() > 0)
87 QByteArray line
= process
.readLine();
88 QString text
= QString::fromUtf8(line
.constData()).simplified();
89 if(regExp
.lastIndexIn(text
) >= 0)
92 int progress
= regExp
.cap(1).toInt(&ok
);
93 if(ok
&& (progress
> prevProgress
))
95 emit
statusUpdated(progress
);
96 prevProgress
= qMin(progress
+ 2, 99);
99 else if(!text
.isEmpty())
101 emit
messageLogged(text
);
106 process
.waitForFinished();
107 if(process
.state() != QProcess::NotRunning
)
110 process
.waitForFinished(-1);
113 emit
statusUpdated(100);
114 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", process
.exitCode()));
116 if(bTimeout
|| bAborted
|| process
.exitCode() != EXIT_SUCCESS
)
124 QString
DCAEncoder::extension(void)
129 bool DCAEncoder::isFormatSupported(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
131 if(containerType
.compare("Wave", Qt::CaseInsensitive
) == 0)
133 if(formatType
.compare("PCM", Qt::CaseInsensitive
) == 0)
142 const unsigned int *DCAEncoder::supportedChannelCount(void)
144 static const unsigned int supportedChannels
[] = {1, 2, 4, 5, 6, NULL
};
145 return supportedChannels
;
148 const unsigned int *DCAEncoder::supportedSamplerates(void)
150 static const unsigned int supportedRates
[] = {48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, NULL
};
151 return supportedRates
;
154 const unsigned int *DCAEncoder::supportedBitdepths(void)
156 static const unsigned int supportedBPS
[] = {16, 32, NULL
};