From 115c6a31935e366527d64e0d574dfafb1fc5f636 Mon Sep 17 00:00:00 2001 From: somewhatlurker <52014015+somewhatlurker@users.noreply.github.com> Date: Wed, 16 Oct 2019 10:13:01 +1100 Subject: [PATCH] sync DivaSound (ASIO config UI) --- .../plugins/DivaSound/bassasio/bassasio.h | 4 +- .../source/plugins/DivaSound/src/dllmain.cpp | 60 ++++++++++++++++++- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/source-code/source/plugins/DivaSound/bassasio/bassasio.h b/source-code/source/plugins/DivaSound/bassasio/bassasio.h index 609ac7e..80c6023 100644 --- a/source-code/source/plugins/DivaSound/bassasio/bassasio.h +++ b/source-code/source/plugins/DivaSound/bassasio/bassasio.h @@ -113,9 +113,9 @@ user : The 'user' parameter given when calling BASS_ASIO_SetNotify */ HMODULE bassAsioModule = LoadLibraryW(L"bassasio.dll"); DWORD(WINAPI* BASS_ASIO_GetVersion)() = (DWORD(WINAPI*)())GetProcAddress(bassAsioModule, "BASS_ASIO_GetVersion"); -// BOOL BASSASIODEF(BASS_ASIO_SetUnicode)(BOOL unicode); +BOOL(WINAPI* BASS_ASIO_SetUnicode)(BOOL unicode) = (BOOL(WINAPI*)(BOOL unicode))GetProcAddress(bassAsioModule, "BASS_ASIO_SetUnicode"); // DWORD BASSASIODEF(BASS_ASIO_ErrorGetCode)(); -// BOOL BASSASIODEF(BASS_ASIO_GetDeviceInfo)(DWORD device, BASS_ASIO_DEVICEINFO *info); +BOOL(WINAPI* BASS_ASIO_GetDeviceInfo)(DWORD device, BASS_ASIO_DEVICEINFO *info) = (BOOL(WINAPI*)(DWORD device, BASS_ASIO_DEVICEINFO *info))GetProcAddress(bassAsioModule, "BASS_ASIO_GetDeviceInfo"); // DWORD BASSASIODEF(BASS_ASIO_AddDevice)(const GUID *clsid, const char *driver, const char *name); // BOOL BASSASIODEF(BASS_ASIO_SetDevice)(DWORD device); // DWORD BASSASIODEF(BASS_ASIO_GetDevice)(); diff --git a/source-code/source/plugins/DivaSound/src/dllmain.cpp b/source-code/source/plugins/DivaSound/src/dllmain.cpp index f53a47b..9d4dbcb 100644 --- a/source-code/source/plugins/DivaSound/src/dllmain.cpp +++ b/source-code/source/plugins/DivaSound/src/dllmain.cpp @@ -362,7 +362,14 @@ void loadConfig() } - asioDevice = GetPrivateProfileIntW(L"asio", L"device", -1, CONFIG_FILE); + if (GetPrivateProfileIntW(L"asio", L"auto_device", TRUE, CONFIG_FILE)) + { + asioDevice = -1; + } + else + { + asioDevice = GetPrivateProfileIntW(L"asio", L"device", -1, CONFIG_FILE); + } showAsioPanel = GetPrivateProfileIntW(L"asio", L"show_config", 0, CONFIG_FILE) > 0 ? true : false; } @@ -520,10 +527,19 @@ PluginConfigOption config[] = { { CONFIG_DROPDOWN_TEXT, new PluginConfigDropdownTextData{L"backend", L"general", CONFIG_FILE, L"Backend:", L"Sets the audio output protocol.", L"WASAPI", std::vector({ L"WASAPI", L"WASAPI_Exclusive" }), true, false } }, { CONFIG_DROPDOWN_NUMBER, new PluginConfigDropdownNumberData{ L"channels", L"general", CONFIG_FILE, L"Channels:", L"Sets the number of channels.", 2, std::vector({ 2, 4 }), false } }, { CONFIG_DROPDOWN_NUMBER, new PluginConfigDropdownNumberData{ L"bit_depth", L"general", CONFIG_FILE, L"Bit Depth:", L"Sets the audio sample format.\n(32 uses floating point samples)", 16, std::vector({ 16, 24, 32 }), false } }, + { CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"alternate_init", L"general", CONFIG_FILE, L"Use new init", L"Use the full initialisation replacement.\nTry unchecking this if DivaSound seems to cause crashes.", true, false } }, + { CONFIG_SPACER, new PluginConfigSpacerData{ 8 } }, + { CONFIG_GROUP_START, new PluginConfigGroupData{ L"WASAPI Buffer Settings", 75 } }, { CONFIG_NUMERIC, new PluginConfigNumericData{ L"buffer_size", L"buffer", CONFIG_FILE, L"Target Buffer Size:", L"Sets the target buffer size in ms.\nWASAPI will often ignore this and adapt to your hardware config automatically.", 10, 1, 100 } }, { CONFIG_NUMERIC, new PluginConfigNumericData{ L"periods", L"buffer", CONFIG_FILE, L"Buffer Periods:", L"Sets how often the buffer should be filled.\nFewer periods usually allows for lower latency, but lowering this may cause issues.", 2, 1, 8 } }, - { CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"alternate_init", L"general", CONFIG_FILE, L"Use new init", L"Use the full initialisation replacement.\nTry unchecking this if DivaSound seems to cause crashes.", true } }, + { CONFIG_GROUP_END, NULL }, { CONFIG_SPACER, new PluginConfigSpacerData{ 8 } }, + { CONFIG_SPACER, new PluginConfigSpacerData{ 0 } }, // 0px spacers are placeholders for ASIO config + { CONFIG_SPACER, new PluginConfigSpacerData{ 0 } }, + { CONFIG_SPACER, new PluginConfigSpacerData{ 0 } }, + { CONFIG_SPACER, new PluginConfigSpacerData{ 0 } }, + { CONFIG_SPACER, new PluginConfigSpacerData{ 0 } }, + { CONFIG_SPACER, new PluginConfigSpacerData{ 0 } }, { CONFIG_BUTTON, new PluginConfigButtonData{ L"Help", L"Get help on the DivaSound wiki.", OpenWiki } }, { CONFIG_SPACER, new PluginConfigSpacerData{ 8 } }, }; @@ -540,5 +556,45 @@ extern "C" __declspec(dllexport) LPCWSTR GetPluginDescription(void) extern "C" __declspec(dllexport) PluginConfigArray GetPluginOptions(void) { + if (BASS_ASIO_GetDeviceInfo != NULL && BASS_ASIO_SetUnicode != NULL) + { + if (BASS_ASIO_SetUnicode(true)) // ensure strings are UTF-16 + { + std::vector devices; + BASS_ASIO_DEVICEINFO info; + for (int i = 0; BASS_ASIO_GetDeviceInfo(i, &info); i++) + { + devices.push_back(_wcsdup((WCHAR*)info.name)); + } + + // make sure user-set device isn't out of bounds + int asioDevice = GetPrivateProfileIntW(L"asio", L"device", -1, CONFIG_FILE); + while (asioDevice + 1 > devices.size()) + { + devices.push_back(L"---"); + } + + if (devices.size() > 0) + { + ((PluginConfigDropdownTextData*)config[0].data)->valueStrings.push_back(L"ASIO"); + + const int cfgPos = 10; + delete config[cfgPos].data; + delete config[cfgPos + 1].data; + delete config[cfgPos + 2].data; + delete config[cfgPos + 3].data; + delete config[cfgPos + 4].data; + delete config[cfgPos + 5].data; + + config[cfgPos] = { CONFIG_GROUP_START, new PluginConfigGroupData{ L"ASIO Settings", 90 } }; + config[cfgPos + 1] = { CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"show_config", L"asio", CONFIG_FILE, L"Show ASIO config", L"Show the ASIO driver config window when the game opens.\nUse this to adjust output settings, then disable it.\n(ASIO devices are unaffected by the normal buffer settings)", false, false } }; + config[cfgPos + 2] = { CONFIG_BOOLEAN, new PluginConfigBooleanData{ L"auto_device", L"asio", CONFIG_FILE, L"Automatic ASIO device", L"Automatically choose the first available device for ASIO backend.\nDisable this to use a manually choose a device.", true, false } }; + config[cfgPos + 3] = { CONFIG_DROPDOWN_INDEX, new PluginConfigDropdownIndexData{ L"device", L"asio", CONFIG_FILE, L"ASIO Device:", L"Sets the ASIO device.\nMake sure automatic device selection is turned off to enable this.", 0, devices } }; + config[cfgPos + 4] = { CONFIG_GROUP_END, NULL }; + config[cfgPos + 5] = { CONFIG_SPACER, new PluginConfigSpacerData{ 8 } }; + } + } + } + return PluginConfigArray{ _countof(config), config }; } \ No newline at end of file