diff --git a/src/Config.h b/src/Config.h index 24fbc6e2..32d6bb61 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 3 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 8 -#define VER_LAMEXP_BUILD 625 +#define VER_LAMEXP_BUILD 626 /////////////////////////////////////////////////////////////////////////////// // Tools versions diff --git a/src/Filter_Downmix.cpp b/src/Filter_Downmix.cpp index 23e168a1..88b0ca73 100644 --- a/src/Filter_Downmix.cpp +++ b/src/Filter_Downmix.cpp @@ -43,6 +43,9 @@ DownmixFilter::~DownmixFilter(void) bool DownmixFilter::apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) { + unsigned int channels = detectChannels(sourceFile, abortFlag); + emit messageLogged(QString().sprintf("--> Number of channels is: %d\n", channels)); + QProcess process; QStringList args; @@ -52,7 +55,28 @@ bool DownmixFilter::apply(const QString &sourceFile, const QString &outputFile, args << "--guard" << "--temp" << "."; args << QDir::toNativeSeparators(sourceFile); args << QDir::toNativeSeparators(outputFile); - args << "remix" << "1,3,4,5,7,9" << "2,3,4,6,8,9"; + + switch(channels) + { + case 3: + args << "remix" << "1,3" << "2,3"; + break; + case 4: + args << "remix" << "1,3,4" << "2,3,4"; + break; + case 6: + args << "remix" << "1,3,4,5" << "2,3,4,6"; + break; + case 8: + args << "remix" << "1,3,4,5,7" << "2,3,4,6,8"; + break; + case 9: + args << "remix" << "1,3,4,5,7,9" << "2,3,4,6,8,9"; + break; + default: + args << "channels" << "2"; + break; + } if(!startProcess(process, m_binary, args)) { @@ -116,3 +140,67 @@ bool DownmixFilter::apply(const QString &sourceFile, const QString &outputFile, return true; } + +unsigned int DownmixFilter::detectChannels(const QString &sourceFile, volatile bool *abortFlag) +{ + unsigned int channels = 0; + + QProcess process; + QStringList args; + + args << "--i" << sourceFile; + + if(!startProcess(process, m_binary, args)) + { + return channels; + } + + bool bTimeout = false; + bool bAborted = false; + + QRegExp regExp("Channels\\s*:\\s*(\\d+)", Qt::CaseInsensitive); + + while(process.state() != QProcess::NotRunning) + { + if(*abortFlag) + { + process.kill(); + bAborted = true; + emit messageLogged("\nABORTED BY USER !!!"); + break; + } + process.waitForReadyRead(m_processTimeoutInterval); + if(!process.bytesAvailable() && process.state() == QProcess::Running) + { + process.kill(); + qWarning("SoX process timed out <-- killing!"); + emit messageLogged("\nPROCESS TIMEOUT !!!"); + bTimeout = true; + break; + } + while(process.bytesAvailable() > 0) + { + QByteArray line = process.readLine(); + QString text = QString::fromUtf8(line.constData()).simplified(); + if(regExp.lastIndexIn(text) >= 0) + { + bool ok = false; + unsigned int temp = regExp.cap(1).toUInt(&ok); + if(ok) channels = temp; + } + if(!text.isEmpty()) + { + emit messageLogged(text); + } + } + } + + process.waitForFinished(); + if(process.state() != QProcess::NotRunning) + { + process.kill(); + process.waitForFinished(-1); + } + + return channels; +} diff --git a/src/Filter_Downmix.h b/src/Filter_Downmix.h index 7f706e89..294f7d4a 100644 --- a/src/Filter_Downmix.h +++ b/src/Filter_Downmix.h @@ -33,4 +33,5 @@ public: private: const QString m_binary; + unsigned int detectChannels(const QString &sourceFile, volatile bool *abortFlag); };