DelayEffect.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. using Ryujinx.Audio.Renderer.Common;
  2. using Ryujinx.Audio.Renderer.Dsp.State;
  3. using Ryujinx.Audio.Renderer.Parameter;
  4. using Ryujinx.Audio.Renderer.Parameter.Effect;
  5. using Ryujinx.Audio.Renderer.Server.MemoryPool;
  6. using System;
  7. using System.Diagnostics;
  8. using System.Runtime.InteropServices;
  9. using DspAddress = System.UInt64;
  10. namespace Ryujinx.Audio.Renderer.Server.Effect
  11. {
  12. /// <summary>
  13. /// Server state for a delay effect.
  14. /// </summary>
  15. public class DelayEffect : BaseEffect
  16. {
  17. /// <summary>
  18. /// The delay parameter.
  19. /// </summary>
  20. public DelayParameter Parameter;
  21. /// <summary>
  22. /// The delay state.
  23. /// </summary>
  24. public Memory<DelayState> State { get; }
  25. public DelayEffect()
  26. {
  27. State = new DelayState[1];
  28. }
  29. public override EffectType TargetEffectType => EffectType.Delay;
  30. public override DspAddress GetWorkBuffer(int index)
  31. {
  32. return GetSingleBuffer();
  33. }
  34. public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameterVersion1 parameter, PoolMapper mapper)
  35. {
  36. Update(out updateErrorInfo, ref parameter, mapper);
  37. }
  38. public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameterVersion2 parameter, PoolMapper mapper)
  39. {
  40. Update(out updateErrorInfo, ref parameter, mapper);
  41. }
  42. public void Update<T>(out BehaviourParameter.ErrorInfo updateErrorInfo, ref T parameter, PoolMapper mapper) where T : unmanaged, IEffectInParameter
  43. {
  44. Debug.Assert(IsTypeValid(ref parameter));
  45. ref DelayParameter delayParameter = ref MemoryMarshal.Cast<byte, DelayParameter>(parameter.SpecificData)[0];
  46. updateErrorInfo = new BehaviourParameter.ErrorInfo();
  47. if (delayParameter.IsChannelCountMaxValid())
  48. {
  49. UpdateParameterBase(ref parameter);
  50. UsageState oldParameterStatus = Parameter.Status;
  51. Parameter = delayParameter;
  52. if (delayParameter.IsChannelCountValid())
  53. {
  54. IsEnabled = parameter.IsEnabled;
  55. if (oldParameterStatus != UsageState.Enabled)
  56. {
  57. Parameter.Status = oldParameterStatus;
  58. }
  59. if (BufferUnmapped || parameter.IsNew)
  60. {
  61. UsageState = UsageState.New;
  62. Parameter.Status = UsageState.Invalid;
  63. BufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[0], parameter.BufferBase, parameter.BufferSize);
  64. }
  65. }
  66. }
  67. }
  68. public override void UpdateForCommandGeneration()
  69. {
  70. UpdateUsageStateForCommandGeneration();
  71. Parameter.Status = UsageState.Enabled;
  72. }
  73. }
  74. }