aboutsummaryrefslogtreecommitdiff
path: root/Ryujinx.HLE/HOS/Services/Aud/AudioOut
diff options
context:
space:
mode:
authorgdkchan <gab.dark.100@gmail.com>2018-08-16 20:47:36 -0300
committerGitHub <noreply@github.com>2018-08-16 20:47:36 -0300
commit521751795a1c97c0d97f6f8904a3be69b13d3a9d (patch)
tree942a05899c40e2de6d92a38b93a494bd96ee64b8 /Ryujinx.HLE/HOS/Services/Aud/AudioOut
parent182d716867ae477c2b15a5332430dc2641fa1cc3 (diff)
Code style fixes and nits on the HLE project (#355)
* Some style fixes and nits on ITimeZoneService * Remove some unneeded usings * Remove the Ryujinx.HLE.OsHle.Handles namespace * Remove hbmenu automatic load on process exit * Rename Ns to Device, rename Os to System, rename SystemState to State * Move Exceptions and Utilities out of OsHle * Rename OsHle to HOS * Rename OsHle folder to HOS * IManagerDisplayService and ISystemDisplayService style fixes * BsdError shouldn't be public * Add a empty new line before using static * Remove unused file * Some style fixes on NPDM * Exit gracefully when the application is closed * Code style fixes on IGeneralService * Add 0x prefix on values printed as hex * Small improvements on finalization code * Move ProcessId and ThreadId out of AThreadState * Rename VFs to FileSystem * FsAccessHeader shouldn't be public. Also fix file names casing * More case changes on NPDM * Remove unused files * Move using to the correct place on NPDM * Use properties on KernelAccessControlMmio * Address PR feedback
Diffstat (limited to 'Ryujinx.HLE/HOS/Services/Aud/AudioOut')
-rw-r--r--Ryujinx.HLE/HOS/Services/Aud/AudioOut/AudioOutData.cs14
-rw-r--r--Ryujinx.HLE/HOS/Services/Aud/AudioOut/IAudioOut.cs163
2 files changed, 177 insertions, 0 deletions
diff --git a/Ryujinx.HLE/HOS/Services/Aud/AudioOut/AudioOutData.cs b/Ryujinx.HLE/HOS/Services/Aud/AudioOut/AudioOutData.cs
new file mode 100644
index 00000000..e25ebe66
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Aud/AudioOut/AudioOutData.cs
@@ -0,0 +1,14 @@
+using System.Runtime.InteropServices;
+
+namespace Ryujinx.HLE.HOS.Services.Aud.AudioOut
+{
+ [StructLayout(LayoutKind.Sequential)]
+ struct AudioOutData
+ {
+ public long NextBufferPtr;
+ public long SampleBufferPtr;
+ public long SampleBufferCapacity;
+ public long SampleBufferSize;
+ public long SampleBufferInnerOffset;
+ }
+} \ No newline at end of file
diff --git a/Ryujinx.HLE/HOS/Services/Aud/AudioOut/IAudioOut.cs b/Ryujinx.HLE/HOS/Services/Aud/AudioOut/IAudioOut.cs
new file mode 100644
index 00000000..81561f04
--- /dev/null
+++ b/Ryujinx.HLE/HOS/Services/Aud/AudioOut/IAudioOut.cs
@@ -0,0 +1,163 @@
+using ChocolArm64.Memory;
+using Ryujinx.Audio;
+using Ryujinx.HLE.HOS.Ipc;
+using Ryujinx.HLE.HOS.Kernel;
+using System;
+using System.Collections.Generic;
+
+namespace Ryujinx.HLE.HOS.Services.Aud.AudioOut
+{
+ class IAudioOut : IpcService, IDisposable
+ {
+ private Dictionary<int, ServiceProcessRequest> m_Commands;
+
+ public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
+
+ private IAalOutput AudioOut;
+
+ private KEvent ReleaseEvent;
+
+ private int Track;
+
+ public IAudioOut(IAalOutput AudioOut, KEvent ReleaseEvent, int Track)
+ {
+ m_Commands = new Dictionary<int, ServiceProcessRequest>()
+ {
+ { 0, GetAudioOutState },
+ { 1, StartAudioOut },
+ { 2, StopAudioOut },
+ { 3, AppendAudioOutBuffer },
+ { 4, RegisterBufferEvent },
+ { 5, GetReleasedAudioOutBuffer },
+ { 6, ContainsAudioOutBuffer },
+ { 7, AppendAudioOutBufferAuto },
+ { 8, GetReleasedAudioOutBufferAuto }
+ };
+
+ this.AudioOut = AudioOut;
+ this.ReleaseEvent = ReleaseEvent;
+ this.Track = Track;
+ }
+
+ public long GetAudioOutState(ServiceCtx Context)
+ {
+ Context.ResponseData.Write((int)AudioOut.GetState(Track));
+
+ return 0;
+ }
+
+ public long StartAudioOut(ServiceCtx Context)
+ {
+ AudioOut.Start(Track);
+
+ return 0;
+ }
+
+ public long StopAudioOut(ServiceCtx Context)
+ {
+ AudioOut.Stop(Track);
+
+ return 0;
+ }
+
+ public long AppendAudioOutBuffer(ServiceCtx Context)
+ {
+ return AppendAudioOutBufferImpl(Context, Context.Request.SendBuff[0].Position);
+ }
+
+ public long RegisterBufferEvent(ServiceCtx Context)
+ {
+ int Handle = Context.Process.HandleTable.OpenHandle(ReleaseEvent);
+
+ Context.Response.HandleDesc = IpcHandleDesc.MakeCopy(Handle);
+
+ return 0;
+ }
+
+ public long GetReleasedAudioOutBuffer(ServiceCtx Context)
+ {
+ long Position = Context.Request.ReceiveBuff[0].Position;
+ long Size = Context.Request.ReceiveBuff[0].Size;
+
+ return GetReleasedAudioOutBufferImpl(Context, Position, Size);
+ }
+
+ public long ContainsAudioOutBuffer(ServiceCtx Context)
+ {
+ long Tag = Context.RequestData.ReadInt64();
+
+ Context.ResponseData.Write(AudioOut.ContainsBuffer(Track, Tag) ? 1 : 0);
+
+ return 0;
+ }
+
+ public long AppendAudioOutBufferAuto(ServiceCtx Context)
+ {
+ (long Position, long Size) = Context.Request.GetBufferType0x21();
+
+ return AppendAudioOutBufferImpl(Context, Position);
+ }
+
+ public long AppendAudioOutBufferImpl(ServiceCtx Context, long Position)
+ {
+ long Tag = Context.RequestData.ReadInt64();
+
+ AudioOutData Data = AMemoryHelper.Read<AudioOutData>(
+ Context.Memory,
+ Position);
+
+ byte[] Buffer = Context.Memory.ReadBytes(
+ Data.SampleBufferPtr,
+ Data.SampleBufferSize);
+
+ AudioOut.AppendBuffer(Track, Tag, Buffer);
+
+ return 0;
+ }
+
+ public long GetReleasedAudioOutBufferAuto(ServiceCtx Context)
+ {
+ (long Position, long Size) = Context.Request.GetBufferType0x22();
+
+ return GetReleasedAudioOutBufferImpl(Context, Position, Size);
+ }
+
+ public long GetReleasedAudioOutBufferImpl(ServiceCtx Context, long Position, long Size)
+ {
+ uint Count = (uint)((ulong)Size >> 3);
+
+ long[] ReleasedBuffers = AudioOut.GetReleasedBuffers(Track, (int)Count);
+
+ for (uint Index = 0; Index < Count; Index++)
+ {
+ long Tag = 0;
+
+ if (Index < ReleasedBuffers.Length)
+ {
+ Tag = ReleasedBuffers[Index];
+ }
+
+ Context.Memory.WriteInt64(Position + Index * 8, Tag);
+ }
+
+ Context.ResponseData.Write(ReleasedBuffers.Length);
+
+ return 0;
+ }
+
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ protected virtual void Dispose(bool Disposing)
+ {
+ if (Disposing)
+ {
+ AudioOut.CloseTrack(Track);
+
+ ReleaseEvent.Dispose();
+ }
+ }
+ }
+}