mirror of
https://git.743378673.xyz/MeloNX/MeloNX.git
synced 2025-08-03 01:37:10 +02:00
Implement many objects, improve logging. (#42)
* Implement many objects, improve logging. Change and rename folders of Services Add Logging of IpcMessage. Add "lm" Log Service. Parse Errors of SetTerminateResult Add Svc Calls. Add many object implementations. * Corrections Forgotten Debug Conf * Corrections 2 * Corrections 3 * Corrections 4
This commit is contained in:
parent
fba0bf8732
commit
e174100474
69 changed files with 660 additions and 27 deletions
180
Ryujinx.Core/OsHle/Services/Aud/IAudioOut.cs
Normal file
180
Ryujinx.Core/OsHle/Services/Aud/IAudioOut.cs
Normal file
|
@ -0,0 +1,180 @@
|
|||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Handles;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using OpenTK.Audio;
|
||||
using OpenTK.Audio.OpenAL;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||
{
|
||||
class IAudioOut : IIpcService
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public IAudioOut()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, GetAudioOutState },
|
||||
{ 1, StartAudioOut },
|
||||
{ 2, StopAudioOut },
|
||||
{ 3, AppendAudioOutBuffer },
|
||||
{ 4, RegisterBufferEvent },
|
||||
{ 5, GetReleasedAudioOutBuffer },
|
||||
{ 6, ContainsAudioOutBuffer },
|
||||
{ 7, AppendAudioOutBuffer_ex },
|
||||
{ 8, GetReleasedAudioOutBuffer_ex }
|
||||
};
|
||||
}
|
||||
|
||||
enum AudioOutState
|
||||
{
|
||||
Started,
|
||||
Stopped
|
||||
};
|
||||
|
||||
//IAudioOut
|
||||
private AudioOutState State = AudioOutState.Stopped;
|
||||
private Queue<long> KeysQueue = new Queue<long>();
|
||||
|
||||
//OpenAL
|
||||
private bool OpenALInstalled = true;
|
||||
private AudioContext AudioCtx;
|
||||
private int Source;
|
||||
private int Buffer;
|
||||
|
||||
//Return State of IAudioOut
|
||||
public long GetAudioOutState(ServiceCtx Context)
|
||||
{
|
||||
Context.ResponseData.Write((int)State);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long StartAudioOut(ServiceCtx Context)
|
||||
{
|
||||
if (State == AudioOutState.Stopped)
|
||||
{
|
||||
State = AudioOutState.Started;
|
||||
|
||||
try
|
||||
{
|
||||
AudioCtx = new AudioContext(); //Create the audio context
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
Logging.Warn("OpenAL Error! PS: Install OpenAL Core SDK!");
|
||||
OpenALInstalled = false;
|
||||
}
|
||||
|
||||
if (OpenALInstalled) AL.Listener(ALListenerf.Gain, (float)8.0); //Add more gain to it
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long StopAudioOut(ServiceCtx Context)
|
||||
{
|
||||
if (State == AudioOutState.Started)
|
||||
{
|
||||
if (OpenALInstalled)
|
||||
{
|
||||
if (AudioCtx == null) //Needed to call the instance of AudioContext()
|
||||
return 0;
|
||||
|
||||
AL.SourceStop(Source);
|
||||
AL.DeleteSource(Source);
|
||||
}
|
||||
State = AudioOutState.Stopped;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long AppendAudioOutBuffer(ServiceCtx Context)
|
||||
{
|
||||
long BufferId = Context.RequestData.ReadInt64();
|
||||
|
||||
KeysQueue.Enqueue(BufferId);
|
||||
|
||||
byte[] AudioOutBuffer = AMemoryHelper.ReadBytes(Context.Memory, Context.Request.SendBuff[0].Position, sizeof(long) * 5);
|
||||
using (MemoryStream MS = new MemoryStream(AudioOutBuffer))
|
||||
{
|
||||
BinaryReader Reader = new BinaryReader(MS);
|
||||
long PointerNextBuffer = Reader.ReadInt64();
|
||||
long PointerSampleBuffer = Reader.ReadInt64();
|
||||
long CapacitySampleBuffer = Reader.ReadInt64();
|
||||
long SizeDataInSampleBuffer = Reader.ReadInt64();
|
||||
long OffsetDataInSampleBuffer = Reader.ReadInt64();
|
||||
|
||||
byte[] AudioSampleBuffer = AMemoryHelper.ReadBytes(Context.Memory, PointerSampleBuffer + OffsetDataInSampleBuffer, (int)SizeDataInSampleBuffer);
|
||||
|
||||
if (OpenALInstalled)
|
||||
{
|
||||
if (AudioCtx == null) //Needed to call the instance of AudioContext()
|
||||
return 0;
|
||||
|
||||
Buffer = AL.GenBuffer();
|
||||
AL.BufferData(Buffer, ALFormat.Stereo16, AudioSampleBuffer, AudioSampleBuffer.Length, 48000);
|
||||
|
||||
Source = AL.GenSource();
|
||||
AL.SourceQueueBuffer(Source, Buffer);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long RegisterBufferEvent(ServiceCtx Context)
|
||||
{
|
||||
int Handle = Context.Ns.Os.Handles.GenerateId(new HEvent());
|
||||
|
||||
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetReleasedAudioOutBuffer(ServiceCtx Context)
|
||||
{
|
||||
long TempKey = 0;
|
||||
|
||||
if (KeysQueue.Count > 0) TempKey = KeysQueue.Dequeue();
|
||||
|
||||
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()
|
||||
return 0;
|
||||
|
||||
AL.SourcePlay(Source);
|
||||
int[] FreeBuffers = AL.SourceUnqueueBuffers(Source, 1);
|
||||
AL.DeleteBuffers(FreeBuffers);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long ContainsAudioOutBuffer(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long AppendAudioOutBuffer_ex(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetReleasedAudioOutBuffer_ex(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
66
Ryujinx.Core/OsHle/Services/Aud/IAudioRenderer.cs
Normal file
66
Ryujinx.Core/OsHle/Services/Aud/IAudioRenderer.cs
Normal file
|
@ -0,0 +1,66 @@
|
|||
using Ryujinx.Core.OsHle.Handles;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||
{
|
||||
class IAudioRenderer : IIpcService
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public IAudioRenderer()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 4, RequestUpdateAudioRenderer },
|
||||
{ 5, StartAudioRenderer },
|
||||
{ 6, StopAudioRenderer },
|
||||
{ 7, QuerySystemEvent }
|
||||
};
|
||||
}
|
||||
|
||||
public long RequestUpdateAudioRenderer(ServiceCtx Context)
|
||||
{
|
||||
//(buffer<unknown, 5, 0>) -> (buffer<unknown, 6, 0>, buffer<unknown, 6, 0>)
|
||||
|
||||
long Position = Context.Request.ReceiveBuff[0].Position;
|
||||
|
||||
//0x40 bytes header
|
||||
Context.Memory.WriteInt32(Position + 0x4, 0xb0); //Behavior Out State Size? (note: this is the last section)
|
||||
Context.Memory.WriteInt32(Position + 0x8, 0x18e0); //Memory Pool Out State Size?
|
||||
Context.Memory.WriteInt32(Position + 0xc, 0x600); //Voice Out State Size?
|
||||
Context.Memory.WriteInt32(Position + 0x14, 0xe0); //Effect Out State Size?
|
||||
Context.Memory.WriteInt32(Position + 0x1c, 0x20); //Sink Out State Size?
|
||||
Context.Memory.WriteInt32(Position + 0x20, 0x10); //Performance Out State Size?
|
||||
Context.Memory.WriteInt32(Position + 0x3c, 0x20e0); //Total Size (including 0x40 bytes header)
|
||||
|
||||
for (int Offset = 0x40; Offset < 0x40 + 0x18e0; Offset += 0x10)
|
||||
{
|
||||
Context.Memory.WriteInt32(Position + Offset, 5);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long StartAudioRenderer(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long StopAudioRenderer(ServiceCtx Context)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long QuerySystemEvent(ServiceCtx Context)
|
||||
{
|
||||
int Handle = Context.Ns.Os.Handles.GenerateId(new HEvent());
|
||||
|
||||
Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
57
Ryujinx.Core/OsHle/Services/Aud/ServiceAudOut.cs
Normal file
57
Ryujinx.Core/OsHle/Services/Aud/ServiceAudOut.cs
Normal file
|
@ -0,0 +1,57 @@
|
|||
using ChocolArm64.Memory;
|
||||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
using static Ryujinx.Core.OsHle.IpcServices.ObjHelper;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||
{
|
||||
class ServiceAudOut : IIpcService
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public ServiceAudOut()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, ListAudioOuts },
|
||||
{ 1, OpenAudioOut },
|
||||
};
|
||||
}
|
||||
|
||||
public long ListAudioOuts(ServiceCtx Context)
|
||||
{
|
||||
long Position = Context.Request.ReceiveBuff[0].Position;
|
||||
|
||||
AMemoryHelper.WriteBytes(Context.Memory, Position, Encoding.ASCII.GetBytes("iface"));
|
||||
|
||||
Context.ResponseData.Write(1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long OpenAudioOut(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new IAudioOut());
|
||||
|
||||
Context.ResponseData.Write(48000); //Sample Rate
|
||||
Context.ResponseData.Write(2); //Channel Count
|
||||
Context.ResponseData.Write(2); //PCM Format
|
||||
/*
|
||||
0 - Invalid
|
||||
1 - INT8
|
||||
2 - INT16
|
||||
3 - INT24
|
||||
4 - INT32
|
||||
5 - PCM Float
|
||||
6 - ADPCM
|
||||
*/
|
||||
Context.ResponseData.Write(0); //Unknown
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
51
Ryujinx.Core/OsHle/Services/Aud/ServiceAudRen.cs
Normal file
51
Ryujinx.Core/OsHle/Services/Aud/ServiceAudRen.cs
Normal file
|
@ -0,0 +1,51 @@
|
|||
using Ryujinx.Core.OsHle.Ipc;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using static Ryujinx.Core.OsHle.IpcServices.ObjHelper;
|
||||
|
||||
namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
||||
{
|
||||
class ServiceAudRen : IIpcService
|
||||
{
|
||||
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
||||
|
||||
public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
||||
|
||||
public ServiceAudRen()
|
||||
{
|
||||
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
||||
{
|
||||
{ 0, OpenAudioRenderer },
|
||||
{ 1, GetAudioRendererWorkBufferSize },
|
||||
};
|
||||
}
|
||||
|
||||
public long OpenAudioRenderer(ServiceCtx Context)
|
||||
{
|
||||
MakeObject(Context, new IAudioRenderer());
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public long GetAudioRendererWorkBufferSize(ServiceCtx Context)
|
||||
{
|
||||
int SampleRate = Context.RequestData.ReadInt32();
|
||||
int Unknown4 = Context.RequestData.ReadInt32();
|
||||
int Unknown8 = Context.RequestData.ReadInt32();
|
||||
int UnknownC = Context.RequestData.ReadInt32();
|
||||
int Unknown10 = Context.RequestData.ReadInt32();
|
||||
int Unknown14 = Context.RequestData.ReadInt32();
|
||||
int Unknown18 = Context.RequestData.ReadInt32();
|
||||
int Unknown1c = Context.RequestData.ReadInt32();
|
||||
int Unknown20 = Context.RequestData.ReadInt32();
|
||||
int Unknown24 = Context.RequestData.ReadInt32();
|
||||
int Unknown28 = Context.RequestData.ReadInt32();
|
||||
int Unknown2c = Context.RequestData.ReadInt32();
|
||||
int Rev1Magic = Context.RequestData.ReadInt32();
|
||||
|
||||
Context.ResponseData.Write(0x400L);
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue