diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2018-07-28 00:43:57 +0300 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2018-07-28 00:43:57 +0300 |
commit | a883931b0d2e40dbfb0a4534694bc98742c09296 (patch) | |
tree | cfb9ee8e572fe177d1644948f79d7b0e0996357c | |
parent | 4eade436667b31dd27f6bec7588c523d571eb664 (diff) | |
download | atracdenc-a883931b0d2e40dbfb0a4534694bc98742c09296.tar.gz |
Use lrint() + fesetround(FE_TONEAREST) instead of round() - a bit faster
-rw-r--r-- | src/atrac/atrac1_bitalloc.cpp | 2 | ||||
-rw-r--r-- | src/atrac/atrac1_bitalloc.h | 5 | ||||
-rw-r--r-- | src/atrac/atrac3_bitstream.cpp | 2 | ||||
-rw-r--r-- | src/atrac/atrac3_bitstream.h | 3 |
4 files changed, 8 insertions, 4 deletions
diff --git a/src/atrac/atrac1_bitalloc.cpp b/src/atrac/atrac1_bitalloc.cpp index f73b1cf..1a7b155 100644 --- a/src/atrac/atrac1_bitalloc.cpp +++ b/src/atrac/atrac1_bitalloc.cpp @@ -260,7 +260,7 @@ void TAtrac1BitStreamWriter::WriteBitStream(const vector<uint32_t>& bitsPerEachB const TFloat multiple = ((1 << (wordLength - 1)) - 1); for (const TFloat val : scaledBlocks[i].Values) { - const int tmp = round(val * multiple); + const int tmp = lrint(val * multiple); const uint32_t testwl = bitsPerEachBlock[i] ? (bitsPerEachBlock[i] - 1) : 0; const uint32_t a = !!testwl + testwl; if (a != wordLength) { diff --git a/src/atrac/atrac1_bitalloc.h b/src/atrac/atrac1_bitalloc.h index 84d17bf..695defc 100644 --- a/src/atrac/atrac1_bitalloc.h +++ b/src/atrac/atrac1_bitalloc.h @@ -24,6 +24,7 @@ #include <vector> #include <map> #include <cstdint> +#include <cfenv> namespace NAtracDEnc { namespace NAtrac1 { @@ -51,7 +52,9 @@ class TAtrac1BitStreamWriter : public virtual TAtrac1Data { public: explicit TAtrac1BitStreamWriter(TAea* container) : Container(container) - {}; + { + fesetround(FE_TONEAREST); + }; void WriteBitStream(const std::vector<uint32_t>& bitsPerEachBlock, const std::vector<TScaledBlock>& scaledBlocks, uint32_t bfuAmountIdx, const TBlockSize& blockSize); }; diff --git a/src/atrac/atrac3_bitstream.cpp b/src/atrac/atrac3_bitstream.cpp index d50d7ed..c976ac2 100644 --- a/src/atrac/atrac3_bitstream.cpp +++ b/src/atrac/atrac3_bitstream.cpp @@ -115,7 +115,7 @@ std::pair<uint8_t, uint32_t> TAtrac3BitStreamWriter::CalcSpecsBitsConsumption(co const TFloat mul = MaxQuant[std::min(precisionPerEachBlocks[i], (uint32_t)7)]; if (calcMant) { for (uint32_t j = 0, f = first; f < last; f++, j++) { - mantisas[f] = round(scaledBlocks[i].Values[j] * mul); + mantisas[f] = lrint(scaledBlocks[i].Values[j] * mul); } } bits += clcMode ? CLCEnc(precisionPerEachBlocks[i], mantisas + first, blockSize, nullptr) : diff --git a/src/atrac/atrac3_bitstream.h b/src/atrac/atrac3_bitstream.h index 4def07c..b65e212 100644 --- a/src/atrac/atrac3_bitstream.h +++ b/src/atrac/atrac3_bitstream.h @@ -25,6 +25,7 @@ #include "atrac_scale.h" #include <vector> #include <utility> +#include <cfenv> namespace NAtracDEnc { namespace NAtrac3 { @@ -88,7 +89,7 @@ public: , Params(params) , BfuIdxConst(bfuIdxConst) { - + fesetround(FE_TONEAREST); } void WriteSoundUnit(const std::vector<TSingleChannelElement>& singleChannelElements); |