// // Copyright (c) 2019-2021 Ryujinx // // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser General Public License // along with this program. If not, see . // 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 Common.WaveBuffer(); waveBuffer.Buffer = BufferAddressInfo.GetReference(true); waveBuffer.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; } } }