From d9784f5b6e7345812b1ef8505567823d811cde2b Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 13 Nov 2016 20:09:29 +0100 Subject: [PATCH] Small code clean-up. --- src/Encoder_AAC.cpp | 28 +++++++++++++++++----------- src/Filter_Downmix.cpp | 6 ++++-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/src/Encoder_AAC.cpp b/src/Encoder_AAC.cpp index 5db4e192..5faba06e 100644 --- a/src/Encoder_AAC.cpp +++ b/src/Encoder_AAC.cpp @@ -33,6 +33,8 @@ static int index2bitrate(const int index) return (index < 32) ? ((index + 1) * 8) : ((index - 15) * 16); } +#define IS_VALID(X) (((X) != 0U) && ((X) != UINT_MAX)) + /////////////////////////////////////////////////////////////////////////////// // Encoder Info /////////////////////////////////////////////////////////////////////////////// @@ -171,8 +173,18 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo args << L1S("-2pass"); } - switch(m_configProfile) + int selectedProfile = m_configProfile; + if ((selectedProfile == 3) && IS_VALID(channels) && (channels != 2)) { + emit messageLogged("WARNING: Cannot use HE-AAC v2 (SBR+PS) with Mono input --> reverting to HE-AAC (SBR)"); + selectedProfile = 2; + } + + switch(selectedProfile) + { + case 0: + //Do *not* overwrite profile -> let the encoder decide! + break; case 1: args << L1S("-lc"); //Forces use of LC AAC profile break; @@ -180,16 +192,10 @@ bool AACEncoder::encode(const QString &sourceFile, const AudioFileModel_MetaInfo args << L1S("-he"); //Forces use of HE AAC profile break; case 3: - if ((channels == 0) || (channels == 2)) - { - args << L1S("-hev2"); //Forces use of HEv2 AAC profile - } - else - { - emit messageLogged("WARNING: Cannot use HE-AAC v2 (SBR+PS) with Non-Stereo input --> reverting to HE-AAC (SBR)"); - args << L1S("-he"); //Forces use of HE AAC profile - } + args << L1S("-hev2"); //Forces use of HEv2 AAC profile break; + default: + MUTILS_THROW("Bad AAC Profile specified!"); } if(!m_configCustomParams.isEmpty()) args << m_configCustomParams.split(" ", QString::SkipEmptyParts); @@ -384,7 +390,7 @@ bool AACEncoder::isFormatSupported(const QString &containerType, const QString & void AACEncoder::setProfile(int profile) { - m_configProfile = profile; + m_configProfile = qBound(0, profile, 3); } void AACEncoder::setEnable2Pass(bool enabled) diff --git a/src/Filter_Downmix.cpp b/src/Filter_Downmix.cpp index e0b04dd6..36374e02 100644 --- a/src/Filter_Downmix.cpp +++ b/src/Filter_Downmix.cpp @@ -35,6 +35,8 @@ #include #include +#define IS_VALID(X) (((X) != 0U) && ((X) != UINT_MAX)) + DownmixFilter::DownmixFilter(void) : m_binary(lamexp_tools_lookup("sox.exe")) @@ -51,10 +53,10 @@ DownmixFilter::~DownmixFilter(void) AbstractFilter::FilterResult DownmixFilter::apply(const QString &sourceFile, const QString &outputFile, AudioFileModel_TechInfo *const formatInfo, volatile bool *abortFlag) { - unsigned int channels = formatInfo->audioChannels(); //detectChannels(sourceFile, abortFlag); + unsigned int channels = formatInfo->audioChannels(); emit messageLogged(QString().sprintf("--> Number of channels is: %d\n", channels)); - if((channels != 0) && (channels <= 2)) + if(IS_VALID(channels) && (channels <= 2)) { messageLogged("Skipping downmix!"); qDebug("Dowmmix not required/possible for Mono or Stereo input, skipping!");