Haydn: Part 1 (#2007)
* Haydn: Part 1 Based on my reverse of audio 11.0.0. As always, core implementation under LGPLv3 for the same reasons as for Amadeus. This place the bases of a more flexible audio system while making audout & audin accurate. This have the following improvements: - Complete reimplementation of audout and audin. - Audin currently only have a dummy backend. - Dramatically reduce CPU usage by up to 50% in common cases (SoundIO and OpenAL). - Audio Renderer now can output to 5.1 devices when supported. - Audio Renderer init its backend on demand instead of keeping two up all the time. - All backends implementation are now in their own project. - Ryujinx.Audio.Renderer was renamed Ryujinx.Audio and was refactored because of this. As a note, games having issues with OpenAL haven't improved and will not because of OpenAL design (stopping when buffers finish playing causing possible audio "pops" when buffers are very small). * Update for latest hexkyz's edits on Switchbrew * audren: Rollback channel configuration changes * Address gdkchan's comments * Fix typo in OpenAL backend driver * Address last comments * Fix a nit * Address gdkchan's comments
This commit is contained in:
parent
1c49089ff0
commit
f556c80d02
249 changed files with 5614 additions and 2712 deletions
|
@ -1,147 +1,12 @@
|
|||
using Ryujinx.Audio;
|
||||
using Ryujinx.Common.Logging;
|
||||
using Ryujinx.Cpu;
|
||||
using Ryujinx.HLE.HOS.Kernel.Threading;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioOutManager;
|
||||
using System.Text;
|
||||
using Ryujinx.Audio.Common;
|
||||
using Ryujinx.HLE.HOS.Services.Audio.AudioOut;
|
||||
|
||||
namespace Ryujinx.HLE.HOS.Services.Audio
|
||||
{
|
||||
[Service("audout:u")]
|
||||
class IAudioOutManager : IpcService
|
||||
interface IAudioOutManager
|
||||
{
|
||||
private const string DefaultAudioOutput = "DeviceOut";
|
||||
private const int DefaultSampleRate = 48000;
|
||||
private const int DefaultChannelsCount = 2;
|
||||
public string[] ListAudioOuts();
|
||||
|
||||
public IAudioOutManager(ServiceCtx context) : base(context.Device.System.AudOutServer) { }
|
||||
|
||||
[Command(0)]
|
||||
// ListAudioOuts() -> (u32 count, buffer<bytes, 6>)
|
||||
public ResultCode ListAudioOuts(ServiceCtx context)
|
||||
{
|
||||
return ListAudioOutsImpl(context, context.Request.ReceiveBuff[0].Position, context.Request.ReceiveBuff[0].Size);
|
||||
}
|
||||
|
||||
[Command(1)]
|
||||
// OpenAudioOut(u32 sample_rate, u16 unused, u16 channel_count, nn::applet::AppletResourceUserId, pid, handle<copy, process>, buffer<bytes, 5> name_in)
|
||||
// -> (u32 sample_rate, u32 channel_count, u32 pcm_format, u32, object<nn::audio::detail::IAudioOut>, buffer<bytes, 6> name_out)
|
||||
public ResultCode OpenAudioOut(ServiceCtx context)
|
||||
{
|
||||
return OpenAudioOutImpl(context, context.Request.SendBuff[0].Position, context.Request.SendBuff[0].Size,
|
||||
context.Request.ReceiveBuff[0].Position, context.Request.ReceiveBuff[0].Size);
|
||||
}
|
||||
|
||||
[Command(2)] // 3.0.0+
|
||||
// ListAudioOutsAuto() -> (u32 count, buffer<bytes, 0x22>)
|
||||
public ResultCode ListAudioOutsAuto(ServiceCtx context)
|
||||
{
|
||||
(long recvPosition, long recvSize) = context.Request.GetBufferType0x22();
|
||||
|
||||
return ListAudioOutsImpl(context, recvPosition, recvSize);
|
||||
}
|
||||
|
||||
[Command(3)] // 3.0.0+
|
||||
// OpenAudioOutAuto(u32 sample_rate, u16 unused, u16 channel_count, nn::applet::AppletResourceUserId, pid, handle<copy, process>, buffer<bytes, 0x21>)
|
||||
// -> (u32 sample_rate, u32 channel_count, u32 pcm_format, u32, object<nn::audio::detail::IAudioOut>, buffer<bytes, 0x22> name_out)
|
||||
public ResultCode OpenAudioOutAuto(ServiceCtx context)
|
||||
{
|
||||
(long sendPosition, long sendSize) = context.Request.GetBufferType0x21();
|
||||
(long recvPosition, long recvSize) = context.Request.GetBufferType0x22();
|
||||
|
||||
return OpenAudioOutImpl(context, sendPosition, sendSize, recvPosition, recvSize);
|
||||
}
|
||||
|
||||
private ResultCode ListAudioOutsImpl(ServiceCtx context, long position, long size)
|
||||
{
|
||||
int nameCount = 0;
|
||||
|
||||
byte[] deviceNameBuffer = Encoding.ASCII.GetBytes(DefaultAudioOutput + "\0");
|
||||
|
||||
if ((ulong)deviceNameBuffer.Length <= (ulong)size)
|
||||
{
|
||||
context.Memory.Write((ulong)position, deviceNameBuffer);
|
||||
|
||||
nameCount++;
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {size} too small!");
|
||||
}
|
||||
|
||||
context.ResponseData.Write(nameCount);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
|
||||
private ResultCode OpenAudioOutImpl(ServiceCtx context, long sendPosition, long sendSize, long receivePosition, long receiveSize)
|
||||
{
|
||||
string deviceName = MemoryHelper.ReadAsciiString(context.Memory, sendPosition, sendSize);
|
||||
|
||||
if (deviceName == string.Empty)
|
||||
{
|
||||
deviceName = DefaultAudioOutput;
|
||||
}
|
||||
|
||||
if (deviceName != DefaultAudioOutput)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Audio, "Invalid device name!");
|
||||
|
||||
return ResultCode.DeviceNotFound;
|
||||
}
|
||||
|
||||
byte[] deviceNameBuffer = Encoding.ASCII.GetBytes(deviceName + "\0");
|
||||
|
||||
if ((ulong)deviceNameBuffer.Length <= (ulong)receiveSize)
|
||||
{
|
||||
context.Memory.Write((ulong)receivePosition, deviceNameBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
Logger.Error?.Print(LogClass.ServiceAudio, $"Output buffer size {receiveSize} too small!");
|
||||
}
|
||||
|
||||
int sampleRate = context.RequestData.ReadInt32();
|
||||
int channels = context.RequestData.ReadInt32();
|
||||
|
||||
if (sampleRate == 0)
|
||||
{
|
||||
sampleRate = DefaultSampleRate;
|
||||
}
|
||||
|
||||
if (sampleRate != DefaultSampleRate)
|
||||
{
|
||||
Logger.Warning?.Print(LogClass.Audio, "Invalid sample rate!");
|
||||
|
||||
return ResultCode.UnsupportedSampleRate;
|
||||
}
|
||||
|
||||
channels = (ushort)channels;
|
||||
|
||||
if (channels == 0)
|
||||
{
|
||||
channels = DefaultChannelsCount;
|
||||
}
|
||||
|
||||
KEvent releaseEvent = new KEvent(context.Device.System.KernelContext);
|
||||
|
||||
ReleaseCallback callback = () =>
|
||||
{
|
||||
releaseEvent.ReadableEvent.Signal();
|
||||
};
|
||||
|
||||
IAalOutput audioOut = context.Device.AudioOut;
|
||||
|
||||
int track = audioOut.OpenTrack(sampleRate, channels, callback);
|
||||
|
||||
MakeObject(context, new IAudioOut(context.Device.System.KernelContext, audioOut, releaseEvent, track, context.Request.HandleDesc.ToCopy[0]));
|
||||
|
||||
context.ResponseData.Write(sampleRate);
|
||||
context.ResponseData.Write(channels);
|
||||
context.ResponseData.Write((int)SampleFormat.PcmInt16);
|
||||
context.ResponseData.Write((int)PlaybackState.Stopped);
|
||||
|
||||
return ResultCode.Success;
|
||||
}
|
||||
public ResultCode OpenAudioOut(ServiceCtx context, out string outputDeviceName, out AudioOutputConfiguration outputConfiguration, out IAudioOut obj, string inputDeviceName, ref AudioInputConfiguration parameter, ulong appletResourceUserId, uint processHandle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue