2020-08-17 21:49:37 -04:00
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
namespace Ryujinx.Audio.Renderer.Dsp
|
|
|
|
{
|
|
|
|
public static class FixedPointHelper
|
|
|
|
{
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
public static int ToInt(long value, int qBits)
|
|
|
|
{
|
|
|
|
return (int)(value >> qBits);
|
|
|
|
}
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
public static float ToFloat(long value, int qBits)
|
|
|
|
{
|
|
|
|
return (float)value / (1 << qBits);
|
|
|
|
}
|
|
|
|
|
2022-12-06 09:04:25 -05:00
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
public static float ConvertFloat(float value, int qBits)
|
|
|
|
{
|
|
|
|
return value / (1 << qBits);
|
|
|
|
}
|
|
|
|
|
2020-08-17 21:49:37 -04:00
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
public static int ToFixed(float value, int qBits)
|
|
|
|
{
|
|
|
|
return (int)(value * (1 << qBits));
|
|
|
|
}
|
|
|
|
|
|
|
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
|
|
|
public static int RoundUpAndToInt(long value, int qBits)
|
|
|
|
{
|
|
|
|
int half = 1 << (qBits - 1);
|
|
|
|
|
|
|
|
return ToInt(value + half, qBits);
|
|
|
|
}
|
|
|
|
}
|
2022-07-25 14:46:33 -04:00
|
|
|
}
|