Increase rounded sound alias float value precision until it is equal to initial value

This commit is contained in:
Jbleezy
2024-10-07 06:41:59 -07:00
parent 93a35f5dcf
commit ed06700f99
4 changed files with 78 additions and 33 deletions

View File

@ -2,6 +2,8 @@
#include "Utils/Pack.h"
#include <cmath>
using namespace T6;
PackedTexCoords Common::Vec2PackTexCoords(const float (&in)[2])
@ -33,3 +35,27 @@ void Common::Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4])
{
pack32::Vec4UnpackGfxColor(in.packed, out);
}
float Common::LinearToDbspl(const float linear)
{
const auto db = 20.0f * std::log10(std::max(linear, 0.0000152879f));
if (db > -95.0f)
return db + 100.0f;
return 0;
}
float Common::DbsplToLinear(const float dbsplValue)
{
return std::pow(10.0f, (dbsplValue - 100.0f) / 20.0f);
}
float Common::HertzToCents(const float hertz)
{
return 1200.0f * std::log2(hertz);
}
float Common::CentsToHertz(const float cents)
{
return std::pow(2.0f, cents / 1200.0f);
}

View File

@ -102,5 +102,9 @@ namespace T6
static void Vec2UnpackTexCoords(const PackedTexCoords& in, float (&out)[2]);
static void Vec3UnpackUnitVec(const PackedUnitVec& in, float (&out)[3]);
static void Vec4UnpackGfxColor(const GfxColor& in, float (&out)[4]);
static float LinearToDbspl(const float linear);
static float DbsplToLinear(const float dbsplValue);
static float HertzToCents(const float hertz);
static float CentsToHertz(const float cents);
};
} // namespace T6