Implemented new "adaptive" Opus bitrate LUT.
[LameXP.git] / src / Encoder_Abstract.cpp
blob11d62a0bfa71f51424447409a18984c7ac0e376d
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2018 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Encoder_Abstract.h"
25 //Internal
26 #include "Global.h"
28 //MUtils
29 #include <MUtils/Global.h>
31 AbstractEncoder::AbstractEncoder(void)
33 m_configBitrate = 0;
34 m_configRCMode = 0;
35 m_configCustomParams.clear();
36 m_configSamplingRate = 0;
39 AbstractEncoder::~AbstractEncoder(void)
45 * Setters
48 void AbstractEncoder::setRCMode(const int &mode)
50 if (!toEncoderInfo()->isModeSupported(qMax(0, mode)))
52 MUTILS_THROW("This RC mode is not supported by the encoder!");
54 m_configRCMode = qMax(0, mode);
55 m_configBitrate = qBound(0, m_configBitrate, toEncoderInfo()->valueCount(m_configRCMode) - 1);
58 void AbstractEncoder::setBitrate(const int &bitrate)
60 const int valueCount = toEncoderInfo()->valueCount(m_configRCMode);
61 if ((valueCount > 0) && (qMax(0, bitrate) >= valueCount))
63 MUTILS_THROW("The specified bitrate/quality is out of range!");
65 m_configBitrate = qMax(0, bitrate);
68 void AbstractEncoder::setCustomParams(const QString &customParams)
70 m_configCustomParams = customParams.trimmed();
73 void AbstractEncoder::setSamplingRate(const int &value)
75 if (!toEncoderInfo()->isResamplingSupported())
77 MUTILS_THROW("This encoder does *not* support native resampling!");
79 m_configSamplingRate = qBound(0, value, 48000);
84 * Default implementation
87 // Does encoder require the input to be downmixed to stereo?
88 const unsigned int *AbstractEncoder::supportedChannelCount(void)
90 return NULL;
93 // Does encoder require the input to be downsampled? (NULL-terminated array of supported sampling rates)
94 const unsigned int *AbstractEncoder::supportedSamplerates(void)
96 return NULL;
99 // What bitdepths does the encoder support as input? (NULL-terminated array of supported bits per sample)
100 const unsigned int *AbstractEncoder::supportedBitdepths(void)
102 return NULL;
105 //Does the encoder need the exact duration of the source?
106 const bool AbstractEncoder::needsTimingInfo(void)
108 return false;
113 * Helper functions
116 //Does this text contain Non-ASCII characters?
117 bool AbstractEncoder::isUnicode(const QString &original)
119 if(!original.isEmpty())
121 QString asLatin1 = QString::fromLatin1(original.toLatin1().constData());
122 return (wcscmp(MUTILS_WCHR(original), MUTILS_WCHR(asLatin1)) != 0);
124 return false;
127 //Remove "problematic" characters from tag
128 QString AbstractEncoder::cleanTag(const QString &text)
130 QString result(text);
131 result.replace(QChar('"'), "'");
132 result.replace(QChar('\\'), "/");
133 return result;