using Ryujinx.Audio.Renderer.Server.MemoryPool;
using System.Runtime.InteropServices;
namespace Ryujinx.Audio.Renderer.Server.Voice
{
///
/// A wavebuffer used for server update.
///
[StructLayout(LayoutKind.Sequential, Size = 0x58, Pack = 1)]
public struct WaveBuffer
{
///
/// The of the sample data of the wavebuffer.
///
public AddressInfo BufferAddressInfo;
///
/// The of the context of the wavebuffer.
///
/// Only used by .
public AddressInfo ContextAddressInfo;
///
/// First sample to play of the wavebuffer.
///
public uint StartSampleOffset;
///
/// Last sample to play of the wavebuffer.
///
public uint EndSampleOffset;
///
/// Set to true if the wavebuffer is looping.
///
[MarshalAs(UnmanagedType.I1)]
public bool ShouldLoop;
///
/// Set to true if the wavebuffer is the end of stream.
///
[MarshalAs(UnmanagedType.I1)]
public bool IsEndOfStream;
///
/// Set to true if the wavebuffer wasn't sent to the .
///
[MarshalAs(UnmanagedType.I1)]
public bool IsSendToAudioProcessor;
///
/// First sample to play when looping the wavebuffer.
///
public uint LoopStartSampleOffset;
///
/// Last sample to play when looping the wavebuffer.
///
public uint LoopEndSampleOffset;
///
/// The max loop count.
///
public int LoopCount;
///
/// Create a new for use by the .
///
/// The target version of the wavebuffer.
/// A new for use by the .
public Common.WaveBuffer ToCommon(int version)
{
Common.WaveBuffer waveBuffer = new()
{
Buffer = BufferAddressInfo.GetReference(true),
BufferSize = (uint)BufferAddressInfo.Size,
};
if (ContextAddressInfo.CpuAddress != 0)
{
waveBuffer.Context = ContextAddressInfo.GetReference(true);
waveBuffer.ContextSize = (uint)ContextAddressInfo.Size;
}
waveBuffer.StartSampleOffset = StartSampleOffset;
waveBuffer.EndSampleOffset = EndSampleOffset;
waveBuffer.Looping = ShouldLoop;
waveBuffer.IsEndOfStream = IsEndOfStream;
if (version == 2)
{
waveBuffer.LoopCount = LoopCount;
waveBuffer.LoopStartSampleOffset = LoopStartSampleOffset;
waveBuffer.LoopEndSampleOffset = LoopEndSampleOffset;
}
else
{
waveBuffer.LoopCount = -1;
}
return waveBuffer;
}
}
}