IDelayLine.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. namespace Ryujinx.Audio.Renderer.Dsp.Effect
  4. {
  5. public interface IDelayLine
  6. {
  7. uint CurrentSampleCount { get; }
  8. uint SampleCountMax { get; }
  9. void SetDelay(float delayTime);
  10. float Read();
  11. float Update(float value);
  12. float TapUnsafe(uint sampleIndex, int offset);
  13. float Tap(uint sampleIndex);
  14. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  15. public static float Tap(Span<float> workBuffer, int baseIndex, int sampleIndex, int delaySampleCount)
  16. {
  17. int targetIndex = baseIndex - sampleIndex;
  18. if (targetIndex < 0)
  19. {
  20. targetIndex += delaySampleCount;
  21. }
  22. return workBuffer[targetIndex];
  23. }
  24. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  25. public static uint GetSampleCount(uint sampleRate, float delayTime)
  26. {
  27. return (uint)MathF.Round(sampleRate * delayTime);
  28. }
  29. }
  30. }