Add audio device switching API#6589
Open
metalgearsloth wants to merge 3 commits into
Open
Conversation
We don't use null here buddy.
metalgearsloth
commented
May 23, 2026
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; | ||
| } | ||
|
|
Contributor
Author
There was a problem hiding this comment.
I have no idea if hrtf needs re-applying but afaict it's context-based and not device-based but I could be wrong.
metalgearsloth
commented
May 23, 2026
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; | ||
| } | ||
|
|
Contributor
Author
There was a problem hiding this comment.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
OpenAL-soft got updated at some point in my absence so this is back on the table.