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 "Tool_WaveProperties.h"
27 #include "Model_AudioFile.h"
30 #include <MUtils/Exception.h>
36 WaveProperties::WaveProperties(void)
38 m_binary(lamexp_tools_lookup("sox.exe"))
40 if(m_binary.isEmpty())
42 MUTILS_THROW("Error initializing MP3 encoder. Tool 'lame.exe' is not registred!");
46 WaveProperties::~WaveProperties(void)
50 bool WaveProperties::detect(const QString &sourceFile, AudioFileModel_TechInfo *info, QAtomicInt &abortFlag)
55 args << "--i" << QDir::toNativeSeparators(sourceFile);
57 if(!startProcess(process, m_binary, args))
64 QRegExp regExp_prc("Precision\\s*:\\s*(\\d+)-bit", Qt::CaseInsensitive);
65 QRegExp regExp_srt("Sample Rate\\s*:\\s*(\\d+)", Qt::CaseInsensitive);
66 QRegExp regExp_drt("Duration\\s*:\\s*(\\d\\d):(\\d\\d):(\\d\\d)\\.(\\d\\d)", Qt::CaseInsensitive);
67 QRegExp regExp_chl("Channels\\s*:\\s*(\\d+)", Qt::CaseInsensitive);
68 QRegExp regExp_enc("Sample Encoding\\s*:\\s*(\\d+)-bit\\s*Float", Qt::CaseInsensitive); //SoX returns a precision of 24-Bit for 32-Bit Float data, so we detect it this way!
70 const result_t result = awaitProcess(process, abortFlag, [this, &info, &progress, ®Exp_prc, ®Exp_srt, ®Exp_drt, ®Exp_chl, ®Exp_enc](const QString &text)
72 if (regExp_prc.lastIndexIn(text) >= 0)
75 if (MUtils::regexp_parse_uint32(regExp_prc, tmp))
77 info->setAudioBitdepth(tmp);
78 emit statusUpdated(qMin(progress += 25, 100));
82 if (regExp_enc.lastIndexIn(text) >= 0)
85 if (MUtils::regexp_parse_uint32(regExp_enc, tmp))
87 info->setAudioBitdepth((tmp == 32) ? AudioFileModel::BITDEPTH_IEEE_FLOAT32 : tmp);
88 emit statusUpdated(qMin(progress += 25, 100));
92 if (regExp_srt.lastIndexIn(text) >= 0)
95 if (MUtils::regexp_parse_uint32(regExp_srt, tmp))
97 info->setAudioSamplerate(tmp);
98 emit statusUpdated(qMin(progress += 25, 100));
102 if (regExp_drt.lastIndexIn(text) >= 0)
105 if (MUtils::regexp_parse_uint32(regExp_drt, tmp, 4))
107 info->setDuration((tmp[0] * 3600) + (tmp[1] * 60) + tmp[2] + qRound(static_cast<double>(tmp[3]) / 100.0));
108 emit statusUpdated(qMin(progress += 25, 100));
112 if (regExp_chl.lastIndexIn(text) >= 0)
115 if (MUtils::regexp_parse_uint32(regExp_chl, tmp))
117 info->setAudioChannels(tmp);
118 emit statusUpdated(qMin(progress += 25, 100));
125 return (result == RESULT_SUCCESS);