LimiterEffect.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. //
  2. // Copyright (c) 2019-2021 Ryujinx
  3. //
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Lesser General Public License
  15. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. //
  17. using Ryujinx.Audio.Renderer.Common;
  18. using Ryujinx.Audio.Renderer.Dsp.State;
  19. using Ryujinx.Audio.Renderer.Parameter;
  20. using Ryujinx.Audio.Renderer.Parameter.Effect;
  21. using Ryujinx.Audio.Renderer.Server.MemoryPool;
  22. using System;
  23. using System.Diagnostics;
  24. using System.Runtime.InteropServices;
  25. namespace Ryujinx.Audio.Renderer.Server.Effect
  26. {
  27. /// <summary>
  28. /// Server state for a limiter effect.
  29. /// </summary>
  30. public class LimiterEffect : BaseEffect
  31. {
  32. /// <summary>
  33. /// The limiter parameter.
  34. /// </summary>
  35. public LimiterParameter Parameter;
  36. /// <summary>
  37. /// The limiter state.
  38. /// </summary>
  39. public Memory<LimiterState> State { get; }
  40. /// <summary>
  41. /// Create a new <see cref="LimiterEffect"/>.
  42. /// </summary>
  43. public LimiterEffect()
  44. {
  45. State = new LimiterState[1];
  46. }
  47. public override EffectType TargetEffectType => EffectType.Limiter;
  48. public override ulong GetWorkBuffer(int index)
  49. {
  50. return GetSingleBuffer();
  51. }
  52. public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameterVersion1 parameter, PoolMapper mapper)
  53. {
  54. Update(out updateErrorInfo, ref parameter, mapper);
  55. }
  56. public override void Update(out BehaviourParameter.ErrorInfo updateErrorInfo, ref EffectInParameterVersion2 parameter, PoolMapper mapper)
  57. {
  58. Update(out updateErrorInfo, ref parameter, mapper);
  59. }
  60. public void Update<T>(out BehaviourParameter.ErrorInfo updateErrorInfo, ref T parameter, PoolMapper mapper) where T : unmanaged, IEffectInParameter
  61. {
  62. Debug.Assert(IsTypeValid(ref parameter));
  63. ref LimiterParameter limiterParameter = ref MemoryMarshal.Cast<byte, LimiterParameter>(parameter.SpecificData)[0];
  64. updateErrorInfo = new BehaviourParameter.ErrorInfo();
  65. UpdateParameterBase(ref parameter);
  66. Parameter = limiterParameter;
  67. IsEnabled = parameter.IsEnabled;
  68. if (BufferUnmapped || parameter.IsNew)
  69. {
  70. UsageState = UsageState.New;
  71. Parameter.Status = UsageState.Invalid;
  72. BufferUnmapped = !mapper.TryAttachBuffer(out updateErrorInfo, ref WorkBuffers[0], parameter.BufferBase, parameter.BufferSize);
  73. }
  74. }
  75. public override void UpdateForCommandGeneration()
  76. {
  77. UpdateUsageStateForCommandGeneration();
  78. Parameter.Status = UsageState.Enabled;
  79. Parameter.StatisticsReset = false;
  80. }
  81. public override void InitializeResultState(ref EffectResultState state)
  82. {
  83. ref LimiterStatistics statistics = ref MemoryMarshal.Cast<byte, LimiterStatistics>(state.SpecificData)[0];
  84. statistics.Reset();
  85. }
  86. public override void UpdateResultState(ref EffectResultState destState, ref EffectResultState srcState)
  87. {
  88. destState = srcState;
  89. }
  90. }
  91. }