CompressorState.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using Ryujinx.Audio.Renderer.Dsp.Effect;
  2. using Ryujinx.Audio.Renderer.Parameter.Effect;
  3. namespace Ryujinx.Audio.Renderer.Dsp.State
  4. {
  5. public class CompressorState
  6. {
  7. public ExponentialMovingAverage InputMovingAverage;
  8. public float Unknown4;
  9. public ExponentialMovingAverage CompressionGainAverage;
  10. public float CompressorGainReduction;
  11. public float Unknown10;
  12. public float Unknown14;
  13. public float PreviousCompressionEmaAlpha;
  14. public float MakeupGain;
  15. public float OutputGain;
  16. public CompressorState(ref CompressorParameter parameter)
  17. {
  18. InputMovingAverage = new ExponentialMovingAverage(0.0f);
  19. Unknown4 = 1.0f;
  20. CompressionGainAverage = new ExponentialMovingAverage(1.0f);
  21. UpdateParameter(ref parameter);
  22. }
  23. public void UpdateParameter(ref CompressorParameter parameter)
  24. {
  25. float threshold = parameter.Threshold;
  26. float ratio = 1.0f / parameter.Ratio;
  27. float attackCoefficient = parameter.AttackCoefficient;
  28. float makeupGain;
  29. if (parameter.MakeupGainEnabled)
  30. {
  31. makeupGain = (threshold * 0.5f * (ratio - 1.0f)) - 3.0f;
  32. }
  33. else
  34. {
  35. makeupGain = 0.0f;
  36. }
  37. PreviousCompressionEmaAlpha = attackCoefficient;
  38. MakeupGain = makeupGain;
  39. CompressorGainReduction = (1.0f - ratio) / Constants.ChannelCountMax;
  40. Unknown10 = threshold - 1.5f;
  41. Unknown14 = threshold + 1.5f;
  42. OutputGain = FloatingPointHelper.DecibelToLinearExtended(parameter.OutputGain + makeupGain);
  43. }
  44. }
  45. }