///////////////////////////////////////////////////////////////////////////////
// LameXP - Audio Encoder Front-End
-// Copyright (C) 2004-2011 LoRd_MuldeR <MuldeR2@GMX.de>
+// Copyright (C) 2004-2012 LoRd_MuldeR <MuldeR2@GMX.de>
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
if(bSuccess)
{
sourceFile = tempFile;
- handleMessage("\n-------------------------------\n");
m_audioFile.setFormatContainerType(QString::fromLatin1("Wave"));
m_audioFile.setFormatAudioType(QString::fromLatin1("PCM"));
+
+ if(QFileInfo(sourceFile).size() >= 4294967296i64)
+ {
+ handleMessage(tr("WARNING: Decoded file size exceeds 4 GB, problems might occur!\n"));
+ }
+
+ handleMessage("\n-------------------------------\n");
}
}
else
//------------------------------------
//Update audio properties after decode
//------------------------------------
- if(bSuccess && IS_WAVE(m_audioFile))
+ if(bSuccess && !m_aborted && IS_WAVE(m_audioFile))
{
- if(m_encoder->supportedSamplerates() || m_encoder->supportedBitdepths() || m_encoder->requiresDownmix())
+ if(m_encoder->supportedSamplerates() || m_encoder->supportedBitdepths() || m_encoder->supportedChannelCount() || m_encoder->needsTimingInfo() || !m_filters.isEmpty())
{
m_currentStep = AnalyzeStep;
bSuccess = m_propDetect->detect(sourceFile, &m_audioFile, &m_aborted);
handleMessage("\n-------------------------------\n");
//Do we need to take care if Stereo downmix?
- if(m_encoder->requiresDownmix())
+ if(m_encoder->supportedChannelCount())
{
insertDownmixFilter();
}
//-----------------------
if(bSuccess)
{
- while(!m_filters.isEmpty())
+ while(!m_filters.isEmpty() && !m_aborted)
{
QString tempFile = generateTempFileName();
AbstractFilter *poFilter = m_filters.takeFirst();
connect(poFilter, SIGNAL(statusUpdated(int)), this, SLOT(handleUpdate(int)), Qt::DirectConnection);
connect(poFilter, SIGNAL(messageLogged(QString)), this, SLOT(handleMessage(QString)), Qt::DirectConnection);
- if(poFilter->apply(sourceFile, tempFile, &m_aborted))
+ if(poFilter->apply(sourceFile, tempFile, &m_audioFile, &m_aborted))
{
sourceFile = tempFile;
}
//-----------------
//Encode audio file
//-----------------
- if(bSuccess)
+ if(bSuccess && !m_aborted)
{
m_currentStep = EncodingStep;
bSuccess = m_encoder->encode(sourceFile, m_audioFile, outFileName, &m_aborted);
}
//Make sure output file exists
- if(bSuccess)
+ if(bSuccess && !m_aborted)
{
QFileInfo fileInfo(outFileName);
bSuccess = fileInfo.exists() && fileInfo.isFile() && (fileInfo.size() > 0);
QThread::msleep(500);
//Report result
- emit processStateChanged(m_jobId, (bSuccess ? tr("Done.") : (m_aborted ? tr("Aborted!") : tr("Failed!"))), (bSuccess ? ProgressModel::JobComplete : ProgressModel::JobFailed));
+ emit processStateChanged(m_jobId, (m_aborted ? tr("Aborted!") : (bSuccess ? tr("Done.") : tr("Failed!"))), ((bSuccess && !m_aborted) ? ProgressModel::JobComplete : ProgressModel::JobFailed));
emit processStateFinished(m_jobId, outFileName, bSuccess);
qDebug("Process thread is done.");
/* Adjust bit depth (word size) */
if(m_encoder->supportedBitdepths() && m_audioFile.formatAudioBitdepth())
{
- const unsigned int *supportedBPS = m_encoder->supportedBitdepths();
const unsigned int inputBPS = m_audioFile.formatAudioBitdepth();
- unsigned int currentDiff = UINT_MAX, minimumDiff = UINT_MAX, bestBPS = UINT_MAX;
+ const unsigned int *supportedBPS = m_encoder->supportedBitdepths();
- //Find the most suitable supported bit depth
+ bool bAdjustBitdepth = true;
+
+ //Is the input bit depth supported exactly? (inclduing IEEE Float)
for(int i = 0; supportedBPS[i]; i++)
{
- currentDiff = DIFF(inputBPS, supportedBPS[i]);
- if((currentDiff < minimumDiff) || ((currentDiff == minimumDiff) && (bestBPS < supportedBPS[i])))
+ if(supportedBPS[i] == inputBPS) bAdjustBitdepth = false;
+ }
+
+ if(bAdjustBitdepth)
+ {
+ unsigned int currentDiff = UINT_MAX, minimumDiff = UINT_MAX, bestBPS = UINT_MAX;
+ const unsigned int originalBPS = (inputBPS == AudioFileModel::BITDEPTH_IEEE_FLOAT32) ? 32 : inputBPS;
+
+ //Find the most suitable supported bit depth
+ for(int i = 0; supportedBPS[i]; i++)
{
- bestBPS = supportedBPS[i];
- minimumDiff = currentDiff;
- if(!(minimumDiff > 0)) break;
+ if(supportedBPS[i] == AudioFileModel::BITDEPTH_IEEE_FLOAT32) continue;
+
+ currentDiff = DIFF(originalBPS, supportedBPS[i]);
+ if((currentDiff < minimumDiff) || ((currentDiff == minimumDiff) && (bestBPS < supportedBPS[i])))
+ {
+ bestBPS = supportedBPS[i];
+ minimumDiff = currentDiff;
+ if(!(minimumDiff > 0)) break;
+ }
}
- }
- if(bestBPS != inputBPS)
- {
- targetBitDepth = (bestBPS != UINT_MAX) ? bestBPS : supportedBPS[0];
+ if(bestBPS != originalBPS)
+ {
+ targetBitDepth = (bestBPS != UINT_MAX) ? bestBPS : supportedBPS[0];
+ }
}
}
if(dynamic_cast<DownmixFilter*>(m_filters.at(i)))
{
qWarning("Encoder requires Stereo downmix, but user has already forced downmix!");
+ handleMessage("WARNING: Encoder may need downmixning, but already using downmixning filter. Encoding *may* fail!\n");
applyDownmixing = false;
}
}
//Now add the downmixing filter, if needed
if(applyDownmixing)
{
+ bool requiresDownmix = true;
+ const unsigned int *supportedChannels = m_encoder->supportedChannelCount();
unsigned int channels = m_audioFile.formatAudioChannels();
- if((channels == 0) || (channels > 2))
+
+ for(int i = 0; supportedChannels[i]; i++)
+ {
+ if(supportedChannels[i] == channels)
+ {
+ requiresDownmix = false;
+ break;
+ }
+ }
+
+ if(requiresDownmix)
{
m_filters.append(new DownmixFilter());
}