From 2878dc7ad005730072e11b00cba1d37cda8b081a Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Wed, 22 Aug 2012 23:52:55 +0200 Subject: [PATCH] Treat Wave files with IEEE Float (32-Bit) sample format separately from Wave files with 32-Bit Integer sample format. For example, the Opus encoder accepts 32-Bit IEEE Float just fine, but does NOT like 32-Bit Integer as input. --- src/Config.h | 2 +- src/Encoder_Opus.cpp | 3 ++- src/Model_AudioFile.cpp | 12 +++++++++- src/Model_AudioFile.h | 2 ++ src/Thread_FileAnalyzer_Task.cpp | 5 ++++ src/Thread_Process.cpp | 41 ++++++++++++++++++++++---------- src/Tool_WaveProperties.cpp | 2 +- 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/src/Config.h b/src/Config.h index 2b0ac4bd..4f26286a 100644 --- a/src/Config.h +++ b/src/Config.h @@ -30,7 +30,7 @@ #define VER_LAMEXP_MINOR_LO 5 #define VER_LAMEXP_TYPE RC #define VER_LAMEXP_PATCH 2 -#define VER_LAMEXP_BUILD 1096 +#define VER_LAMEXP_BUILD 1097 /////////////////////////////////////////////////////////////////////////////// // Tool versions (minimum expected versions!) diff --git a/src/Encoder_Opus.cpp b/src/Encoder_Opus.cpp index 11e27dd6..ef9ab38c 100644 --- a/src/Encoder_Opus.cpp +++ b/src/Encoder_Opus.cpp @@ -233,7 +233,8 @@ const unsigned int *OpusEncoder::supportedChannelCount(void) const unsigned int *OpusEncoder::supportedBitdepths(void) { - return NULL; + static const unsigned int supportedBPS[] = {8, 16, 24, AudioFileModel::BITDEPTH_IEEE_FLOAT32, NULL}; + return supportedBPS; } const bool OpusEncoder::needsTimingInfo(void) diff --git a/src/Model_AudioFile.cpp b/src/Model_AudioFile.cpp index 2e987a94..92911f86 100644 --- a/src/Model_AudioFile.cpp +++ b/src/Model_AudioFile.cpp @@ -25,9 +25,12 @@ #include #include #include +#include #define U16Str(X) QString::fromUtf16(reinterpret_cast(L##X)) +const unsigned int AudioFileModel::BITDEPTH_IEEE_FLOAT32 = UINT_MAX-1; + //////////////////////////////////////////////////////////// // Constructor & Destructor //////////////////////////////////////////////////////////// @@ -288,7 +291,14 @@ const QString AudioFileModel::formatAudioBaseInfo(void) const if(m_formatAudioBitdepth) { if(!info.isEmpty()) info.append(", "); - info.append(QString("%1: %2 Bit").arg(tr("Bitdepth"), QString::number(m_formatAudioBitdepth))); + if(m_formatAudioBitdepth == BITDEPTH_IEEE_FLOAT32) + { + info.append(QString("%1: %2 Bit (IEEE Float)").arg(tr("Bitdepth"), QString::number(32))); + } + else + { + info.append(QString("%1: %2 Bit").arg(tr("Bitdepth"), QString::number(m_formatAudioBitdepth))); + } } return info; } diff --git a/src/Model_AudioFile.h b/src/Model_AudioFile.h index 10376168..a5bf5c00 100644 --- a/src/Model_AudioFile.h +++ b/src/Model_AudioFile.h @@ -45,6 +45,8 @@ public: BitrateModeVariable = 2, }; + static const unsigned int BITDEPTH_IEEE_FLOAT32; + //----------------------- //Getters //----------------------- diff --git a/src/Thread_FileAnalyzer_Task.cpp b/src/Thread_FileAnalyzer_Task.cpp index 2b407527..cb806a2f 100644 --- a/src/Thread_FileAnalyzer_Task.cpp +++ b/src/Thread_FileAnalyzer_Task.cpp @@ -339,6 +339,11 @@ const AudioFileModel AnalyzeTask::analyzeFile(const QString &filePath, int *type retrieveCover(audioFile, coverType, coverData); } + if((audioFile.formatAudioType().compare("PCM", Qt::CaseInsensitive) == 0) && (audioFile.formatAudioProfile().compare("Float", Qt::CaseInsensitive) == 0)) + { + if(audioFile.formatAudioBitdepth() == 32) audioFile.setFormatAudioBitdepth(AudioFileModel::BITDEPTH_IEEE_FLOAT32); + } + return audioFile; } diff --git a/src/Thread_Process.cpp b/src/Thread_Process.cpp index db6fa687..5d5a31f7 100644 --- a/src/Thread_Process.cpp +++ b/src/Thread_Process.cpp @@ -444,25 +444,40 @@ void ProcessThread::insertDownsampleFilter(void) /* Adjust bit depth (word size) */ if(m_encoder->supportedBitdepths() && m_audioFile.formatAudioBitdepth()) { - const unsigned int *supportedBPS = m_encoder->supportedBitdepths(); const unsigned int inputBPS = m_audioFile.formatAudioBitdepth(); - unsigned int currentDiff = UINT_MAX, minimumDiff = UINT_MAX, bestBPS = UINT_MAX; + const unsigned int *supportedBPS = m_encoder->supportedBitdepths(); - //Find the most suitable supported bit depth + bool bAdjustBitdepth = true; + + //Is the input bit depth supported exactly? (inclduing IEEE Float) for(int i = 0; supportedBPS[i]; i++) { - currentDiff = DIFF(inputBPS, supportedBPS[i]); - if((currentDiff < minimumDiff) || ((currentDiff == minimumDiff) && (bestBPS < supportedBPS[i]))) - { - bestBPS = supportedBPS[i]; - minimumDiff = currentDiff; - if(!(minimumDiff > 0)) break; - } + if(supportedBPS[i] == inputBPS) bAdjustBitdepth = false; } - - if(bestBPS != inputBPS) + + if(bAdjustBitdepth) { - targetBitDepth = (bestBPS != UINT_MAX) ? bestBPS : supportedBPS[0]; + unsigned int currentDiff = UINT_MAX, minimumDiff = UINT_MAX, bestBPS = UINT_MAX; + const unsigned int originalBPS = (inputBPS == AudioFileModel::BITDEPTH_IEEE_FLOAT32) ? 32 : inputBPS; + + //Find the most suitable supported bit depth + for(int i = 0; supportedBPS[i]; i++) + { + if(supportedBPS[i] == AudioFileModel::BITDEPTH_IEEE_FLOAT32) continue; + + currentDiff = DIFF(originalBPS, supportedBPS[i]); + if((currentDiff < minimumDiff) || ((currentDiff == minimumDiff) && (bestBPS < supportedBPS[i]))) + { + bestBPS = supportedBPS[i]; + minimumDiff = currentDiff; + if(!(minimumDiff > 0)) break; + } + } + + if(bestBPS != originalBPS) + { + targetBitDepth = (bestBPS != UINT_MAX) ? bestBPS : supportedBPS[0]; + } } } diff --git a/src/Tool_WaveProperties.cpp b/src/Tool_WaveProperties.cpp index ff2b1f9e..d7335485 100644 --- a/src/Tool_WaveProperties.cpp +++ b/src/Tool_WaveProperties.cpp @@ -96,7 +96,7 @@ bool WaveProperties::detect(const QString &sourceFile, AudioFileModel *info, vol { bool ok = false; unsigned int tmp = regExp_encoding.cap(1).toUInt(&ok); - if(ok) info->setFormatAudioBitdepth(tmp); + if(ok) info->setFormatAudioBitdepth((tmp == 32) ? AudioFileModel::BITDEPTH_IEEE_FLOAT32 : tmp); emit statusUpdated(qMin(progress += 25, 100)); } if(regExp_samplerate.lastIndexIn(text) >= 0)