diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index 103a48af8..7a2b73286 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -610,6 +610,7 @@ Basic.Settings.Advanced.Video.ColorRange.Partial="Partial" Basic.Settings.Advanced.Video.ColorRange.Full="Full" Basic.Settings.Advanced.Audio.MonitoringDevice="Audio Monitoring Device" Basic.Settings.Advanced.Audio.MonitoringDevice.Default="Default" +Basic.Settings.Advanced.Audio.DisableAudioDucking="Disable Windows audio ducking" Basic.Settings.Advanced.StreamDelay="Stream Delay" Basic.Settings.Advanced.StreamDelay.Duration="Duration (seconds)" Basic.Settings.Advanced.StreamDelay.Preserve="Preserve cutoff point (increase delay) when reconnecting" diff --git a/UI/forms/OBSBasicSettings.ui b/UI/forms/OBSBasicSettings.ui index 2d467aaf8..00b8afc19 100644 --- a/UI/forms/OBSBasicSettings.ui +++ b/UI/forms/OBSBasicSettings.ui @@ -3755,6 +3755,13 @@ + + + + Basic.Settings.Advanced.Audio.DisableAudioDucking + + + diff --git a/UI/obs-app.cpp b/UI/obs-app.cpp index 098f01e7f..2758b72e5 100644 --- a/UI/obs-app.cpp +++ b/UI/obs-app.cpp @@ -410,6 +410,11 @@ bool OBSApp::InitGlobalConfigDefaults() config_set_default_bool(globalConfig, "BasicWindow", "ShowStatusBar", true); +#ifdef _WIN32 + config_set_default_bool(globalConfig, "Audio", "DisableAudioDucking", + true); +#endif + #ifdef __APPLE__ config_set_default_bool(globalConfig, "Video", "DisableOSXVSync", true); config_set_default_bool(globalConfig, "Video", "ResetOSXVSyncOnExit", @@ -733,6 +738,13 @@ OBSApp::OBSApp(int &argc, char **argv, profiler_name_store_t *store) OBSApp::~OBSApp() { +#ifdef _WIN32 + bool disableAudioDucking = config_get_bool(globalConfig, "Audio", + "DisableAudioDucking"); + if (disableAudioDucking) + DisableAudioDucking(false); +#endif + #ifdef __APPLE__ bool vsyncDiabled = config_get_bool(globalConfig, "Video", "DisableOSXVSync"); @@ -851,6 +863,13 @@ void OBSApp::AppInit() config_set_default_string(globalConfig, "Basic", "SceneCollectionFile", Str("Untitled")); +#ifdef _WIN32 + bool disableAudioDucking = config_get_bool(globalConfig, "Audio", + "DisableAudioDucking"); + if (disableAudioDucking) + DisableAudioDucking(true); +#endif + #ifdef __APPLE__ if (config_get_bool(globalConfig, "Video", "DisableOSXVSync")) EnableOSXVSync(false); diff --git a/UI/platform-windows.cpp b/UI/platform-windows.cpp index 73863753b..b3ee38d59 100644 --- a/UI/platform-windows.cpp +++ b/UI/platform-windows.cpp @@ -30,6 +30,11 @@ using namespace std; #include #include #include +#include +#include + +#include +#include static inline bool check_path(const char* data, const char *path, string &output) @@ -216,3 +221,41 @@ void SetWin32DropStyle(QWidget *window) ex_style |= WS_EX_ACCEPTFILES; SetWindowLongPtr(hwnd, GWL_EXSTYLE, ex_style); } + +bool DisableAudioDucking(bool disable) +{ + ComPtr devEmum; + ComPtr device; + ComPtr sessionManager2; + ComPtr sessionControl; + ComPtr sessionControl2; + + HRESULT result = CoCreateInstance(__uuidof(MMDeviceEnumerator), + nullptr, CLSCTX_INPROC_SERVER, + __uuidof(IMMDeviceEnumerator), + (void **)&devEmum); + if (FAILED(result)) + return false; + + result = devEmum->GetDefaultAudioEndpoint(eRender, eConsole, &device); + if (FAILED(result)) + return false; + + result = device->Activate(__uuidof(IAudioSessionManager2), + CLSCTX_INPROC_SERVER, nullptr, + (void **)&sessionManager2); + if (FAILED(result)) + return false; + + result = sessionManager2->GetAudioSessionControl(nullptr, 0, + &sessionControl); + if (FAILED(result)) + return false; + + result = sessionControl->QueryInterface(&sessionControl2); + if (FAILED(result)) + return false; + + result = sessionControl2->SetDuckingPreference(disable); + return SUCCEEDED(result); +} diff --git a/UI/platform.hpp b/UI/platform.hpp index 1b1344be5..73ea999af 100644 --- a/UI/platform.hpp +++ b/UI/platform.hpp @@ -42,6 +42,7 @@ uint32_t GetWindowsVersion(); void SetAeroEnabled(bool enable); void SetProcessPriority(const char *priority); void SetWin32DropStyle(QWidget *window); +bool DisableAudioDucking(bool disable); #endif #ifdef __APPLE__ diff --git a/UI/window-basic-settings.cpp b/UI/window-basic-settings.cpp index 928c6de94..6153dbd43 100644 --- a/UI/window-basic-settings.cpp +++ b/UI/window-basic-settings.cpp @@ -392,6 +392,9 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent) HookWidget(ui->resetOSXVSync, CHECK_CHANGED, ADV_CHANGED); #if defined(_WIN32) || defined(__APPLE__) HookWidget(ui->monitoringDevice, COMBO_CHANGED, ADV_CHANGED); +#endif +#ifdef _WIN32 + HookWidget(ui->disableAudioDucking, CHECK_CHANGED, ADV_CHANGED); #endif HookWidget(ui->filenameFormatting, EDIT_CHANGED, ADV_CHANGED); HookWidget(ui->overwriteIfExists, CHECK_CHANGED, ADV_CHANGED); @@ -461,6 +464,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent) delete ui->advancedGeneralGroupBox; delete ui->enableNewSocketLoop; delete ui->enableLowLatencyMode; + delete ui->disableAudioDucking; ui->rendererLabel = nullptr; ui->renderer = nullptr; ui->adapterLabel = nullptr; @@ -470,6 +474,7 @@ OBSBasicSettings::OBSBasicSettings(QWidget *parent) ui->advancedGeneralGroupBox = nullptr; ui->enableNewSocketLoop = nullptr; ui->enableLowLatencyMode = nullptr; + ui->disableAudioDucking = nullptr; #endif #ifndef __APPLE__ @@ -2065,6 +2070,10 @@ void OBSBasicSettings::LoadAdvancedSettings() ui->resetOSXVSync->setChecked(resetOSXVSync); ui->resetOSXVSync->setEnabled(disableOSXVSync); #elif _WIN32 + bool disableAudioDucking = config_get_bool(App()->GlobalConfig(), + "Audio", "DisableAudioDucking"); + ui->disableAudioDucking->setChecked(disableAudioDucking); + const char *processPriority = config_get_string(App()->GlobalConfig(), "General", "ProcessPriority"); bool enableNewSocketLoop = config_get_bool(main->Config(), "Output", @@ -2585,6 +2594,16 @@ void OBSBasicSettings::SaveAdvancedSettings() SaveCombo(ui->monitoringDevice, "Audio", "MonitoringDeviceName"); SaveComboData(ui->monitoringDevice, "Audio", "MonitoringDeviceId"); #endif + +#ifdef _WIN32 + if (WidgetChanged(ui->disableAudioDucking)) { + bool disable = ui->disableAudioDucking->isChecked(); + config_set_bool(App()->GlobalConfig(), + "Audio", "DisableAudioDucking", disable); + DisableAudioDucking(disable); + } +#endif + SaveEdit(ui->filenameFormatting, "Output", "FilenameFormatting"); SaveEdit(ui->simpleRBPrefix, "SimpleOutput", "RecRBPrefix"); SaveEdit(ui->simpleRBSuffix, "SimpleOutput", "RecRBSuffix");