2018-02-25 05:34:16 +01:00
|
|
|
using ChocolArm64.Memory;
|
2018-03-16 01:06:24 +01:00
|
|
|
using Ryujinx.Audio;
|
2018-03-19 19:58:46 +01:00
|
|
|
using Ryujinx.Core.OsHle.Handles;
|
2018-02-25 05:34:16 +01:00
|
|
|
using Ryujinx.Core.OsHle.Ipc;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
namespace Ryujinx.Core.OsHle.IpcServices.Aud
|
|
|
|
{
|
2018-03-19 19:58:46 +01:00
|
|
|
class ServiceAudOut : IpcService
|
2018-02-25 05:34:16 +01:00
|
|
|
{
|
|
|
|
private Dictionary<int, ServiceProcessRequest> m_Commands;
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
|
2018-02-25 05:34:16 +01:00
|
|
|
|
|
|
|
public ServiceAudOut()
|
|
|
|
{
|
|
|
|
m_Commands = new Dictionary<int, ServiceProcessRequest>()
|
|
|
|
{
|
|
|
|
{ 0, ListAudioOuts },
|
2018-03-16 01:06:24 +01:00
|
|
|
{ 1, OpenAudioOut }
|
2018-02-25 05:34:16 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2018-03-16 01:06:24 +01:00
|
|
|
IAalOutput AudioOut = Context.Ns.AudioOut;
|
|
|
|
|
|
|
|
string DeviceName = AMemoryHelper.ReadAsciiString(
|
|
|
|
Context.Memory,
|
|
|
|
Context.Request.SendBuff[0].Position,
|
|
|
|
Context.Request.SendBuff[0].Size);
|
|
|
|
|
|
|
|
if (DeviceName == string.Empty)
|
|
|
|
{
|
|
|
|
DeviceName = "FIXME";
|
|
|
|
}
|
|
|
|
|
|
|
|
long DeviceNamePosition = Context.Request.ReceiveBuff[0].Position;
|
|
|
|
long DeviceNameSize = Context.Request.ReceiveBuff[0].Size;
|
|
|
|
|
|
|
|
byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName);
|
|
|
|
|
|
|
|
if (DeviceName.Length <= DeviceNameSize)
|
|
|
|
{
|
|
|
|
AMemoryHelper.WriteBytes(Context.Memory, DeviceNamePosition, DeviceNameBuffer);
|
|
|
|
}
|
|
|
|
|
|
|
|
int SampleRate = Context.RequestData.ReadInt32();
|
|
|
|
int Channels = Context.RequestData.ReadInt32();
|
|
|
|
|
|
|
|
Channels = (ushort)(Channels >> 16);
|
|
|
|
|
|
|
|
if (SampleRate == 0)
|
|
|
|
{
|
|
|
|
SampleRate = 48000;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (Channels < 1 || Channels > 2)
|
|
|
|
{
|
|
|
|
Channels = 2;
|
|
|
|
}
|
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
KEvent ReleaseEvent = new KEvent();
|
|
|
|
|
|
|
|
ReleaseCallback Callback = () =>
|
|
|
|
{
|
|
|
|
ReleaseEvent.Handle.Set();
|
|
|
|
};
|
|
|
|
|
|
|
|
int Track = AudioOut.OpenTrack(SampleRate, Channels, Callback, out AudioFormat Format);
|
2018-03-16 01:06:24 +01:00
|
|
|
|
2018-03-19 19:58:46 +01:00
|
|
|
MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track));
|
2018-03-16 01:06:24 +01:00
|
|
|
|
|
|
|
Context.ResponseData.Write(SampleRate);
|
|
|
|
Context.ResponseData.Write(Channels);
|
|
|
|
Context.ResponseData.Write((int)Format);
|
|
|
|
Context.ResponseData.Write((int)PlaybackState.Stopped);
|
2018-02-25 05:34:16 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|