Skip to content

Add audio device switching API#6589

Open
metalgearsloth wants to merge 3 commits into
space-wizards:masterfrom
metalgearsloth:2026-05-20-audio-device-engine
Open

Add audio device switching API#6589
metalgearsloth wants to merge 3 commits into
space-wizards:masterfrom
metalgearsloth:2026-05-20-audio-device-engine

Conversation

@metalgearsloth
Copy link
Copy Markdown
Contributor

OpenAL-soft got updated at some point in my absence so this is back on the table.

Comment on lines +188 to +200
private void SwitchAudioDevice(string requestedDevice)
{
OpenALSawmill.Info("Switching OpenAL output device to {0}.",
string.IsNullOrEmpty(requestedDevice) ? "<default>" : requestedDevice);

if (TryReopenAudioDevice(requestedDevice))
{
ReloadDeviceExtensions();
IsEfxSupported = HasAlDeviceExtension("ALC_EXT_EFX");
SetMasterGain(_cfg.GetCVar(CVars.AudioMasterVolume));
return;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have no idea if hrtf needs re-applying but afaict it's context-based and not device-based but I could be wrong.

Comment on lines +286 to +310
/*
* Evil hack because OpenTK doesn't expose the device switch call.
*/

private delegate bool AlcReopenDeviceSoftDelegate(ALDevice device, string? deviceName, IntPtr attribs);

private static TDelegate? LoadAlcDelegate<TDelegate>(string name)
where TDelegate : Delegate
{
var type = typeof(ALC);
while (type != null)
{
var method = type.GetMethod(
"LoadDelegate",
BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.FlattenHierarchy);

if (method != null)
return (TDelegate?) method.MakeGenericMethod(typeof(TDelegate)).Invoke(null, [name]);

type = type.BaseType;
}

return null;
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evil hellcode happy to replace with whatever but OpenTK doesn't expose device switching that I could see now or when I checked a year ago.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant