Update IAudioOut.cs (#51)
Little improvements, sound looks a little better...
This commit is contained in:
parent
65e04e9854
commit
1d71e33171
1 changed files with 38 additions and 28 deletions
|
@ -1,4 +1,4 @@
|
||||||
using ChocolArm64.Memory;
|
using ChocolArm64.Memory;
|
||||||
using Ryujinx.Core.OsHle.Handles;
|
using Ryujinx.Core.OsHle.Handles;
|
||||||
using Ryujinx.Core.OsHle.Ipc;
|
using Ryujinx.Core.OsHle.Ipc;
|
||||||
using OpenTK.Audio;
|
using OpenTK.Audio;
|
||||||
|
@ -39,7 +39,7 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||||
|
|
||||||
//IAudioOut
|
//IAudioOut
|
||||||
private AudioOutState State = AudioOutState.Stopped;
|
private AudioOutState State = AudioOutState.Stopped;
|
||||||
private Queue<long> KeysQueue = new Queue<long>();
|
private Queue<long> BufferIdQueue = new Queue<long>();
|
||||||
|
|
||||||
//OpenAL
|
//OpenAL
|
||||||
private bool OpenALInstalled = true;
|
private bool OpenALInstalled = true;
|
||||||
|
@ -71,7 +71,7 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||||
OpenALInstalled = false;
|
OpenALInstalled = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (OpenALInstalled) AL.Listener(ALListenerf.Gain, (float)8.0); //Add more gain to it
|
if (OpenALInstalled) AL.Listener(ALListenerf.Gain, 8.0f); //Add more gain to it
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -88,6 +88,7 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||||
|
|
||||||
AL.SourceStop(Source);
|
AL.SourceStop(Source);
|
||||||
AL.DeleteSource(Source);
|
AL.DeleteSource(Source);
|
||||||
|
AL.DeleteBuffers(1, ref Buffer);
|
||||||
}
|
}
|
||||||
State = AudioOutState.Stopped;
|
State = AudioOutState.Stopped;
|
||||||
}
|
}
|
||||||
|
@ -99,9 +100,8 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||||
{
|
{
|
||||||
long BufferId = Context.RequestData.ReadInt64();
|
long BufferId = Context.RequestData.ReadInt64();
|
||||||
|
|
||||||
KeysQueue.Enqueue(BufferId);
|
|
||||||
|
|
||||||
byte[] AudioOutBuffer = AMemoryHelper.ReadBytes(Context.Memory, Context.Request.SendBuff[0].Position, sizeof(long) * 5);
|
byte[] AudioOutBuffer = AMemoryHelper.ReadBytes(Context.Memory, Context.Request.SendBuff[0].Position, sizeof(long) * 5);
|
||||||
|
|
||||||
using (MemoryStream MS = new MemoryStream(AudioOutBuffer))
|
using (MemoryStream MS = new MemoryStream(AudioOutBuffer))
|
||||||
{
|
{
|
||||||
BinaryReader Reader = new BinaryReader(MS);
|
BinaryReader Reader = new BinaryReader(MS);
|
||||||
|
@ -111,6 +111,10 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||||
long SizeDataInSampleBuffer = Reader.ReadInt64();
|
long SizeDataInSampleBuffer = Reader.ReadInt64();
|
||||||
long OffsetDataInSampleBuffer = Reader.ReadInt64();
|
long OffsetDataInSampleBuffer = Reader.ReadInt64();
|
||||||
|
|
||||||
|
if (SizeDataInSampleBuffer > 0)
|
||||||
|
{
|
||||||
|
BufferIdQueue.Enqueue(BufferId);
|
||||||
|
|
||||||
byte[] AudioSampleBuffer = AMemoryHelper.ReadBytes(Context.Memory, PointerSampleBuffer + OffsetDataInSampleBuffer, (int)SizeDataInSampleBuffer);
|
byte[] AudioSampleBuffer = AMemoryHelper.ReadBytes(Context.Memory, PointerSampleBuffer + OffsetDataInSampleBuffer, (int)SizeDataInSampleBuffer);
|
||||||
|
|
||||||
if (OpenALInstalled)
|
if (OpenALInstalled)
|
||||||
|
@ -118,11 +122,23 @@ 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;
|
||||||
|
|
||||||
Buffer = AL.GenBuffer();
|
|
||||||
AL.BufferData(Buffer, ALFormat.Stereo16, AudioSampleBuffer, AudioSampleBuffer.Length, 48000);
|
|
||||||
|
|
||||||
Source = AL.GenSource();
|
Source = AL.GenSource();
|
||||||
|
Buffer = AL.GenBuffer();
|
||||||
|
|
||||||
|
AL.BufferData(Buffer, ALFormat.Stereo16, AudioSampleBuffer, AudioSampleBuffer.Length, 48000);
|
||||||
AL.SourceQueueBuffer(Source, Buffer);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,25 +156,19 @@ namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||||
|
|
||||||
public long GetReleasedAudioOutBuffer(ServiceCtx Context)
|
public long GetReleasedAudioOutBuffer(ServiceCtx Context)
|
||||||
{
|
{
|
||||||
long TempKey = 0;
|
int ReleasedBuffersCount = 0;
|
||||||
|
|
||||||
if (KeysQueue.Count > 0) TempKey = KeysQueue.Dequeue();
|
for(int i = 0; i < BufferIdQueue.Count; i++)
|
||||||
|
|
||||||
AMemoryHelper.WriteBytes(Context.Memory, Context.Request.ReceiveBuff[0].Position, BitConverter.GetBytes(TempKey));
|
|
||||||
|
|
||||||
int ReleasedBuffersCount = 1;
|
|
||||||
Context.ResponseData.Write(ReleasedBuffersCount);
|
|
||||||
|
|
||||||
if (OpenALInstalled)
|
|
||||||
{
|
{
|
||||||
if (AudioCtx == null) //Needed to call the instance of AudioContext()
|
long BufferId = BufferIdQueue.Dequeue();
|
||||||
return 0;
|
|
||||||
|
|
||||||
AL.SourcePlay(Source);
|
AMemoryHelper.WriteBytes(Context.Memory, Context.Request.ReceiveBuff[0].Position + (8 * i), BitConverter.GetBytes(BufferId));
|
||||||
int[] FreeBuffers = AL.SourceUnqueueBuffers(Source, 1);
|
|
||||||
AL.DeleteBuffers(FreeBuffers);
|
ReleasedBuffersCount++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context.ResponseData.Write(ReleasedBuffersCount);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue