Write outputs on decode method, some basic error handling
This commit is contained in:
parent
f031e3a6fe
commit
75180521e9
2 changed files with 28 additions and 1 deletions
7
Ryujinx.HLE/OsHle/Services/Aud/AudErr.cs
Normal file
7
Ryujinx.HLE/OsHle/Services/Aud/AudErr.cs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
namespace Ryujinx.HLE.OsHle.Services.Aud
|
||||||
|
{
|
||||||
|
static class AudErr
|
||||||
|
{
|
||||||
|
public const int OpusInvalidInput = 6;
|
||||||
|
}
|
||||||
|
}
|
|
@ -2,6 +2,8 @@ using Concentus.Structs;
|
||||||
using Ryujinx.HLE.OsHle.Ipc;
|
using Ryujinx.HLE.OsHle.Ipc;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
using static Ryujinx.HLE.OsHle.ErrorCode;
|
||||||
|
|
||||||
namespace Ryujinx.HLE.OsHle.Services.Aud
|
namespace Ryujinx.HLE.OsHle.Services.Aud
|
||||||
{
|
{
|
||||||
class IHardwareOpusDecoder : IpcService
|
class IHardwareOpusDecoder : IpcService
|
||||||
|
@ -35,16 +37,31 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
|
||||||
long InPosition = Context.Request.SendBuff[0].Position;
|
long InPosition = Context.Request.SendBuff[0].Position;
|
||||||
long InSize = Context.Request.SendBuff[0].Size;
|
long InSize = Context.Request.SendBuff[0].Size;
|
||||||
|
|
||||||
|
if (InSize < 8)
|
||||||
|
{
|
||||||
|
return MakeError(ErrorModule.Audio, AudErr.OpusInvalidInput);
|
||||||
|
}
|
||||||
|
|
||||||
long OutPosition = Context.Request.ReceiveBuff[0].Position;
|
long OutPosition = Context.Request.ReceiveBuff[0].Position;
|
||||||
long OutSize = Context.Request.ReceiveBuff[0].Size;
|
long OutSize = Context.Request.ReceiveBuff[0].Size;
|
||||||
|
|
||||||
byte[] OpusData = Context.Memory.ReadBytes(InPosition, InSize);
|
byte[] OpusData = Context.Memory.ReadBytes(InPosition, InSize);
|
||||||
|
|
||||||
|
int Processed = ((OpusData[0] << 0) |
|
||||||
|
(OpusData[1] << 8) |
|
||||||
|
(OpusData[2] << 16) |
|
||||||
|
(OpusData[3] << 24)) + 8;
|
||||||
|
|
||||||
|
if (Processed > InSize)
|
||||||
|
{
|
||||||
|
return MakeError(ErrorModule.Audio, AudErr.OpusInvalidInput);
|
||||||
|
}
|
||||||
|
|
||||||
short[] Pcm = new short[OutSize / 2];
|
short[] Pcm = new short[OutSize / 2];
|
||||||
|
|
||||||
int FrameSize = Pcm.Length / (ChannelsCount * 2);
|
int FrameSize = Pcm.Length / (ChannelsCount * 2);
|
||||||
|
|
||||||
int Result = Decoder.Decode(OpusData, 0, OpusData.Length, Pcm, 0, FrameSize);
|
int Samples = Decoder.Decode(OpusData, 0, OpusData.Length, Pcm, 0, FrameSize);
|
||||||
|
|
||||||
foreach (short Sample in Pcm)
|
foreach (short Sample in Pcm)
|
||||||
{
|
{
|
||||||
|
@ -53,6 +70,9 @@ namespace Ryujinx.HLE.OsHle.Services.Aud
|
||||||
OutPosition += 2;
|
OutPosition += 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Context.ResponseData.Write(Samples);
|
||||||
|
Context.ResponseData.Write(Processed);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue