0
0
Fork 0
mirror of https://github.com/ryujinx-mirror/ryujinx.git synced 2024-12-23 04:05:46 +00:00

Do not block execution on audout append buffer

This commit is contained in:
gdkchan 2018-03-04 01:41:35 -03:00
parent 479443564c
commit ee9df32e3e

View file

@ -9,7 +9,7 @@ using System.IO;
namespace Ryujinx.Core.OsHle.IpcServices.Aud namespace Ryujinx.Core.OsHle.IpcServices.Aud
{ {
class IAudioOut : IIpcService class IAudioOut : IIpcService, IDisposable
{ {
private Dictionary<int, ServiceProcessRequest> m_Commands; private Dictionary<int, ServiceProcessRequest> m_Commands;
@ -122,22 +122,14 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud
if (AudioCtx == null) //Needed to call the instance of AudioContext() if (AudioCtx == null) //Needed to call the instance of AudioContext()
return 0; return 0;
EnsureAudioFinalized();
Source = AL.GenSource(); Source = AL.GenSource();
Buffer = AL.GenBuffer(); Buffer = AL.GenBuffer();
AL.BufferData(Buffer, ALFormat.Stereo16, AudioSampleBuffer, AudioSampleBuffer.Length, 48000); AL.BufferData(Buffer, ALFormat.Stereo16, AudioSampleBuffer, AudioSampleBuffer.Length, 48000);
AL.SourceQueueBuffer(Source, Buffer); AL.SourceQueueBuffer(Source, Buffer);
AL.SourcePlay(Source); 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; 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();
}
}
} }
} }