From c734137f4164d356a2fdad3349c1afd1976e1cd9 Mon Sep 17 00:00:00 2001
From: jduncanator <1518948+jduncanator@users.noreply.github.com>
Date: Wed, 13 Feb 2019 12:59:26 +1100
Subject: Audio: Select a shared audio device by default (#574)
* Audio: Select a shared audio device by default
This ensures that a non-raw audio device is selected wherever possible.
* Audio: Resolve libsoundio version mismatch between bindings and binaries
It turns out we were using bindings generated with libsoundio 1.1.0 git source, but the binaries we were using were built from master git source. I've rebuilt both binaries and bindings to ensure they are version matched.
This should resolve all outstanding issues with libsoundio (including the Linux segfault issue, and the "cannot open device" Windows issue).
* Audio: Reformat MarshalExtensions
* Resolve code indentation issues
---
Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs | 151 +++++++++++++--------
1 file changed, 96 insertions(+), 55 deletions(-)
(limited to 'Ryujinx.Audio/Renderers')
diff --git a/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs b/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs
index 0d3e74dd..649aa8d7 100644
--- a/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs
+++ b/Ryujinx.Audio/Renderers/SoundIo/SoundIoAudioOut.cs
@@ -36,60 +36,7 @@ namespace Ryujinx.Audio
{
get
{
- SoundIO context = null;
- SoundIODevice device = null;
- SoundIOOutStream stream = null;
-
- bool backendDisconnected = false;
-
- try
- {
- context = new SoundIO();
-
- context.OnBackendDisconnect = (i) => {
- backendDisconnected = true;
- };
-
- context.Connect();
- context.FlushEvents();
-
- if(backendDisconnected)
- {
- return false;
- }
-
- device = context.GetOutputDevice(context.DefaultOutputDeviceIndex);
-
- if(device == null || backendDisconnected)
- {
- return false;
- }
-
- stream = device.CreateOutStream();
-
- if(stream == null || backendDisconnected)
- {
- return false;
- }
-
- return true;
- }
- catch
- {
- return false;
- }
- finally
- {
- if(stream != null)
- {
- stream.Dispose();
- }
-
- if(context != null)
- {
- context.Dispose();
- }
- }
+ return IsSupportedInternal();
}
}
@@ -103,7 +50,7 @@ namespace Ryujinx.Audio
m_AudioContext.Connect();
m_AudioContext.FlushEvents();
- m_AudioDevice = m_AudioContext.GetOutputDevice(m_AudioContext.DefaultOutputDeviceIndex);
+ m_AudioDevice = FindNonRawDefaultAudioDevice(m_AudioContext, true);
m_TrackPool = new SoundIoAudioTrackPool(m_AudioContext, m_AudioDevice, MaximumTracks);
}
@@ -244,5 +191,99 @@ namespace Ryujinx.Audio
m_AudioContext.Disconnect();
m_AudioContext.Dispose();
}
+
+ ///
+ /// Searches for a shared version of the default audio device
+ ///
+ /// The audio context
+ /// Whether to fallback to the raw default audio device if a non-raw device cannot be found
+ private static SoundIODevice FindNonRawDefaultAudioDevice(SoundIO audioContext, bool fallback = false)
+ {
+ SoundIODevice defaultAudioDevice = audioContext.GetOutputDevice(audioContext.DefaultOutputDeviceIndex);
+
+ if(!defaultAudioDevice.IsRaw)
+ {
+ return defaultAudioDevice;
+ }
+
+ for(var i = 0; i < audioContext.BackendCount; i++)
+ {
+ SoundIODevice audioDevice = audioContext.GetOutputDevice(i);
+
+ if (audioDevice.Id == defaultAudioDevice.Id && !audioDevice.IsRaw)
+ {
+ return audioDevice;
+ }
+ }
+
+ return fallback ? defaultAudioDevice : null;
+ }
+
+ ///
+ /// Determines if SoundIO can connect to a supported backend
+ ///
+ ///
+ private static bool IsSupportedInternal()
+ {
+ SoundIO context = null;
+ SoundIODevice device = null;
+ SoundIOOutStream stream = null;
+
+ bool backendDisconnected = false;
+
+ try
+ {
+ context = new SoundIO();
+
+ context.OnBackendDisconnect = (i) => {
+ backendDisconnected = true;
+ };
+
+ context.Connect();
+ context.FlushEvents();
+
+ if(backendDisconnected)
+ {
+ return false;
+ }
+
+ if(context.OutputDeviceCount == 0)
+ {
+ return false;
+ }
+
+ device = FindNonRawDefaultAudioDevice(context);
+
+ if(device == null || backendDisconnected)
+ {
+ return false;
+ }
+
+ stream = device.CreateOutStream();
+
+ if(stream == null || backendDisconnected)
+ {
+ return false;
+ }
+
+ return true;
+ }
+ catch
+ {
+ return false;
+ }
+ finally
+ {
+ if(stream != null)
+ {
+ stream.Dispose();
+ }
+
+ if(context != null)
+ {
+ context.Dispose();
+ }
+ }
+ }
}
}
\ No newline at end of file
--
cgit v1.2.3