From ee9df32e3e13fe982c8154a6454566c8edfa13d3 Mon Sep 17 00:00:00 2001 From: gdkchan Date: Sun, 4 Mar 2018 01:41:35 -0300 Subject: [PATCH] Do not block execution on audout append buffer --- Ryujinx.Core/OsHle/Services/Aud/IAudioOut.cs | 42 +++++++++++++++----- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/Ryujinx.Core/OsHle/Services/Aud/IAudioOut.cs b/Ryujinx.Core/OsHle/Services/Aud/IAudioOut.cs index 0562d4b9..c58d9e80 100644 --- a/Ryujinx.Core/OsHle/Services/Aud/IAudioOut.cs +++ b/Ryujinx.Core/OsHle/Services/Aud/IAudioOut.cs @@ -9,7 +9,7 @@ using System.IO; namespace Ryujinx.Core.OsHle.IpcServices.Aud { - class IAudioOut : IIpcService + class IAudioOut : IIpcService, IDisposable { private Dictionary m_Commands; @@ -121,6 +121,8 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud { if (AudioCtx == null) //Needed to call the instance of AudioContext() return 0; + + EnsureAudioFinalized(); Source = AL.GenSource(); Buffer = AL.GenBuffer(); @@ -128,16 +130,6 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud AL.BufferData(Buffer, ALFormat.Stereo16, AudioSampleBuffer, AudioSampleBuffer.Length, 48000); AL.SourceQueueBuffer(Source, Buffer); AL.SourcePlay(Source); - - int State; - - do AL.GetSource(Source, ALGetSourcei.SourceState, out State); - while ((ALSourceState)State == ALSourceState.Playing); - - AL.SourceStop(Source); - AL.SourceUnqueueBuffer(Buffer); - AL.DeleteSource(Source); - AL.DeleteBuffers(1, ref Buffer); } } } @@ -186,5 +178,33 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud { return 0; } + + private void EnsureAudioFinalized() + { + if (Source != 0 || + Buffer != 0) + { + AL.SourceStop(Source); + AL.SourceUnqueueBuffer(Buffer); + AL.DeleteSource(Source); + AL.DeleteBuffers(1, ref Buffer); + + Source = 0; + Buffer = 0; + } + } + + public void Dispose() + { + Dispose(true); + } + + protected virtual void Dispose(bool disposing) + { + if (disposing) + { + EnsureAudioFinalized(); + } + } } }