From cfb7c7ca78bce595a985e797d19f8b0234f156a8 Mon Sep 17 00:00:00 2001 From: Jbleezy Date: Tue, 8 Oct 2024 11:56:52 -0700 Subject: [PATCH] Save format string instead of float --- .../T6/AssetDumpers/AssetDumperSndBank.cpp | 21 +++++++++++-------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp index e3b213ee..39ee1e4b 100644 --- a/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp +++ b/src/ObjWriting/Game/T6/AssetDumpers/AssetDumperSndBank.cpp @@ -384,17 +384,18 @@ namespace const auto linear = static_cast(value) / static_cast(std::numeric_limits::max()); const auto dbSpl = std::clamp(Common::LinearToDbspl(linear), 0.0f, 100.0f); - float dbSplRound; + std::string dbSplFormat; for (auto i = 0; i <= 4; i++) { - dbSplRound = std::stof(std::format("{:.{}f}", dbSpl, i)); + dbSplFormat = std::format("{:.{}f}", dbSpl, i); + const auto dbSplRound = std::stof(dbSplFormat); const auto dbSplRoundToValue = static_cast(Common::DbsplToLinear(dbSplRound) * static_cast(std::numeric_limits::max())); if (dbSplRoundToValue == value) break; } - stream.WriteColumn(std::format("{}", dbSplRound)); + stream.WriteColumn(dbSplFormat); } void WriteColumnPitchHertz(CsvOutputStream& stream, const uint16_t value) @@ -402,34 +403,36 @@ namespace const auto hertz = static_cast(value) / static_cast(std::numeric_limits::max()); const auto cents = std::clamp(Common::HertzToCents(hertz), -2400.0f, 1200.0f); - float centsRound; + std::string centsFormat; for (auto i = 0; i <= 4; i++) { - centsRound = std::stof(std::format("{:.{}f}", cents, i)); + centsFormat = std::format("{:.{}f}", cents, i); + const auto centsRound = std::stof(centsFormat); const auto centsRoundToValue = static_cast(Common::CentsToHertz(centsRound) * static_cast(std::numeric_limits::max())); if (centsRoundToValue == value) break; } - stream.WriteColumn(std::format("{}", centsRound)); + stream.WriteColumn(centsFormat); } void WriteColumnNormByte(CsvOutputStream& stream, const uint8_t value) { const auto normValue = static_cast(value) / static_cast(std::numeric_limits::max()); - float normValueRound; + std::string normValueFormat; for (auto i = 0; i <= 4; i++) { - normValueRound = std::stof(std::format("{:.{}f}", normValue, i)); + normValueFormat = std::format("{:.{}f}", normValue, i); + const auto normValueRound = std::stof(normValueFormat); const auto normValueRoundToValue = static_cast(normValueRound * static_cast(std::numeric_limits::max())); if (normValueRoundToValue == value) break; } - stream.WriteColumn(std::format("{}", normValueRound)); + stream.WriteColumn(normValueFormat); } void WriteColumnWithKnownHashes(CsvOutputStream& stream, const std::unordered_map& knownValues, const unsigned value)