# Disables OpenAL Soft's dependency on both `ghc::filesystem` and `std::filesystem`. None of those work when building for PlayStation 3. # As a side effect, also prevents OpenAL Soft from loading from its config file. --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -628,7 +628,7 @@ set(COMMON_OBJS common/comptr.h common/dynload.cpp common/dynload.h - common/filesystem.cpp + common/filesystem.h common/flexarray.h common/intrusive_ptr.h @@ -691,7 +691,7 @@ set(CORE_OBJS core/fpu_ctrl.cpp core/fpu_ctrl.h core/front_stablizer.h - core/helpers.cpp + core/helpers.h core/hrtf.cpp core/hrtf.h --- a/alc/alconfig.cpp +++ b/alc/alconfig.cpp @@ -46,7 +46,7 @@ #include "alstring.h" #include "core/helpers.h" #include "core/logging.h" -#include "filesystem.h" + #include "strutils.h" #if ALSOFT_UWP @@ -332,156 +332,156 @@ auto GetConfigValue(const std::string_view devName, const std::string_view block #ifdef _WIN32 void ReadALConfig() { - fs::path path; -#if !defined(_GAMING_XBOX) - { -#if !ALSOFT_UWP - std::unique_ptr bufstore; - const HRESULT hr{SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DONT_UNEXPAND, - nullptr, al::out_ptr(bufstore))}; - if(SUCCEEDED(hr)) - { - const std::wstring_view buffer{bufstore.get()}; -#else - winrt::Windows::Storage::ApplicationDataContainer localSettings = winrt::Windows::Storage::ApplicationData::Current().LocalSettings(); - auto bufstore = Windows::Storage::ApplicationData::Current().RoamingFolder().Path(); - std::wstring_view buffer{bufstore}; - { -#endif - path = fs::path{buffer}; - path /= L"alsoft.ini"; - TRACE("Loading config {}...", al::u8_as_char(path.u8string())); - if(fs::ifstream f{path}; f.is_open()) - LoadConfigFromFile(f); - } - } -#endif - path = fs::u8path(GetProcBinary().path); - if(!path.empty()) - { - path /= L"alsoft.ini"; - TRACE("Loading config {}...", al::u8_as_char(path.u8string())); - if(fs::ifstream f{path}; f.is_open()) - LoadConfigFromFile(f); - } - if(auto confpath = al::getenv(L"ALSOFT_CONF")) - { - path = *confpath; - TRACE("Loading config {}...", al::u8_as_char(path.u8string())); - if(fs::ifstream f{path}; f.is_open()) - LoadConfigFromFile(f); - } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } #else void ReadALConfig() { - fs::path path{"/etc/openal/alsoft.conf"}; - - TRACE("Loading config {}...", al::u8_as_char(path.u8string())); - if(fs::ifstream f{path}; f.is_open()) - LoadConfigFromFile(f); - - std::string confpaths{al::getenv("XDG_CONFIG_DIRS").value_or("/etc/xdg")}; - /* Go through the list in reverse, since "the order of base directories - * denotes their importance; the first directory listed is the most - * important". Ergo, we need to load the settings from the later dirs - * first so that the settings in the earlier dirs override them. - */ - while(!confpaths.empty()) - { - auto next = confpaths.rfind(':'); - if(next < confpaths.length()) - { - path = fs::path{std::string_view{confpaths}.substr(next+1)}.lexically_normal(); - confpaths.erase(next); - } - else - { - path = fs::path{confpaths}.lexically_normal(); - confpaths.clear(); - } - if(!path.is_absolute()) - WARN("Ignoring XDG config dir: {}", al::u8_as_char(path.u8string())); - else - { - path /= "alsoft.conf"; - TRACE("Loading config {}...", al::u8_as_char(path.u8string())); - if(fs::ifstream f{path}; f.is_open()) - LoadConfigFromFile(f); - } - } -#ifdef __APPLE__ - CFBundleRef mainBundle = CFBundleGetMainBundle(); - if(mainBundle) - { - CFURLRef configURL{CFBundleCopyResourceURL(mainBundle, CFSTR(".alsoftrc"), CFSTR(""), - nullptr)}; - std::array fileName{}; - if(configURL && CFURLGetFileSystemRepresentation(configURL, true, fileName.data(), fileName.size())) - { - if(std::ifstream f{reinterpret_cast(fileName.data())}; f.is_open()) - LoadConfigFromFile(f); - } - } -#endif - if(auto homedir = al::getenv("HOME")) - { - path = *homedir; - path /= ".alsoftrc"; - TRACE("Loading config {}...", al::u8_as_char(path.u8string())); - if(std::ifstream f{path}; f.is_open()) - LoadConfigFromFile(f); - } - if(auto configdir = al::getenv("XDG_CONFIG_HOME")) - { - path = *configdir; - path /= "alsoft.conf"; - } - else - { - path.clear(); - if(auto homedir = al::getenv("HOME")) - { - path = *homedir; - path /= ".config/alsoft.conf"; - } - } - if(!path.empty()) - { - TRACE("Loading config {}...", al::u8_as_char(path.u8string())); - if(std::ifstream f{path}; f.is_open()) - LoadConfigFromFile(f); - } - path = GetProcBinary().path; - if(!path.empty()) - { - path /= "alsoft.conf"; - TRACE("Loading config {}...", al::u8_as_char(path.u8string())); - if(std::ifstream f{path}; f.is_open()) - LoadConfigFromFile(f); - } - if(auto confname = al::getenv("ALSOFT_CONF")) - { - TRACE("Loading config {}...", *confname); - if(std::ifstream f{*confname}; f.is_open()) - LoadConfigFromFile(f); - } + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } #endif --- a/core/ambdec.cpp +++ b/core/ambdec.cpp @@ -15,7 +15,7 @@ #include "albit.h" #include "alspan.h" -#include "filesystem.h" + #include "fmt/core.h" @@ -60,231 +60,5 @@ AmbDecConf::~AmbDecConf() = default; std::optional AmbDecConf::load(const char *fname) noexcept { - fs::ifstream f{fs::u8path(fname)}; - if(!f.is_open()) - return std::string("Failed to open file \"")+fname+"\""; - - ReaderScope scope{ReaderScope::Global}; - size_t speaker_pos{0}; - size_t lfmatrix_pos{0}; - size_t hfmatrix_pos{0}; - size_t linenum{0}; - - std::string buffer; - while(f.good() && std::getline(f, buffer)) - { - ++linenum; - - std::istringstream istr{buffer}; - std::string command{read_word(istr)}; - if(command.empty() || command[0] == '#') - continue; - - if(command == "/}") - { - if(scope == ReaderScope::Global) - return make_error(linenum, "Unexpected /}} in global scope"); - scope = ReaderScope::Global; - continue; - } - - if(scope == ReaderScope::Speakers) - { - if(command == "add_spkr") - { - if(speaker_pos == Speakers.size()) - return make_error(linenum, "Too many speakers specified"); - - AmbDecConf::SpeakerConf &spkr = Speakers[speaker_pos++]; - istr >> spkr.Name; - istr >> spkr.Distance; - istr >> spkr.Azimuth; - istr >> spkr.Elevation; - istr >> spkr.Connection; - } - else - return make_error(linenum, "Unexpected speakers command: {}", command); - } - else if(scope == ReaderScope::LFMatrix || scope == ReaderScope::HFMatrix) - { - auto &gains = (scope == ReaderScope::LFMatrix) ? LFOrderGain : HFOrderGain; - auto matrix = (scope == ReaderScope::LFMatrix) ? LFMatrix : HFMatrix; - auto &pos = (scope == ReaderScope::LFMatrix) ? lfmatrix_pos : hfmatrix_pos; - - if(command == "order_gain") - { - size_t toread{(ChanMask > Ambi3OrderMask) ? 5u : 4u}; - std::size_t curgain{0u}; - float value{}; - while(toread) - { - --toread; - istr >> value; - if(curgain < std::size(gains)) - gains[curgain++] = value; - } - } - else if(command == "add_row") - { - if(pos == Speakers.size()) - return make_error(linenum, "Too many matrix rows specified"); - - unsigned int mask{ChanMask}; - - AmbDecConf::CoeffArray &mtxrow = matrix[pos++]; - mtxrow.fill(0.0f); - - float value{}; - while(mask) - { - auto idx = static_cast(al::countr_zero(mask)); - mask &= ~(1u << idx); - - istr >> value; - if(idx < mtxrow.size()) - mtxrow[idx] = value; - } - } - else - return make_error(linenum, "Unexpected matrix command: {}", command); - } - // Global scope commands - else if(command == "/description") - { - while(istr.good() && std::isspace(istr.peek())) - istr.ignore(); - std::getline(istr, Description); - while(!Description.empty() && std::isspace(Description.back())) - Description.pop_back(); - } - else if(command == "/version") - { - if(Version) - return make_error(linenum, "Duplicate version definition"); - istr >> Version; - if(Version != 3) - return make_error(linenum, "Unsupported version: {}", Version); - } - else if(command == "/dec/chan_mask") - { - if(ChanMask) - return make_error(linenum, "Duplicate chan_mask definition"); - istr >> std::hex >> ChanMask >> std::dec; - - if(!ChanMask || ChanMask > Ambi4OrderMask) - return make_error(linenum, "Invalid chan_mask: {:#x}", ChanMask); - if(ChanMask > Ambi3OrderMask && CoeffScale == AmbDecScale::FuMa) - return make_error(linenum, "FuMa not compatible with over third-order"); - } - else if(command == "/dec/freq_bands") - { - if(FreqBands) - return make_error(linenum, "Duplicate freq_bands"); - istr >> FreqBands; - if(FreqBands != 1 && FreqBands != 2) - return make_error(linenum, "Invalid freq_bands: {}", FreqBands); - } - else if(command == "/dec/speakers") - { - if(!Speakers.empty()) - return make_error(linenum, "Duplicate speakers"); - size_t numspeakers{}; - istr >> numspeakers; - if(!numspeakers) - return make_error(linenum, "Invalid speakers: {}", numspeakers); - Speakers.resize(numspeakers); - } - else if(command == "/dec/coeff_scale") - { - if(CoeffScale != AmbDecScale::Unset) - return make_error(linenum, "Duplicate coeff_scale"); - - std::string scale{read_word(istr)}; - if(scale == "n3d") CoeffScale = AmbDecScale::N3D; - else if(scale == "sn3d") CoeffScale = AmbDecScale::SN3D; - else if(scale == "fuma") CoeffScale = AmbDecScale::FuMa; - else - return make_error(linenum, "Unexpected coeff_scale: {}", scale); - - if(ChanMask > Ambi3OrderMask && CoeffScale == AmbDecScale::FuMa) - return make_error(linenum, "FuMa not compatible with over third-order"); - } - else if(command == "/opt/xover_freq") - { - istr >> XOverFreq; - } - else if(command == "/opt/xover_ratio") - { - istr >> XOverRatio; - } - else if(command == "/opt/input_scale" || command == "/opt/nfeff_comp" - || command == "/opt/delay_comp" || command == "/opt/level_comp") - { - /* Unused */ - read_word(istr); - } - else if(command == "/speakers/{") - { - if(Speakers.empty()) - return make_error(linenum, "Speakers defined without a count"); - scope = ReaderScope::Speakers; - } - else if(command == "/lfmatrix/{" || command == "/hfmatrix/{" || command == "/matrix/{") - { - if(Speakers.empty()) - return make_error(linenum, "Matrix defined without a speaker count"); - if(!ChanMask) - return make_error(linenum, "Matrix defined without a channel mask"); - - if(Matrix.empty()) - { - Matrix.resize(Speakers.size() * FreqBands); - LFMatrix = al::span{Matrix}.first(Speakers.size()); - HFMatrix = al::span{Matrix}.subspan(Speakers.size()*(FreqBands-1)); - } - - if(FreqBands == 1) - { - if(command != "/matrix/{") - return make_error(linenum, "Unexpected \"{}\" for a single-band decoder", - command); - scope = ReaderScope::HFMatrix; - } - else - { - if(command == "/lfmatrix/{") - scope = ReaderScope::LFMatrix; - else if(command == "/hfmatrix/{") - scope = ReaderScope::HFMatrix; - else - return make_error(linenum, "Unexpected \"{}\" for a dual-band decoder", - command); - } - } - else if(command == "/end") - { - const auto endpos = static_cast(istr.tellg()); - if(!is_at_end(buffer, endpos)) - return make_error(linenum, "Extra junk on end: {}", - std::string_view{buffer}.substr(endpos)); - - if(speaker_pos < Speakers.size() || hfmatrix_pos < Speakers.size() - || (FreqBands == 2 && lfmatrix_pos < Speakers.size())) - return make_error(linenum, "Incomplete decoder definition"); - if(CoeffScale == AmbDecScale::Unset) - return make_error(linenum, "No coefficient scaling defined"); - - return std::nullopt; - } - else - return make_error(linenum, "Unexpected command: {}", command); - - istr.clear(); - const auto endpos = static_cast(istr.tellg()); - if(!is_at_end(buffer, endpos)) - return make_error(linenum, "Extra junk on line: {}", - std::string_view{buffer}.substr(endpos)); - buffer.clear(); - } - return make_error(linenum, "Unexpected end of file"); + return std::string("OpenAL Soft's Ambisonics config loader is disabled by mkxp-z"); } --- a/core/hrtf.cpp +++ b/core/hrtf.cpp @@ -30,7 +30,7 @@ #include "alspan.h" #include "alstring.h" #include "ambidefs.h" -#include "filesystem.h" + #include "filters/splitter.h" #include "fmt/core.h" #include "helpers.h" @@ -1202,8 +1202,8 @@ std::vector EnumerateHrtf(std::optional pathopt) std::lock_guard enumlock{EnumeratedHrtfLock}; EnumeratedHrtfs.clear(); - for(const auto &fname : SearchDataFiles(".mhr"sv)) - AddFileEntry(fname); + + bool usedefaults{true}; if(pathopt) @@ -1230,16 +1230,16 @@ std::vector EnumerateHrtf(std::optional pathopt) entry.remove_suffix(1); if(!entry.empty()) { - for(const auto &fname : SearchDataFiles(".mhr"sv, entry)) - AddFileEntry(fname); + + } } } if(usedefaults) { - for(const auto &fname : SearchDataFiles(".mhr"sv, "openal/hrtf"sv)) - AddFileEntry(fname); + + if(!GetResource(IDR_DEFAULT_HRTF_MHR).empty()) AddBuiltInEntry("Built-In HRTF", IDR_DEFAULT_HRTF_MHR); @@ -1303,14 +1303,14 @@ HrtfStorePtr GetLoadedHrtf(const std::string_view name, const uint devrate) else { TRACE("Loading {}...", fname); - auto fstr = std::make_unique(fs::u8path(fname), - std::ios::binary); - if(!fstr->is_open()) + + ERR("OpenAL Soft's HRTF loader is disabled by mkxp-z"); + if(true) { ERR("Could not open {}", fname); return nullptr; } - stream = std::move(fstr); + } auto hrtf = std::unique_ptr{};