aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2024-12-22 23:26:04 +0100
committerDaniil Cherednik <dan.cherednik@gmail.com>2024-12-22 23:26:04 +0100
commita0a18fc3536c006c157c3988c3f95f6b32df22f8 (patch)
treeb28480dd0f5e2840e3fce01be4f35d498bd3039c
parenteb33c262156f4feb67c523908add841077574021 (diff)
downloadatracdenc-a0a18fc3536c006c157c3988c3f95f6b32df22f8.tar.gz
Do not check energy aware flag on each loop iterationnew_psy
-rw-r--r--src/atrac/atrac_scale.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/src/atrac/atrac_scale.cpp b/src/atrac/atrac_scale.cpp
index 5eff3d3..a436aae 100644
--- a/src/atrac/atrac_scale.cpp
+++ b/src/atrac/atrac_scale.cpp
@@ -41,25 +41,33 @@ float QuantMantisas(const float* in, const uint32_t first, const uint32_t last,
float e1 = 0.0;
float e2 = 0.0;
+ const float inv2 = 1.0 / (mul * mul);
+
+ if (!ea) {
+ for (uint32_t j = 0, f = first; f < last; f++, j++) {
+ float t = in[j] * mul;
+ e1 += in[j] * in[j];
+ mantisas[f] = ToInt(t);
+ e2 += mantisas[f] * mantisas[f] * inv2;
+ }
+ return e1 / e2;
+ }
+
std::vector<std::pair<float, int>> candidates;
candidates.reserve(last - first);
- const float inv2 = 1.0 / (mul * mul);
-
for (uint32_t j = 0, f = first; f < last; f++, j++) {
float t = in[j] * mul;
e1 += in[j] * in[j];
mantisas[f] = ToInt(t);
e2 += mantisas[f] * mantisas[f] * inv2;
- if (ea) {
- float delta = t - (std::truncf(t) + 0.5f);
- // 0 ... 0.25 ... 0.5 ... 0.75 ... 1
- // ^----------------^ candidates to be rounded to opposite side
- // to decrease overall energy error in the band
- if (std::abs(delta) < 0.25f) {
- candidates.push_back({delta, f});
- }
+ float delta = t - (std::truncf(t) + 0.5f);
+ // 0 ... 0.25 ... 0.5 ... 0.75 ... 1
+ // ^----------------^ candidates to be rounded to opposite side
+ // to decrease overall energy error in the band
+ if (std::abs(delta) < 0.25f) {
+ candidates.push_back({delta, f});
}
}