From 3f0796d2886ff9beb734012678456698d7599f57 Mon Sep 17 00:00:00 2001 From: lordmulder Date: Fri, 21 Jan 2011 23:25:55 +0100 Subject: [PATCH] Added support for bitrate management to LAME and OggEnc2 encoders. --- etc/Translation/Blank.ts | 16 +++++++++++++ etc/Translation/LameXP_DE.ts | 34 ++++++++++++++++++++------- etc/Translation/LameXP_ES.ts | 16 +++++++++++++ etc/Translation/LameXP_FR.ts | 16 +++++++++++++ etc/Translation/LameXP_IT.ts | 16 +++++++++++++ gui/MainWindow.ui | 3 ++- res/localization/LameXP_DE.qm | Bin 42727 -> 44142 bytes src/Config.h | 2 +- src/Dialog_Processing.cpp | 8 +++++++ src/Encoder_MP3.cpp | 43 ++++++++++++++++++++++++++++++++++ src/Encoder_MP3.h | 6 +++++ src/Encoder_Vorbis.cpp | 15 ++++++++++++ src/Encoder_Vorbis.h | 4 ++++ 13 files changed, 168 insertions(+), 11 deletions(-) diff --git a/etc/Translation/Blank.ts b/etc/Translation/Blank.ts index e6ab29c9..85558098 100644 --- a/etc/Translation/Blank.ts +++ b/etc/Translation/Blank.ts @@ -413,6 +413,22 @@ Better quality + + Bitrate Management (LAME and OggEnc2) + + + + Enable Bitrate Management + + + + Minimum (kbps): + + + + Maximum (kbps): + + Encode Now! diff --git a/etc/Translation/LameXP_DE.ts b/etc/Translation/LameXP_DE.ts index 2fac9d0c..e47f569b 100644 --- a/etc/Translation/LameXP_DE.ts +++ b/etc/Translation/LameXP_DE.ts @@ -157,7 +157,7 @@ The True Audio - Lossless Audio Codec - + @@ -896,35 +896,51 @@ LAME Algorithm Quality - + LAME Algorithmus Qualität Faster Processing - + Schnellere Verarbeitung Better quality - + Bessere Qualität Best Quality (Very Slow) - + Beste Qualität (Sehr Langsam) High Quality (Recommended) - + Höhere Qualität (Empfohlen) Average Quality (Default) - + Mittlere Qualität (Standard) Low Quality (Fast) - + Niedrige Qualität (Schnell) Poor Quality (Very Fast) - + Miese Qualität (Sehr Schnell) + + + Bitrate Management (LAME and OggEnc2) + Bitraten Verwaltung (LAME und OggEnc2) + + + Enable Bitrate Management + Bitraten Verwaltung Aktivieren + + + Minimum (kbps): + Minimum (kbps): + + + Maximum (kbps): + Maximum (kbps): diff --git a/etc/Translation/LameXP_ES.ts b/etc/Translation/LameXP_ES.ts index e3b0db4a..63f03e9d 100644 --- a/etc/Translation/LameXP_ES.ts +++ b/etc/Translation/LameXP_ES.ts @@ -926,6 +926,22 @@ Poor Quality (Very Fast) + + Bitrate Management (LAME and OggEnc2) + + + + Enable Bitrate Management + + + + Minimum (kbps): + + + + Maximum (kbps): + + MetaInfo diff --git a/etc/Translation/LameXP_FR.ts b/etc/Translation/LameXP_FR.ts index e8a3af9f..de4113e1 100644 --- a/etc/Translation/LameXP_FR.ts +++ b/etc/Translation/LameXP_FR.ts @@ -930,6 +930,22 @@ Votre dossier TEMP est situé ici: Poor Quality (Very Fast) + + Bitrate Management (LAME and OggEnc2) + + + + Enable Bitrate Management + + + + Minimum (kbps): + + + + Maximum (kbps): + + MetaInfo diff --git a/etc/Translation/LameXP_IT.ts b/etc/Translation/LameXP_IT.ts index d7d98e33..702a4557 100644 --- a/etc/Translation/LameXP_IT.ts +++ b/etc/Translation/LameXP_IT.ts @@ -926,6 +926,22 @@ Poor Quality (Very Fast) + + Bitrate Management (LAME and OggEnc2) + + + + Enable Bitrate Management + + + + Minimum (kbps): + + + + Maximum (kbps): + + MetaInfo diff --git a/gui/MainWindow.ui b/gui/MainWindow.ui index e534e418..dfc051aa 100644 --- a/gui/MainWindow.ui +++ b/gui/MainWindow.ui @@ -1120,7 +1120,7 @@ - Bitrate Management + Bitrate Management (LAME and OggEnc2) @@ -1700,6 +1700,7 @@ + diff --git a/res/localization/LameXP_DE.qm b/res/localization/LameXP_DE.qm index 98b7e6046be0690016dc95c97b192661b4ce2b23..46ecf0ccc1e052aef1a481922c8f2c54be28f6ee 100644 GIT binary patch delta 3841 zcma)9cU+WL7CkfbebbALh!Ai@QLtB3M5G8xv4J8sbc7L57<3p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kW0b8k~e`O`6-o~je4)v%rqemaL*rtLTebs~Mb2v>dX9eK41=59AZ*vH2p13r?P;;6PEXTCDM@Y zTjtJd=F93|mWWb*qu#POZl*geHP^B8lFPV28fz(WBoaPemd~%u zAOZ$U_0|pSRBySkkF)e&W%*U70{IX4n)tLp$CS3Y;ik7Mt}A&q6&3wX>2o{!|5oAe z8m3esetBitrate(m_settings->compressionBitrate()); mp3Encoder->setRCMode(m_settings->compressionRCMode()); mp3Encoder->setAlgoQuality(m_settings->lameAlgoQuality()); + if(m_settings->bitrateManagementEnabled()) + { + mp3Encoder->setBitrateLimits(m_settings->bitrateManagementMinRate(), m_settings->bitrateManagementMaxRate()); + } encoder = mp3Encoder; } break; @@ -444,6 +448,10 @@ void ProcessingDialog::startNextJob(void) VorbisEncoder *vorbisEncoder = new VorbisEncoder(); vorbisEncoder->setBitrate(m_settings->compressionBitrate()); vorbisEncoder->setRCMode(m_settings->compressionRCMode()); + if(m_settings->bitrateManagementEnabled()) + { + vorbisEncoder->setBitrateLimits(m_settings->bitrateManagementMinRate(), m_settings->bitrateManagementMaxRate()); + } encoder = vorbisEncoder; } break; diff --git a/src/Encoder_MP3.cpp b/src/Encoder_MP3.cpp index 27b4930b..4d223b49 100644 --- a/src/Encoder_MP3.cpp +++ b/src/Encoder_MP3.cpp @@ -42,6 +42,8 @@ MP3Encoder::MP3Encoder(void) } m_algorithmQuality = 3; + m_configBitrateMaximum = 0; + m_configBitrateMinimum = 0; } MP3Encoder::~MP3Encoder(void) @@ -73,6 +75,15 @@ bool MP3Encoder::encode(const QString &sourceFile, const AudioFileModel &metaInf break; } + if((m_configBitrateMaximum > 0) && (m_configBitrateMinimum > 0) && (m_configBitrateMinimum <= m_configBitrateMaximum)) + { + if(m_configRCMode != SettingsModel::CBRMode) + { + args << "-b" << QString::number(clipBitrate(m_configBitrateMinimum)); + args << "-B" << QString::number(clipBitrate(m_configBitrateMaximum)); + } + } + if(!metaInfo.fileName().isEmpty()) args << (IS_UNICODE(metaInfo.fileName()) ? "--uTitle" : "--lTitle") << metaInfo.fileName(); if(!metaInfo.fileArtist().isEmpty()) args << (IS_UNICODE(metaInfo.fileArtist()) ? "--uArtist" : "--lArtist") << metaInfo.fileArtist(); if(!metaInfo.fileAlbum().isEmpty()) args << (IS_UNICODE(metaInfo.fileAlbum()) ? "--uAlbum" : "--lAlbum") << metaInfo.fileAlbum(); @@ -188,3 +199,35 @@ void MP3Encoder::setAlgoQuality(int value) { m_algorithmQuality = value; } + +void MP3Encoder::setBitrateLimits(int minimumBitrate, int maximumBitrate) +{ + m_configBitrateMinimum = minimumBitrate; + m_configBitrateMaximum = maximumBitrate; +} + +int MP3Encoder::clipBitrate(int bitrate) +{ + int targetBitrate = min(max(bitrate, 32), 320); + + int minDiff = INT_MAX; + int minIndx = -1; + + for(int i = 0; SettingsModel::mp3Bitrates[i] > 0; i++) + { + int currentDiff = abs(targetBitrate - SettingsModel::mp3Bitrates[i]); + if(currentDiff < minDiff) + { + minDiff = currentDiff; + minIndx = i; + } + } + + if(minIndx >= 0) + { + return SettingsModel::mp3Bitrates[minIndx]; + } + + return targetBitrate; +} + diff --git a/src/Encoder_MP3.h b/src/Encoder_MP3.h index e5b12369..9079b3fd 100644 --- a/src/Encoder_MP3.h +++ b/src/Encoder_MP3.h @@ -40,8 +40,14 @@ public: //Advanced options virtual void setAlgoQuality(int value); + virtual void setBitrateLimits(int minimumBitrate, int maximumBitrate); + private: const QString m_binary; int m_algorithmQuality; + int m_configBitrateMaximum; + int m_configBitrateMinimum; + + int clipBitrate(int bitrate); }; diff --git a/src/Encoder_Vorbis.cpp b/src/Encoder_Vorbis.cpp index bfd96590..6bc17fb1 100644 --- a/src/Encoder_Vorbis.cpp +++ b/src/Encoder_Vorbis.cpp @@ -41,6 +41,9 @@ VorbisEncoder::VorbisEncoder(void) { throw "Error initializing Vorbis encoder. Tool 'oggenc2.exe' is not registred!"; } + + m_configBitrateMaximum = 0; + m_configBitrateMinimum = 0; } VorbisEncoder::~VorbisEncoder(void) @@ -68,6 +71,12 @@ bool VorbisEncoder::encode(const QString &sourceFile, const AudioFileModel &meta break; } + if((m_configBitrateMaximum > 0) && (m_configBitrateMinimum > 0) && (m_configBitrateMinimum <= m_configBitrateMaximum)) + { + args << "--min-bitrate" << QString::number(min(max(m_configBitrateMinimum, 32), 500)); + args << "--max-bitrate" << QString::number(min(max(m_configBitrateMaximum, 32), 500)); + } + if(!metaInfo.fileName().isEmpty()) args << "-t" << metaInfo.fileName(); if(!metaInfo.fileArtist().isEmpty()) args << "-a" << metaInfo.fileArtist(); if(!metaInfo.fileAlbum().isEmpty()) args << "-l" << metaInfo.fileAlbum(); @@ -167,3 +176,9 @@ bool VorbisEncoder::isFormatSupported(const QString &containerType, const QStrin return false; } + +void VorbisEncoder::setBitrateLimits(int minimumBitrate, int maximumBitrate) +{ + m_configBitrateMinimum = minimumBitrate; + m_configBitrateMaximum = maximumBitrate; +} diff --git a/src/Encoder_Vorbis.h b/src/Encoder_Vorbis.h index 80e64f1f..71f5185b 100644 --- a/src/Encoder_Vorbis.h +++ b/src/Encoder_Vorbis.h @@ -36,9 +36,13 @@ 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 void setBitrateLimits(int minimumBitrate, int maximumBitrate); private: const QString m_binary_i386; const QString m_binary_sse2; const QString m_binary_x64; + int m_configBitrateMaximum; + int m_configBitrateMinimum; + };