From 3f4be5c846d5b63bb07ccae984a5b923da51ec7c Mon Sep 17 00:00:00 2001 From: lordmulder Date: Sun, 1 Jan 2012 21:31:48 +0100 Subject: [PATCH] Fixed AC-3 encoding with sources that have more than 6 channels. --- src/Config.h | 2 +- src/Encoder_AC3.cpp | 6 ++++ src/Encoder_AC3.h | 1 + src/Filter_Abstract.h | 4 ++- src/Filter_Downmix.cpp | 73 ++++----------------------------------- src/Filter_Downmix.h | 5 +-- src/Filter_Normalize.cpp | 2 +- src/Filter_Normalize.h | 2 +- src/Filter_Resample.cpp | 13 ++++++- src/Filter_Resample.h | 2 +- src/Filter_ToneAdjust.cpp | 2 +- src/Filter_ToneAdjust.h | 2 +- src/Thread_Process.cpp | 4 +-- 13 files changed, 39 insertions(+), 79 deletions(-) diff --git a/src/Config.h b/src/Config.h index e59f06ac..1523d77a 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 4 #define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_PATCH 13 -#define VER_LAMEXP_BUILD 862 +#define VER_LAMEXP_BUILD 865 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Encoder_AC3.cpp b/src/Encoder_AC3.cpp index 3126a58d..20257647 100644 --- a/src/Encoder_AC3.cpp +++ b/src/Encoder_AC3.cpp @@ -179,6 +179,12 @@ QString AC3Encoder::extension(void) return "ac3"; } +const unsigned int *AC3Encoder::supportedChannelCount(void) +{ + static const unsigned int supportedChannels[] = {1, 2, 3, 4, 5, 6, NULL}; + return supportedChannels; +} + const unsigned int *AC3Encoder::supportedSamplerates(void) { static const unsigned int supportedRates[] = {48000, 44100, 32000, NULL}; diff --git a/src/Encoder_AC3.h b/src/Encoder_AC3.h index d6649fcb..ed778dbe 100644 --- a/src/Encoder_AC3.h +++ b/src/Encoder_AC3.h @@ -36,6 +36,7 @@ public: virtual bool encode(const QString &sourceFile, const AudioFileModel &metaInfo, const QString &outputFile, volatile bool *abortFlag); virtual bool isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion); virtual QString extension(void); + virtual const unsigned int *supportedChannelCount(void); virtual const unsigned int *supportedSamplerates(void); //Advanced options diff --git a/src/Filter_Abstract.h b/src/Filter_Abstract.h index fb8a9ccd..40d1faea 100644 --- a/src/Filter_Abstract.h +++ b/src/Filter_Abstract.h @@ -23,6 +23,8 @@ #include "Tool_Abstract.h" +class AudioFileModel; + class AbstractFilter : public AbstractTool { Q_OBJECT @@ -32,6 +34,6 @@ public: ~AbstractFilter(void); //Internal decoder API - virtual bool apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) = 0; + virtual bool apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag) = 0; }; diff --git a/src/Filter_Downmix.cpp b/src/Filter_Downmix.cpp index 4cf61a00..20acfaa8 100644 --- a/src/Filter_Downmix.cpp +++ b/src/Filter_Downmix.cpp @@ -22,6 +22,8 @@ #include "Filter_Downmix.h" #include "Global.h" +#include "Tool_WaveProperties.h" +#include "Model_AudioFile.h" #include #include @@ -41,16 +43,16 @@ DownmixFilter::~DownmixFilter(void) { } -bool DownmixFilter::apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) +bool DownmixFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag) { - unsigned int channels = detectChannels(sourceFile, abortFlag); + unsigned int channels = formatInfo->formatAudioChannels(); //detectChannels(sourceFile, abortFlag); emit messageLogged(QString().sprintf("--> Number of channels is: %d\n", channels)); if((channels == 1) || (channels == 2)) { messageLogged("Skipping downmix!"); qDebug("Dowmmix not required for Mono or Stereo input, skipping!"); - return false; + return true; } QProcess process; @@ -152,69 +154,6 @@ bool DownmixFilter::apply(const QString &sourceFile, const QString &outputFile, return false; } + formatInfo->setFormatAudioChannels(2); 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 294f7d4a..79afb8e9 100644 --- a/src/Filter_Downmix.h +++ b/src/Filter_Downmix.h @@ -23,15 +23,16 @@ #include "Filter_Abstract.h" +class WaveProperties; + class DownmixFilter : public AbstractFilter { public: DownmixFilter(void); ~DownmixFilter(void); - virtual bool apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag); + virtual bool apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag); private: const QString m_binary; - unsigned int detectChannels(const QString &sourceFile, volatile bool *abortFlag); }; diff --git a/src/Filter_Normalize.cpp b/src/Filter_Normalize.cpp index b6baf610..a39e9fdb 100644 --- a/src/Filter_Normalize.cpp +++ b/src/Filter_Normalize.cpp @@ -44,7 +44,7 @@ NormalizeFilter::~NormalizeFilter(void) { } -bool NormalizeFilter::apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) +bool NormalizeFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag) { QProcess process; QStringList args; diff --git a/src/Filter_Normalize.h b/src/Filter_Normalize.h index 8bbc57cc..c69e9cce 100644 --- a/src/Filter_Normalize.h +++ b/src/Filter_Normalize.h @@ -29,7 +29,7 @@ public: NormalizeFilter(int peakVolume = -50, int equalizationMode = 0); ~NormalizeFilter(void); - virtual bool apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag); + virtual bool apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag); private: const QString m_binary; diff --git a/src/Filter_Resample.cpp b/src/Filter_Resample.cpp index 929768e2..b33dc750 100644 --- a/src/Filter_Resample.cpp +++ b/src/Filter_Resample.cpp @@ -22,6 +22,7 @@ #include "Filter_Resample.h" #include "Global.h" +#include "Model_AudioFile.h" #include #include @@ -54,11 +55,18 @@ ResampleFilter::~ResampleFilter(void) { } -bool ResampleFilter::apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) +bool ResampleFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag) { QProcess process; QStringList args; + if((m_samplingRate == formatInfo->formatAudioSamplerate()) && (m_bitDepth == formatInfo->formatAudioBitdepth())) + { + messageLogged("Skipping resample filter!"); + qDebug("Resampling filter target samplerate/bitdepth is equals to the format of the input file, skipping!"); + return true; + } + process.setWorkingDirectory(QFileInfo(outputFile).canonicalPath()); args << "-V3" << "-S"; @@ -145,5 +153,8 @@ bool ResampleFilter::apply(const QString &sourceFile, const QString &outputFile, return false; } + if(m_samplingRate) formatInfo->setFormatAudioSamplerate(m_samplingRate); + if(m_bitDepth) formatInfo->setFormatAudioBitdepth(m_bitDepth); + return true; } diff --git a/src/Filter_Resample.h b/src/Filter_Resample.h index 87a82cb8..ca46bd8e 100644 --- a/src/Filter_Resample.h +++ b/src/Filter_Resample.h @@ -29,7 +29,7 @@ public: ResampleFilter(int samplingRate = 0, int bitDepth = 0); ~ResampleFilter(void); - virtual bool apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag); + virtual bool apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag); private: const QString m_binary; diff --git a/src/Filter_ToneAdjust.cpp b/src/Filter_ToneAdjust.cpp index 24080434..233d3e48 100644 --- a/src/Filter_ToneAdjust.cpp +++ b/src/Filter_ToneAdjust.cpp @@ -45,7 +45,7 @@ ToneAdjustFilter::~ToneAdjustFilter(void) { } -bool ToneAdjustFilter::apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag) +bool ToneAdjustFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag) { QProcess process; QStringList args; diff --git a/src/Filter_ToneAdjust.h b/src/Filter_ToneAdjust.h index 7236c7c5..40521568 100644 --- a/src/Filter_ToneAdjust.h +++ b/src/Filter_ToneAdjust.h @@ -29,7 +29,7 @@ public: ToneAdjustFilter(int bass = 0, int treble = 0); ~ToneAdjustFilter(void); - virtual bool apply(const QString &sourceFile, const QString &outputFile, volatile bool *abortFlag); + virtual bool apply(const QString &sourceFile, const QString &outputFile, AudioFileModel *formatInfo, volatile bool *abortFlag); private: const QString m_binary; diff --git a/src/Thread_Process.cpp b/src/Thread_Process.cpp index bc688aa6..3f09030d 100644 --- a/src/Thread_Process.cpp +++ b/src/Thread_Process.cpp @@ -177,7 +177,7 @@ void ProcessThread::processFile() //------------------------------------ if(bSuccess && !m_aborted && IS_WAVE(m_audioFile)) { - if(m_encoder->supportedSamplerates() || m_encoder->supportedBitdepths() || m_encoder->supportedChannelCount()) + if(m_encoder->supportedSamplerates() || m_encoder->supportedBitdepths() || m_encoder->supportedChannelCount() || !m_filters.isEmpty()) { m_currentStep = AnalyzeStep; bSuccess = m_propDetect->detect(sourceFile, &m_audioFile, &m_aborted); @@ -215,7 +215,7 @@ void ProcessThread::processFile() connect(poFilter, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection); connect(poFilter, SIGNAL(messageLogged(QString)), this, SLOT(handleMessage(QString)), Qt::DirectConnection); - if(poFilter->apply(sourceFile, tempFile, &m_aborted)) + if(poFilter->apply(sourceFile, tempFile, &m_audioFile, &m_aborted)) { sourceFile = tempFile; }