1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2013 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.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License along
16 // with this program; if not, write to the Free Software Foundation, Inc.,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 // http://www.gnu.org/licenses/gpl-2.0.txt
20 ///////////////////////////////////////////////////////////////////////////////
22 #include "Tool_WaveProperties.h"
25 #include "Model_AudioFile.h"
29 WaveProperties::WaveProperties(void)
31 m_binary(lamexp_lookup_tool("sox.exe"))
33 if(m_binary
.isEmpty())
35 throw "Error initializing MP3 encoder. Tool 'lame.exe' is not registred!";
39 WaveProperties::~WaveProperties(void)
43 bool WaveProperties::detect(const QString
&sourceFile
, AudioFileModel
*info
, volatile bool *abortFlag
)
48 args
<< "--i" << sourceFile
;
50 if(!startProcess(process
, m_binary
, args
))
55 bool bTimeout
= false;
56 bool bAborted
= false;
60 QRegExp
regExp_precision("Precision\\s*:\\s*(\\d+)-bit", Qt::CaseInsensitive
);
61 QRegExp
regExp_samplerate("Sample Rate\\s*:\\s*(\\d+)", Qt::CaseInsensitive
);
62 QRegExp
regExp_duration("Duration\\s*:\\s*(\\d\\d):(\\d\\d):(\\d\\d)\\.(\\d\\d)", Qt::CaseInsensitive
);
63 QRegExp
regExp_channels("Channels\\s*:\\s*(\\d+)", Qt::CaseInsensitive
);
64 QRegExp
regExp_encoding("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!
66 while(process
.state() != QProcess::NotRunning
)
72 emit
messageLogged("\nABORTED BY USER !!!");
75 process
.waitForReadyRead(m_processTimeoutInterval
);
76 if(!process
.bytesAvailable() && process
.state() == QProcess::Running
)
79 qWarning("SoX process timed out <-- killing!");
80 emit
messageLogged("\nPROCESS TIMEOUT !!!");
84 while(process
.bytesAvailable() > 0)
86 QByteArray line
= process
.readLine();
87 QString text
= QString::fromUtf8(line
.constData()).simplified();
88 if(regExp_precision
.lastIndexIn(text
) >= 0)
91 unsigned int tmp
= regExp_precision
.cap(1).toUInt(&ok
);
92 if(ok
) info
->setFormatAudioBitdepth(tmp
);
93 emit
statusUpdated(qMin(progress
+= 25, 100));
95 if(regExp_encoding
.lastIndexIn(text
) >= 0)
98 unsigned int tmp
= regExp_encoding
.cap(1).toUInt(&ok
);
99 if(ok
) info
->setFormatAudioBitdepth((tmp
== 32) ? AudioFileModel::BITDEPTH_IEEE_FLOAT32
: tmp
);
100 emit
statusUpdated(qMin(progress
+= 25, 100));
102 if(regExp_samplerate
.lastIndexIn(text
) >= 0)
105 unsigned int tmp
= regExp_samplerate
.cap(1).toUInt(&ok
);
106 if(ok
) info
->setFormatAudioSamplerate(tmp
);
107 emit
statusUpdated(qMin(progress
+= 25, 100));
109 if(regExp_duration
.lastIndexIn(text
) >= 0)
111 bool ok
[4] = {false, false, false, false};
112 unsigned int tmp1
= regExp_duration
.cap(1).toUInt(&ok
[0]);
113 unsigned int tmp2
= regExp_duration
.cap(2).toUInt(&ok
[1]);
114 unsigned int tmp3
= regExp_duration
.cap(3).toUInt(&ok
[2]);
115 unsigned int tmp4
= regExp_duration
.cap(4).toUInt(&ok
[3]);
116 if(ok
[0] && ok
[1] && ok
[2] && ok
[3])
118 info
->setFileDuration((tmp1
* 3600) + (tmp2
* 60) + tmp3
+ qRound(static_cast<double>(tmp4
) / 100.0));
120 emit
statusUpdated(qMin(progress
+= 25, 100));
122 if(regExp_channels
.lastIndexIn(text
) >= 0)
125 unsigned int tmp
= regExp_channels
.cap(1).toUInt(&ok
);
126 if(ok
) info
->setFormatAudioChannels(tmp
);
127 emit
statusUpdated(qMin(progress
+= 25, 100));
131 emit
messageLogged(text
);
136 process
.waitForFinished();
137 if(process
.state() != QProcess::NotRunning
)
140 process
.waitForFinished(-1);
143 emit
statusUpdated(100);
144 emit
messageLogged(QString().sprintf("\nExited with code: 0x%04X", process
.exitCode()));
146 if(bTimeout
|| bAborted
|| process
.exitCode() != EXIT_SUCCESS
)