Bump version.
[LameXP.git] / src / Decoder_ADPCM.cpp
blob58463048c55befcc700e1ffcb34c61ba8c672cea
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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 "Decoder_ADPCM.h"
25 //Internal
26 #include "Global.h"
28 //MUtils
29 #include <MUtils/Exception.h>
31 //Qt
32 #include <QDir>
33 #include <QProcess>
34 #include <QRegExp>
36 ADPCMDecoder::ADPCMDecoder(void)
38 m_binary(lamexp_tools_lookup("sox.exe"))
40 if(m_binary.isEmpty())
42 MUTILS_THROW("Error initializing Vorbis decoder. Tool 'sox.exe' is not registred!");
46 ADPCMDecoder::~ADPCMDecoder(void)
50 bool ADPCMDecoder::decode(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag)
52 QProcess process;
53 QStringList args;
55 process.setWorkingDirectory(QFileInfo(outputFile).canonicalPath());
57 args << "-V3" << "-S" << "--temp" << ".";
58 args << QDir::toNativeSeparators(sourceFile);
59 args << "-e" << "signed-integer";
60 args << QDir::toNativeSeparators(outputFile);
62 if(!startProcess(process, m_binary, args))
64 return false;
67 bool bTimeout = false;
68 bool bAborted = false;
70 QRegExp regExp("In:(\\d+)(\\.\\d+)*%");
72 while(process.state() != QProcess::NotRunning)
74 if(*abortFlag)
76 process.kill();
77 bAborted = true;
78 emit messageLogged("\nABORTED BY USER !!!");
79 break;
81 process.waitForReadyRead(m_processTimeoutInterval);
82 if(!process.bytesAvailable() && process.state() == QProcess::Running)
84 process.kill();
85 qWarning("Sox process timed out <-- killing!");
86 emit messageLogged("\nPROCESS TIMEOUT !!!");
87 bTimeout = true;
88 break;
90 while(process.bytesAvailable() > 0)
92 QByteArray line = process.readLine();
93 QString text = QString::fromUtf8(line.constData()).simplified();
94 if(regExp.lastIndexIn(text) >= 0)
96 bool ok = false;
97 int progress = regExp.cap(1).toInt(&ok);
98 if(ok) emit statusUpdated(progress);
100 else if(!text.isEmpty())
102 emit messageLogged(text);
107 process.waitForFinished();
108 if(process.state() != QProcess::NotRunning)
110 process.kill();
111 process.waitForFinished(-1);
114 emit statusUpdated(100);
115 emit messageLogged(QString().sprintf("\nExited with code: 0x%04X", process.exitCode()));
117 if(bTimeout || bAborted || process.exitCode() != EXIT_SUCCESS || QFileInfo(outputFile).size() == 0)
119 return false;
122 return true;
125 bool ADPCMDecoder::isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
127 if(containerType.compare("Wave", Qt::CaseInsensitive) == 0)
129 if(formatType.compare("ADPCM", Qt::CaseInsensitive) == 0)
131 return true;
135 if(containerType.compare("AIFF", Qt::CaseInsensitive) == 0 || containerType.compare("AU", Qt::CaseInsensitive) == 0)
137 if(formatType.compare("PCM", Qt::CaseInsensitive) == 0 || formatType.compare("ADPCM", Qt::CaseInsensitive) == 0)
139 return true;
143 return false;
146 const AbstractDecoder::supportedType_t *ADPCMDecoder::supportedTypes(void)
148 static const char *exts[][3] =
150 { "wav", NULL },
151 { "aif", "aiff", NULL },
152 { "au" , "snd", NULL }
155 static const supportedType_t s_supportedTypes[] =
157 { "Microsoft ADPCM", exts[0] },
158 { "Apple/SGI AIFF", exts[1] },
159 { "Sun/NeXT Au", exts[2] },
160 { NULL, NULL }
163 return s_supportedTypes;