DeviceSink.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using Ryujinx.Audio.Renderer.Common;
  2. using Ryujinx.Audio.Renderer.Parameter;
  3. using Ryujinx.Audio.Renderer.Parameter.Sink;
  4. using Ryujinx.Audio.Renderer.Server.MemoryPool;
  5. using Ryujinx.Audio.Renderer.Server.Upsampler;
  6. using System;
  7. using System.Diagnostics;
  8. using System.Runtime.InteropServices;
  9. namespace Ryujinx.Audio.Renderer.Server.Sink
  10. {
  11. /// <summary>
  12. /// Server information for a device sink.
  13. /// </summary>
  14. public class DeviceSink : BaseSink
  15. {
  16. /// <summary>
  17. /// The downmix coefficients.
  18. /// </summary>
  19. public float[] DownMixCoefficients;
  20. /// <summary>
  21. /// The device parameters.
  22. /// </summary>
  23. public DeviceParameter Parameter;
  24. /// <summary>
  25. /// The upsampler instance used by this sink.
  26. /// </summary>
  27. /// <remarks>Null if no upsampling is needed.</remarks>
  28. public UpsamplerState UpsamplerState;
  29. /// <summary>
  30. /// Create a new <see cref="DeviceSink"/>.
  31. /// </summary>
  32. public DeviceSink()
  33. {
  34. DownMixCoefficients = new float[4];
  35. }
  36. public override void CleanUp()
  37. {
  38. UpsamplerState?.Release();
  39. UpsamplerState = null;
  40. base.CleanUp();
  41. }
  42. public override SinkType TargetSinkType => SinkType.Device;
  43. public override void Update(out BehaviourParameter.ErrorInfo errorInfo, ref SinkInParameter parameter, ref SinkOutStatus outStatus, PoolMapper mapper)
  44. {
  45. Debug.Assert(IsTypeValid(ref parameter));
  46. ref DeviceParameter inputDeviceParameter = ref MemoryMarshal.Cast<byte, DeviceParameter>(parameter.SpecificData)[0];
  47. if (parameter.IsUsed != IsUsed)
  48. {
  49. UpdateStandardParameter(ref parameter);
  50. Parameter = inputDeviceParameter;
  51. }
  52. else
  53. {
  54. Parameter.DownMixParameterEnabled = inputDeviceParameter.DownMixParameterEnabled;
  55. inputDeviceParameter.DownMixParameter.AsSpan().CopyTo(Parameter.DownMixParameter.AsSpan());
  56. }
  57. Parameter.DownMixParameter.AsSpan().CopyTo(DownMixCoefficients.AsSpan());
  58. errorInfo = new BehaviourParameter.ErrorInfo();
  59. outStatus = new SinkOutStatus();
  60. }
  61. }
  62. }