| 1 |
// Part of SAASound copyright 2020 Dave Hooper <[email protected]> |
| 2 |
// |
| 3 |
// SAAConfig.cpp: configuration file handler class |
| 4 |
// |
| 5 |
////////////////////////////////////////////////////////////////////// |
| 6 |
|
| 7 |
#include "defns.h" |
| 8 |
#ifdef USE_CONFIG_FILE |
| 9 |
|
| 10 |
#include "SAAConfig.h" |
| 11 |
#define INI_READONLY |
| 12 |
#define INI_ANSIONLY |
| 13 |
#include "minIni/minIni.h" |
| 14 |
#include <codecvt> |
| 15 |
|
| 16 |
SAAConfig::SAAConfig() |
| 17 |
: |
| 18 |
m_bHasReadConfig(false), |
| 19 |
m_bGenerateRegisterLogs(false), |
| 20 |
m_bGeneratePcmLogs(false), |
| 21 |
m_bGeneratePcmSeparateChannels(false), |
| 22 |
m_nBoost(DEFAULT_BOOST), |
| 23 |
m_bHighpass(false), |
| 24 |
m_nOversample(DEFAULT_OVERSAMPLE), |
| 25 |
m_minIni(_T(CONFIG_FILE_PATH)) |
| 26 |
{ |
| 27 |
} |
| 28 |
|
| 29 |
void SAAConfig::ReadConfig() |
| 30 |
{ |
| 31 |
// Assume (i.e. require) that the config file is always in UTF-8 . |
| 32 |
// These days, I think that's a good assumption to want to make. |
| 33 |
// It's also easy for people to create UTF-8 configs. |
| 34 |
// Define a helper to let us read from UTF-8 and convert to system locale |
| 35 |
// across platforms (and assume this will be a no-op on *nix) |
| 36 |
|
| 37 |
#if defined(WIN32) && defined(UNICODE) |
| 38 |
// WIN32 support for UNICODE requires different types |
| 39 |
// Convert config file contents from utf8 to wchar_t |
| 40 |
// minIni has been compiled to use plain char for file read-write operations |
| 41 |
// (which supports UTF8) and wchar_t for filenames (which supports unicode filenames |
| 42 |
// on win32) |
| 43 |
std::wstring_convert<std::codecvt_utf8<wchar_t>> converter; |
| 44 |
#define wrapped_gets(_mstring, _section, _element, _default) do{ \ |
| 45 |
std::string _temp_u8 = m_minIni.gets(u8"" _section "", u8"" _element "", u8"" _default ""); \ |
| 46 |
_mstring = converter.from_bytes(_temp_u8.c_str()); \ |
| 47 |
} \ |
| 48 |
while(0) |
| 49 |
#else |
| 50 |
// For *nix I think I'm supposed to convert the text from the |
| 51 |
// file encoding (which I'm assuming is utf8) to system/user locale (if different) |
| 52 |
// which I think that requires converting first to wchar_t and then to current locale |
| 53 |
// For now I'm just going to assume you'using UTF8, and I will do no conversion. |
| 54 |
// minIni has been compiled to use plain char for everything, |
| 55 |
// which is really just a utf8 passthrough assumption. |
| 56 |
// If you're compiling for WIN32 but with UNICODE not defined: you're on your own |
| 57 |
// (it might work but I'm not testing or supporting you..) |
| 58 |
|
| 59 |
#define wrapped_gets(_mstring, _section, _element, _default) \ |
| 60 |
_mstring = m_minIni.gets(u8"" _section "", u8"" _element "", u8"" _default ""); |
| 61 |
#endif |
| 62 |
|
| 63 |
#define _u8ify(x) ( u8"" x "" ) |
| 64 |
m_bGenerateRegisterLogs = m_minIni.getbool(u8"Debug", u8"WriteRegisterLog", false); |
| 65 |
if (m_bGenerateRegisterLogs) |
| 66 |
{ |
| 67 |
wrapped_gets(m_strRegisterLogPath, "Debug", "RegisterLogPath", DEBUG_SAA_REGISTER_LOG); |
| 68 |
} |
| 69 |
|
| 70 |
m_bGeneratePcmLogs = m_minIni.getbool(u8"Debug", u8"WritePCMOutput", false); |
| 71 |
if (m_bGeneratePcmLogs) |
| 72 |
{ |
| 73 |
wrapped_gets(m_strPcmOutputPath, "Debug", "PCMOutputPath", DEBUG_SAA_PCM_LOG); |
| 74 |
m_bGeneratePcmSeparateChannels = m_minIni.getbool(u8"Debug", u8"PCMSeparateChannels", false); |
| 75 |
} |
| 76 |
|
| 77 |
m_bHighpass = m_minIni.getbool(u8"Quality", u8"Highpass", false); |
| 78 |
|
| 79 |
m_nOversample = m_minIni.geti(u8"Quality", u8"Oversample", DEFAULT_OVERSAMPLE); |
| 80 |
if (m_nOversample < 1) |
| 81 |
// oversample of 0 or negative doesn't make sense |
| 82 |
m_nOversample = 1; |
| 83 |
if (m_nOversample > 15) |
| 84 |
// oversample of 16 (=65536x oversample) or more is ridiculous |
| 85 |
// apart from just CPU cycles, our (32-bit)int-based accumulation would overflow |
| 86 |
m_nOversample = 15; |
| 87 |
|
| 88 |
m_nBoost = m_minIni.getf(u8"Quality", u8"Boost", DEFAULT_BOOST); |
| 89 |
if (m_nBoost < 1) |
| 90 |
{ |
| 91 |
// interpret setting Boost=0 as disabling boost i.e. volume multipler = 100% (not 0%) |
| 92 |
// Since "Boost=1" also means volume multipler = 100%, we can just ignore values of |
| 93 |
// Boost between 0 and 1 as meaning 'no boost' |
| 94 |
m_nBoost = 1; |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
t_string SAAConfig::getChannelPcmOutputPath(int i) |
| 99 |
{ |
| 100 |
// returns a name for the i'th PCM output file when generating |
| 101 |
// single files per channel. This is really just a helper to localise |
| 102 |
// the string manipulation involved in this. |
| 103 |
// TODO - maybe make the naming convention more flexible? |
| 104 |
t_string filename = m_strPcmOutputPath; |
| 105 |
#if defined UNICODE |
| 106 |
filename += std::to_wstring(i); |
| 107 |
#else |
| 108 |
filename += std::to_string(i); |
| 109 |
#endif |
| 110 |
return filename; |
| 111 |
} |
| 112 |
|
| 113 |
#endif // USE_CONFIG_FILE |