1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2023 LoRd_MuldeR <MuldeR2@GMX.de>
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; always including the non-optional
9 // LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "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_DCA.h"
26 #include "Model_Settings.h"
32 static int index2bitrate(const int index
)
34 return (index
< 8) ? ((index
+ 1) * 32) : ((index
< 12) ? ((index
- 3) * 64) : ((index
< 24) ? (index
- 7) * 128 : (index
- 15) * 256));
37 ///////////////////////////////////////////////////////////////////////////////
39 ///////////////////////////////////////////////////////////////////////////////
41 class DCAEncoderInfo
: public AbstractEncoderInfo
43 virtual bool isModeSupported(int mode
) const
47 case SettingsModel::VBRMode
:
48 case SettingsModel::ABRMode
:
51 case SettingsModel::CBRMode
:
55 MUTILS_THROW("Bad RC mode specified!");
59 virtual int valueCount(int mode
) const
63 case SettingsModel::VBRMode
:
64 case SettingsModel::ABRMode
:
67 case SettingsModel::CBRMode
:
71 MUTILS_THROW("Bad RC mode specified!");
75 virtual int valueAt(int mode
, int index
) const
79 case SettingsModel::VBRMode
:
80 case SettingsModel::ABRMode
:
83 case SettingsModel::CBRMode
:
84 return qBound(32, index2bitrate(index
), 4096);
87 MUTILS_THROW("Bad RC mode specified!");
91 virtual int valueType(int mode
) const
95 case SettingsModel::VBRMode
:
96 return TYPE_QUALITY_LEVEL_INT
;
98 case SettingsModel::ABRMode
:
99 case SettingsModel::CBRMode
:
103 MUTILS_THROW("Bad RC mode specified!");
107 virtual const char *description(void) const
109 static const char* s_description
= "dcaenc-2 by Alexander E. Patrakov";
110 return s_description
;
113 virtual const char *extension(void) const
115 static const char* s_extension
= "dts";
119 virtual bool isResamplingSupported(void) const
124 static const g_dcaEncoderInfo
;
126 ///////////////////////////////////////////////////////////////////////////////
127 // Encoder implementation
128 ///////////////////////////////////////////////////////////////////////////////
130 DCAEncoder::DCAEncoder(void)
132 m_binary(lamexp_tools_lookup(L1S("dcaenc.exe")))
134 if(m_binary
.isEmpty())
136 MUTILS_THROW("Error initializing DCA encoder. Tool 'dcaenc.exe' is not registred!");
140 DCAEncoder::~DCAEncoder(void)
144 bool DCAEncoder::encode(const QString
&sourceFile
, const AudioFileModel_MetaInfo
& /*metaInfo*/, const unsigned int /*duration*/, const unsigned int /*channels*/, const QString
&outputFile
, QAtomicInt
&abortFlag
)
149 args
<< L1S("-i") << QDir::toNativeSeparators(sourceFile
);
150 args
<< L1S("-o") << QDir::toNativeSeparators(outputFile
);
151 args
<< L1S("-b") << QString::number(qBound(32, index2bitrate(m_configBitrate
), 4096));
153 if(!startProcess(process
, m_binary
, args
))
158 int prevProgress
= -1;
159 QRegExp
regExp(L1S("\\[(\\d+)\\.(\\d+)%\\]"));
161 const result_t result
= awaitProcess(process
, abortFlag
, [this, &prevProgress
, ®Exp
](const QString
&text
)
163 if (regExp
.lastIndexIn(text
) >= 0)
166 if (MUtils::regexp_parse_int32(regExp
, newProgress
))
168 if (newProgress
> prevProgress
)
170 emit
statusUpdated(newProgress
);
171 prevProgress
= NEXT_PROGRESS(newProgress
);
179 return (result
== RESULT_SUCCESS
);
182 bool DCAEncoder::isFormatSupported(const QString
&containerType
, const QString
& /*containerProfile*/, const QString
&formatType
, const QString
& /*formatProfile*/, const QString
& /*formatVersion*/)
184 if(containerType
.compare(L1S("Wave"), Qt::CaseInsensitive
) == 0)
186 if(formatType
.compare(L1S("PCM"), Qt::CaseInsensitive
) == 0)
195 const unsigned int *DCAEncoder::supportedChannelCount(void)
197 static const unsigned int supportedChannels
[] = {1, 2, 4, 5, 6, NULL
};
198 return supportedChannels
;
201 const unsigned int *DCAEncoder::supportedSamplerates(void)
203 static const unsigned int supportedRates
[] = {48000, 44100, 32000, 24000, 22050, 16000, 12000, 11025, 8000, NULL
};
204 return supportedRates
;
207 const unsigned int *DCAEncoder::supportedBitdepths(void)
209 static const unsigned int supportedBPS
[] = {16, 32, NULL
};
213 const AbstractEncoderInfo
*DCAEncoder::getEncoderInfo(void)
215 return &g_dcaEncoderInfo
;