Fixed QAAC built-in resampling + improved QAAC encoder detection.
[LameXP.git] / src / Encoder_Abstract.cpp
blob5ba3049180da220edbe25e020aea71e5c6fe8570
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2016 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)
44 * Setters
47 void AbstractEncoder::setRCMode(const int &mode)
49 if (!toEncoderInfo()->isModeSupported(qMax(0, mode)))
51 MUTILS_THROW("This RC mode is not supported by the encoder!");
53 m_configRCMode = qMax(0, mode);
56 void AbstractEncoder::setBitrate(const int &bitrate)
58 if (qMax(0, bitrate) >= toEncoderInfo()->valueCount(m_configRCMode))
60 MUTILS_THROW("The specified bitrate/quality is out of range!");
62 m_configBitrate = qMax(0, bitrate);
65 void AbstractEncoder::setCustomParams(const QString &customParams)
67 m_configCustomParams = customParams.trimmed();
70 void AbstractEncoder::setSamplingRate(const int &value)
72 if (!toEncoderInfo()->isResamplingSupported())
74 MUTILS_THROW("This encoder does *not* support native resampling!");
76 m_configSamplingRate = qBound(0, value, 48000);
81 * Default implementation
84 // Does encoder require the input to be downmixed to stereo?
85 const unsigned int *AbstractEncoder::supportedChannelCount(void)
87 return NULL;
90 // Does encoder require the input to be downsampled? (NULL-terminated array of supported sampling rates)
91 const unsigned int *AbstractEncoder::supportedSamplerates(void)
93 return NULL;
96 // What bitdepths does the encoder support as input? (NULL-terminated array of supported bits per sample)
97 const unsigned int *AbstractEncoder::supportedBitdepths(void)
99 return NULL;
102 //Does the encoder need the exact duration of the source?
103 const bool AbstractEncoder::needsTimingInfo(void)
105 return false;
110 * Helper functions
113 //Does this text contain Non-ASCII characters?
114 bool AbstractEncoder::isUnicode(const QString &original)
116 if(!original.isEmpty())
118 QString asLatin1 = QString::fromLatin1(original.toLatin1().constData());
119 return (wcscmp(MUTILS_WCHR(original), MUTILS_WCHR(asLatin1)) != 0);
121 return false;
124 //Remove "problematic" characters from tag
125 QString AbstractEncoder::cleanTag(const QString &text)
127 QString result(text);
128 result.replace(QChar('"'), "'");
129 result.replace(QChar('\\'), "/");
130 return result;