UI: Add option to disable audio ducking on windows

The audio subsystem of windows is by default configured to lower the
volume of other things while a communications device (mic) is currently
active.  This patch prevents that from being enabled with OBS.  If the
user needs audio ducking enabled again for whatever reason, there is now
an option to re-enable it in advanced settings.

Closes jp9000/obs-studio#884
master
mntone 2017-04-17 22:38:16 +09:00 committed by jp9000
parent 4684294bcd
commit 9efd2b87aa
6 changed files with 90 additions and 0 deletions

View File

@ -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"

View File

@ -3755,6 +3755,13 @@
<item row="0" column="1">
<widget class="QComboBox" name="monitoringDevice"/>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="disableAudioDucking">
<property name="text">
<string>Basic.Settings.Advanced.Audio.DisableAudioDucking</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View File

@ -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);

View File

@ -30,6 +30,11 @@ using namespace std;
#include <shellapi.h>
#include <shlobj.h>
#include <Dwmapi.h>
#include <mmdeviceapi.h>
#include <audiopolicy.h>
#include <util/windows/HRError.hpp>
#include <util/windows/ComPtr.hpp>
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<IMMDeviceEnumerator> devEmum;
ComPtr<IMMDevice> device;
ComPtr<IAudioSessionManager2> sessionManager2;
ComPtr<IAudioSessionControl> sessionControl;
ComPtr<IAudioSessionControl2> 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);
}

View File

@ -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__

View File

@ -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");