From 2ad5c3068dcde786fa0d31b3d0e92a0bddcd73fd Mon Sep 17 00:00:00 2001 From: lordmulder Date: Wed, 21 Dec 2011 01:23:21 +0100 Subject: [PATCH] Prepare to support audio encoders that only support specific bit-depths. --- src/Config.h | 2 +- src/Encoder_AC3.cpp | 2 +- src/Encoder_AC3.h | 2 +- src/Encoder_Abstract.cpp | 8 +++++++- src/Encoder_Abstract.h | 3 ++- src/Thread_Process.cpp | 41 +++++++++++++++++++++++++++------------- src/Thread_Process.h | 1 + 7 files changed, 41 insertions(+), 18 deletions(-) diff --git a/src/Config.h b/src/Config.h index 49b17eec..6cb62bc1 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 11 -#define VER_LAMEXP_BUILD 822 +#define VER_LAMEXP_BUILD 823 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Encoder_AC3.cpp b/src/Encoder_AC3.cpp index ed2a126a..ed9cb60f 100644 --- a/src/Encoder_AC3.cpp +++ b/src/Encoder_AC3.cpp @@ -179,7 +179,7 @@ QString AC3Encoder::extension(void) return "ac3"; } -const unsigned int *AC3Encoder::requiresDownsample(void) +const unsigned int *AC3Encoder::supportedSamplerates(void) { static const unsigned int supportedRates[] = {48000, 44100, 32000, NULL}; return supportedRates; diff --git a/src/Encoder_AC3.h b/src/Encoder_AC3.h index 9ff1b018..d6649fcb 100644 --- a/src/Encoder_AC3.h +++ b/src/Encoder_AC3.h @@ -36,7 +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 *requiresDownsample(void); + virtual const unsigned int *supportedSamplerates(void); //Advanced options virtual void setAudioCodingMode(int value); diff --git a/src/Encoder_Abstract.cpp b/src/Encoder_Abstract.cpp index 67dea371..e23e5dc5 100644 --- a/src/Encoder_Abstract.cpp +++ b/src/Encoder_Abstract.cpp @@ -53,7 +53,13 @@ bool AbstractEncoder::requiresDownmix(void) } // Does encoder require the input to be downsampled? (NULL-terminated array of supported sampling rates) -const unsigned int *AbstractEncoder::requiresDownsample(void) +const unsigned int *AbstractEncoder::supportedSamplerates(void) +{ + return NULL; +} + +// What bitdepths does the encoder support as input? (NULL-terminated array of supported bits per sample) +const unsigned int *AbstractEncoder::supportedBitdepths(void) { return NULL; } diff --git a/src/Encoder_Abstract.h b/src/Encoder_Abstract.h index 6b6cd102..d34ae5e8 100644 --- a/src/Encoder_Abstract.h +++ b/src/Encoder_Abstract.h @@ -41,7 +41,8 @@ public: virtual bool isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) = 0; virtual QString extension(void) = 0; virtual bool requiresDownmix(void); - virtual const unsigned int *requiresDownsample(void); + virtual const unsigned int *supportedSamplerates(void); + virtual const unsigned int *supportedBitdepths(void); //Common setter methods void setBitrate(int bitrate); diff --git a/src/Thread_Process.cpp b/src/Thread_Process.cpp index 2a6a1a3d..864a2986 100644 --- a/src/Thread_Process.cpp +++ b/src/Thread_Process.cpp @@ -128,18 +128,6 @@ void ProcessThread::processFile() return; } - //Do we need to take care of downsampling the input? - if(m_encoder->requiresDownsample()) - { - insertDownsampleFilter(); - } - - //Do we need Stereo downmix? - if(m_encoder->requiresDownmix()) - { - insertDownmixFilter(); - } - QString sourceFile = m_audioFile.filePath(); //Decode source file @@ -173,6 +161,28 @@ void ProcessThread::processFile() } } + //Check audio properties + if(bSuccess) + { + //Do we need to take care of downsampling the input? + if(m_encoder->supportedSamplerates()) + { + insertDownsampleFilter(); + } + + //Do we need to change the bits per sample of the input? + if(m_encoder->supportedBitdepths()) + { + insertBitdepthFilter(); + } + + //Do we need Stereo downmix? + if(m_encoder->requiresDownmix()) + { + insertDownmixFilter(); + } + } + //Apply all audio filters if(bSuccess) { @@ -370,7 +380,7 @@ void ProcessThread::insertDownsampleFilter(void) //Now add the downsampling filter, if needed if(applyDownsampling) { - const unsigned int *supportedRates = m_encoder->requiresDownsample(); + const unsigned int *supportedRates = m_encoder->supportedSamplerates(); const unsigned int inputRate = m_audioFile.formatAudioSamplerate(); unsigned int currentDiff = UINT_MAX, minimumDiff = UINT_MAX, bestRate = UINT_MAX; @@ -393,6 +403,11 @@ void ProcessThread::insertDownsampleFilter(void) } } +void ProcessThread::insertBitdepthFilter(void) +{ + qFatal("ProcessThread::insertBitdepthFilter not implemented yet!"); +} + void ProcessThread::insertDownmixFilter(void) { bool applyDownmixing = true; diff --git a/src/Thread_Process.h b/src/Thread_Process.h index 92787532..d34787cd 100644 --- a/src/Thread_Process.h +++ b/src/Thread_Process.h @@ -70,6 +70,7 @@ private: QString generateTempFileName(void); void insertDownsampleFilter(void); void insertDownmixFilter(void); + void insertBitdepthFilter(void); const QUuid m_jobId; AudioFileModel m_audioFile;