Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit 7ec13cf

Browse files
committed
Allow loading flac audio and rework alternative audio file extension handling
1 parent 022510c commit 7ec13cf

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

System/Constants.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ namespace RTE {
7272
#pragma endregion
7373

7474
#pragma region Audio Constants
75+
static constexpr std::array<const char*, 3> c_SupportedAudioFormats = { ".wav", ".ogg", ".flac" };
76+
7577
static constexpr unsigned short c_MaxSoftwareChannels = 128;
7678
static constexpr unsigned short c_MaxVirtualChannels = 1024;
7779
static constexpr unsigned short c_MaxPlayingSoundsPerContainer = 128;

System/ContentFile.cpp

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -217,20 +217,23 @@ namespace RTE {
217217
if (m_DataPath.empty() || !g_AudioMan.IsAudioEnabled()) {
218218
return nullptr;
219219
}
220-
const std::string altFileExtension = (m_DataPathExtension == ".wav") ? ".ogg" : ".wav";
221220

222221
if (!std::filesystem::exists(m_DataPath)) {
223-
if (std::filesystem::exists(m_DataPathWithoutExtension + altFileExtension)) {
224-
g_ConsoleMan.AddLoadWarningLogEntry(m_DataPath, m_FormattedReaderPosition, altFileExtension);
225-
SetDataPath(m_DataPathWithoutExtension + altFileExtension);
226-
} else {
227-
if (abortGameForInvalidSound) {
228-
RTEAbort("Failed to find audio file with following path and name:\n\n" + m_DataPath + " or " + altFileExtension + "\n" + m_FormattedReaderPosition);
229-
} else {
230-
g_ConsoleMan.PrintString("Failed to find audio file with following path and name:\n\n" + m_DataPath + " or " + altFileExtension + ". The file was not loaded!");
231-
return nullptr;
222+
bool foundAltExtension = false;
223+
for (const std::string &altFileExtension : c_SupportedAudioFormats) {
224+
if (std::filesystem::exists(m_DataPathWithoutExtension + altFileExtension)) {
225+
g_ConsoleMan.AddLoadWarningLogEntry(m_DataPath, m_FormattedReaderPosition, altFileExtension);
226+
SetDataPath(m_DataPathWithoutExtension + altFileExtension);
227+
foundAltExtension = true;
228+
break;
232229
}
233230
}
231+
if (!foundAltExtension) {
232+
std::string errorMessage = "Failed to find audio file with following path and name:\n\n" + m_DataPath + " or any alternative supported file type";
233+
RTEAssert(!abortGameForInvalidSound, errorMessage + "\n" + m_FormattedReaderPosition);
234+
g_ConsoleMan.PrintString(errorMessage + ". The file was not loaded!");
235+
return nullptr;
236+
}
234237
}
235238
FMOD::Sound *returnSample = nullptr;
236239

0 commit comments

Comments
 (0)