Skip to content

Commit

Permalink
- Loosened SMF and WAV detection constraints to account for different
Browse files Browse the repository at this point in the history
formats of WAV and a rare difference in bytes 0x5-0xB for SMF (the much
more common value is used when creating SMFs)
- Fixed a typo that caused the folder path chosen to note be resolved
when creating the error message for no SMF/WAV files found during batch
conversion, resulting in showing "%1" instead of the path
- Fixed a typo that caused the output SMF files during batch WAV->SMF
conversion to be incorrectly give the .wav extension
  • Loading branch information
oblivioncth committed May 11, 2020
1 parent c9ee010 commit cf6fd18
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 24 deletions.
6 changes: 3 additions & 3 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1364,7 +1364,7 @@ void MainWindow::all_on_menuAction_triggered()
if(smfList.isEmpty())
{
batchResult.setIcon(QMessageBox::Critical);
batchResult.setText(MSG_BATCH_SMF_NO_FILES);
batchResult.setText(MSG_BATCH_SMF_NO_FILES.arg(QDir::toNativeSeparators(smfFolderPath)));
}
else if(smfList.length() == failedConvList.length())
{
Expand Down Expand Up @@ -1467,7 +1467,7 @@ void MainWindow::all_on_menuAction_triggered()
{
WAV currentWAV(wavData);
QString smfOutPath = wavList.value(i).remove(wavFolderPath).prepend(smfFolderPath);
smfOutPath = smfOutPath.left(smfOutPath.length() - 3).append(WAV::FILE_EXT);
smfOutPath = smfOutPath.left(smfOutPath.length() - 3).append(SMF::FILE_EXT);

QFile smfOut(smfOutPath);

Expand Down Expand Up @@ -1529,7 +1529,7 @@ void MainWindow::all_on_menuAction_triggered()
if(wavList.isEmpty())
{
batchResult.setIcon(QMessageBox::Critical);
batchResult.setText(MSG_BATCH_WAV_NO_FILES);
batchResult.setText(MSG_BATCH_WAV_NO_FILES.arg(QDir::toNativeSeparators(wavFolderPath)));
}
else if(wavList.length() == failedConvList.length())
{
Expand Down
14 changes: 7 additions & 7 deletions src/smf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ bool SMF::fileIsValidSMF(QFile &possibleSMF, Qx::IO::IOOpReport& reportBuffer)
long long fullFileSize = QFileInfo(possibleSMF).size();

QByteArray smfSigRegion = headers.left(L_SMF_SIG);
QByteArray smfByteSigRegion = headers.mid(L_SMF_SIG, L_SMF_BYTE_SIG);
QByteArray riffSigRegion = headers.mid(L_SMF_SIG + L_SMF_BYTE_SIG, L_RIFF_SIG);
QByteArray riffSizeRegion = headers.mid(L_SMF_SIG + L_SMF_BYTE_SIG + L_RIFF_SIG, L_RIFF_LEN);
QByteArray wavSigRegion = headers.mid(L_SMF_SIG + L_SMF_BYTE_SIG + L_RIFF_SIG + L_RIFF_LEN, L_WAV_SIG);
QByteArray formatSigRegion = headers.mid(L_SMF_SIG + L_SMF_BYTE_SIG + L_RIFF_SIG + L_RIFF_LEN + L_WAV_SIG, L_FORMAT_SIG);
QByteArray unkFlagOne = headers.mid(L_SMF_SIG, L_SMF_CMN_FLAGS/2); // Not understood so unused
QByteArray unkFlagTwo = headers.mid(L_SMF_SIG + L_SMF_CMN_FLAGS/2, L_SMF_CMN_FLAGS/2); // Not understood so unused
QByteArray riffSigRegion = headers.mid(L_SMF_SIG + L_SMF_CMN_FLAGS, L_RIFF_SIG);
QByteArray riffSizeRegion = headers.mid(L_SMF_SIG + L_SMF_CMN_FLAGS + L_RIFF_SIG, L_RIFF_LEN);
QByteArray wavSigRegion = headers.mid(L_SMF_SIG + L_SMF_CMN_FLAGS + L_RIFF_SIG + L_RIFF_LEN, L_WAV_SIG);

return smfSigRegion == SMF_SIG && smfByteSigRegion == QByteArray(SMF_BYTE_SIG, 8) && riffSigRegion == RIFF_SIG && wavSigRegion == WAV_SIG && formatSigRegion == FORMAT_SIG &&
return smfSigRegion == SMF_SIG && riffSigRegion == RIFF_SIG && wavSigRegion == WAV_SIG &&
Qx::ByteArray::RAWToPrimitive<uint32_t>(riffSizeRegion, Qx::Endian::LE) == fullFileSize - 0x14;
}
}

//-Instance Functions------------------------------------------------------------------------------------------------
//Public:
QByteArray SMF::getFullData() { return mFileDataF; }
WAV SMF::toWAV() { return WAV(mFileDataF.mid(L_SMF_SIG + L_SMF_BYTE_SIG)); }
WAV SMF::toWAV() { return WAV(mFileDataF.mid(L_SMF_SIG + L_SMF_CMN_FLAGS)); } // Uses unknown flag values that seem to be common to a huge majority of SMFs

//Private:
8 changes: 3 additions & 5 deletions src/smf.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ class SMF
static inline const QString SMF_SIG = "fssm";


static inline const char SMF_BYTE_SIG[] = {0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; //This appears to actually be two back-to-back,
// 32-bit, little-endian values of 1 that may be some kind of count, but no SMF files seem to have different values than 1,1. Initialized
static inline const char SMF_CMN_FLAGS[] = {0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00}; //This appears to actually be two back-to-back,
// 32-bit, little-endian values of 1 that may be some kind of count. A few older looking BSCs use 1,0 instead, perhaps its a version tag? Initialized
// using char[] because QByteArray seems to be bugged when using "inline" with null (0x00) characters as part of the array

static inline const QString RIFF_SIG = "RIFF";
static inline const QString WAV_SIG = "WAVE";
static inline const QString FORMAT_SIG = "fmt ";

static const int L_SMF_SIG = 0x04;
static const int L_SMF_BYTE_SIG = 0x08;
static const int L_SMF_CMN_FLAGS = 0x08;
static const int L_RIFF_SIG = 0x04;
static const int L_RIFF_LEN = 0x04;
static const int L_WAV_SIG = 0x04;
static const int L_FORMAT_SIG = 0x04;


//-Instance Variables--------------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions src/version.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#ifndef VERSION_H
#define VERSION_H

#define VER_FILEVERSION 0,1,5,0
#define VER_FILEVERSION_STR "0.1.5.0"
#define VER_FILEVERSION 0,1,6,0
#define VER_FILEVERSION_STR "0.1.6.0"

#define VER_PRODUCTVERSION 0,1,5,0
#define VER_PRODUCTVERSION_STR "0.1.5.0"
#define VER_PRODUCTVERSION 0,1,6,0
#define VER_PRODUCTVERSION_STR "0.1.6.0"

#define VER_COMPANYNAME_STR "Obby Apps"
#define VER_FILEDESCRIPTION_STR "BSCWorks (CoH:v14)"
Expand Down
5 changes: 2 additions & 3 deletions src/wav.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,15 @@ bool WAV::fileIsValidWAV(QFile &possibleWAV, Qx::IO::IOOpReport& reportBuffer)
QByteArray riffSigRegion = headers.left(L_RIFF_SIG);
QByteArray riffSizeRegion = headers.mid(L_RIFF_SIG, L_RIFF_LEN);
QByteArray wavSigRegion = headers.mid(L_RIFF_SIG + L_RIFF_LEN, L_WAV_SIG);
QByteArray formatSigRegion = headers.mid(L_RIFF_SIG + L_RIFF_LEN + L_WAV_SIG, L_FORMAT_SIG);

return riffSigRegion == RIFF_SIG && wavSigRegion == WAV_SIG && formatSigRegion == FORMAT_SIG &&
return riffSigRegion == RIFF_SIG && wavSigRegion == WAV_SIG &&
Qx::ByteArray::RAWToPrimitive<uint32_t>(riffSizeRegion, Qx::Endian::LE) == fullFileSize - 0x08;
}
}

//-Instance Functions------------------------------------------------------------------------------------------------
//Public:
SMF WAV::toSMF() { return SMF(Qx::ByteArray::RAWFromString(SMF::SMF_SIG) + QByteArray(SMF::SMF_BYTE_SIG, 8) + mFileDataF); }
SMF WAV::toSMF() { return SMF(Qx::ByteArray::RAWFromString(SMF::SMF_SIG) + QByteArray(SMF::SMF_CMN_FLAGS, 8) + mFileDataF); }
QByteArray WAV::getFullData() { return mFileDataF; }

//Private:
2 changes: 0 additions & 2 deletions src/wav.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,10 @@ class WAV
static inline const QString FILE_EXT = "wav";
static inline const QString RIFF_SIG = "RIFF";
static inline const QString WAV_SIG = "WAVE";
static inline const QString FORMAT_SIG = "fmt ";

static const int L_RIFF_SIG = 0x04;
static const int L_RIFF_LEN = 0x04;
static const int L_WAV_SIG = 0x04;
static const int L_FORMAT_SIG = 0x04;

//-Instance Variables--------------------------------------------------------------------------------------------
private:
Expand Down

0 comments on commit cf6fd18

Please sign in to comment.