OSDN Git Service

In Downmix filter: Choose the "remix" parameters based on the number of input channels.
authorlordmulder <mulder2@gmx.de>
Sun, 7 Aug 2011 02:06:03 +0000 (04:06 +0200)
committerlordmulder <mulder2@gmx.de>
Sun, 7 Aug 2011 02:06:03 +0000 (04:06 +0200)
src/Config.h
src/Filter_Downmix.cpp
src/Filter_Downmix.h

index 24fbc6e..32d6bb6 100644 (file)
@@ -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
index 23e168a..88b0ca7 100644 (file)
@@ -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;
+}
index 7f706e8..294f7d4 100644 (file)
@@ -33,4 +33,5 @@ public:
 
 private:
        const QString m_binary;
+       unsigned int detectChannels(const QString &sourceFile, volatile bool *abortFlag);
 };