FixedPointHelper.cs 916 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Runtime.CompilerServices;
  2. namespace Ryujinx.Audio.Renderer.Dsp
  3. {
  4. public static class FixedPointHelper
  5. {
  6. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  7. public static int ToInt(long value, int qBits)
  8. {
  9. return (int)(value >> qBits);
  10. }
  11. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  12. public static float ToFloat(long value, int qBits)
  13. {
  14. return (float)value / (1 << qBits);
  15. }
  16. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  17. public static int ToFixed(float value, int qBits)
  18. {
  19. return (int)(value * (1 << qBits));
  20. }
  21. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  22. public static int RoundUpAndToInt(long value, int qBits)
  23. {
  24. int half = 1 << (qBits - 1);
  25. return ToInt(value + half, qBits);
  26. }
  27. }
  28. }