Improvements to IAudioOutManager (#232)

* Improvements to IAudioOutManager

* Make implementation private
This commit is contained in:
gdkchan 2018-07-08 12:42:10 -03:00 committed by GitHub
parent af1516a146
commit dc04b5465f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 62 additions and 32 deletions

View file

@ -0,0 +1,8 @@
namespace Ryujinx.HLE.OsHle.Services.Aud
{
static class AudErr
{
public const int DeviceNotFound = 1;
public const int UnsupportedSampleRate = 3;
}
}

View file

@ -6,6 +6,8 @@ using Ryujinx.HLE.OsHle.Ipc;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text; using System.Text;
using static Ryujinx.HLE.OsHle.ErrorCode;
namespace Ryujinx.HLE.OsHle.Services.Aud namespace Ryujinx.HLE.OsHle.Services.Aud
{ {
class IAudioOutManager : IpcService class IAudioOutManager : IpcService
@ -29,35 +31,43 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
public long ListAudioOuts(ServiceCtx Context) public long ListAudioOuts(ServiceCtx Context)
{ {
ListAudioOutsMethod(Context, Context.Request.ReceiveBuff[0].Position, Context.Request.ReceiveBuff[0].Size); return ListAudioOutsImpl(
Context,
return 0; Context.Request.ReceiveBuff[0].Position,
Context.Request.ReceiveBuff[0].Size);
} }
public long OpenAudioOut(ServiceCtx Context) public long OpenAudioOut(ServiceCtx Context)
{ {
OpenAudioOutMethod(Context, Context.Request.SendBuff[0].Position, Context.Request.SendBuff[0].Size, return OpenAudioOutImpl(
Context.Request.ReceiveBuff[0].Position, Context.Request.ReceiveBuff[0].Size); Context,
Context.Request.SendBuff[0].Position,
return 0; Context.Request.SendBuff[0].Size,
Context.Request.ReceiveBuff[0].Position,
Context.Request.ReceiveBuff[0].Size);
} }
public long ListAudioOutsAuto(ServiceCtx Context) public long ListAudioOutsAuto(ServiceCtx Context)
{ {
ListAudioOutsMethod(Context, Context.Request.GetBufferType0x22().Position, Context.Request.GetBufferType0x22().Size); (long RecvPosition, long RecvSize) = Context.Request.GetBufferType0x22();
return 0; return ListAudioOutsImpl(Context, RecvPosition, RecvSize);
} }
public long OpenAudioOutAuto(ServiceCtx Context) public long OpenAudioOutAuto(ServiceCtx Context)
{ {
OpenAudioOutMethod(Context, Context.Request.GetBufferType0x21().Position, Context.Request.GetBufferType0x21().Size, (long SendPosition, long SendSize) = Context.Request.GetBufferType0x21();
Context.Request.GetBufferType0x22().Position, Context.Request.GetBufferType0x22().Size); (long RecvPosition, long RecvSize) = Context.Request.GetBufferType0x22();
return 0; return OpenAudioOutImpl(
Context,
SendPosition,
SendSize,
RecvPosition,
RecvSize);
} }
public void ListAudioOutsMethod(ServiceCtx Context, long Position, long Size) private long ListAudioOutsImpl(ServiceCtx Context, long Position, long Size)
{ {
int NameCount = 0; int NameCount = 0;
@ -75,23 +85,29 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
} }
Context.ResponseData.Write(NameCount); Context.ResponseData.Write(NameCount);
return 0;
} }
public void OpenAudioOutMethod(ServiceCtx Context, long SendPosition, long SendSize, long ReceivePosition, long ReceiveSize) private long OpenAudioOutImpl(ServiceCtx Context, long SendPosition, long SendSize, long ReceivePosition, long ReceiveSize)
{ {
IAalOutput AudioOut = Context.Ns.AudioOut;
string DeviceName = AMemoryHelper.ReadAsciiString( string DeviceName = AMemoryHelper.ReadAsciiString(
Context.Memory, Context.Memory,
SendPosition, SendPosition,
SendSize SendSize);
);
if (DeviceName == string.Empty) if (DeviceName == string.Empty)
{ {
DeviceName = DefaultAudioOutput; DeviceName = DefaultAudioOutput;
} }
if (DeviceName != DefaultAudioOutput)
{
Context.Ns.Log.PrintWarning(LogClass.Audio, "Invalid device name!");
return MakeError(ErrorModule.Audio, AudErr.DeviceNotFound);
}
byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName + "\0"); byte[] DeviceNameBuffer = Encoding.ASCII.GetBytes(DeviceName + "\0");
if ((ulong)DeviceNameBuffer.Length <= (ulong)ReceiveSize) if ((ulong)DeviceNameBuffer.Length <= (ulong)ReceiveSize)
@ -106,14 +122,16 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
int SampleRate = Context.RequestData.ReadInt32(); int SampleRate = Context.RequestData.ReadInt32();
int Channels = Context.RequestData.ReadInt32(); int Channels = Context.RequestData.ReadInt32();
Channels = (ushort)(Channels >> 16); if (SampleRate != 48000)
if (SampleRate == 0)
{ {
SampleRate = 48000; Context.Ns.Log.PrintWarning(LogClass.Audio, "Invalid sample rate!");
return MakeError(ErrorModule.Audio, AudErr.UnsupportedSampleRate);
} }
if (Channels < 1 || Channels > 2) Channels = (ushort)Channels;
if (Channels == 0)
{ {
Channels = 2; Channels = 2;
} }
@ -125,7 +143,9 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
ReleaseEvent.WaitEvent.Set(); ReleaseEvent.WaitEvent.Set();
}; };
int Track = AudioOut.OpenTrack(SampleRate, Channels, Callback, out AudioFormat Format); IAalOutput AudioOut = Context.Ns.AudioOut;
int Track = AudioOut.OpenTrack(SampleRate, 2, Callback, out AudioFormat Format);
MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track)); MakeObject(Context, new IAudioOut(AudioOut, ReleaseEvent, Track));
@ -133,6 +153,8 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
Context.ResponseData.Write(Channels); Context.ResponseData.Write(Channels);
Context.ResponseData.Write((int)Format); Context.ResponseData.Write((int)Format);
Context.ResponseData.Write((int)PlaybackState.Stopped); Context.ResponseData.Write((int)PlaybackState.Stopped);
return 0;
} }
} }
} }