aboutsummaryrefslogtreecommitdiffstats
path: root/src/atrac/atrac_psy_common.cpp
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2024-10-11 00:07:48 +0200
committerDaniil Cherednik <dan.cherednik@gmail.com>2024-10-11 00:07:48 +0200
commit57ba306db046601b96b5a1943e63574a37c5e96c (patch)
tree85103e059c0153923bcb844ea69f7117e6d9b8a5 /src/atrac/atrac_psy_common.cpp
parentfe377370c1ae4691a65270123345f225e3159ed8 (diff)
downloadatracdenc-57ba306db046601b96b5a1943e63574a37c5e96c.tar.gz
Attempt to use adaptive ATH for ATRAC1new_psy
Diffstat (limited to 'src/atrac/atrac_psy_common.cpp')
-rw-r--r--src/atrac/atrac_psy_common.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/atrac/atrac_psy_common.cpp b/src/atrac/atrac_psy_common.cpp
index 089bf47..18f855c 100644
--- a/src/atrac/atrac_psy_common.cpp
+++ b/src/atrac/atrac_psy_common.cpp
@@ -135,4 +135,40 @@ vector<float> CalcATH(int len, int sampleRate)
return res;
}
+float TrackLoudness(float prevLoud, const TFloat* e0, const TFloat* e1, const float* weight, size_t sz)
+{
+ float s = 0;
+ if (e1 != nullptr) {
+ for (size_t i = 0; i < sz; i++) {
+ s += (e0[i] + e1[i]) * weight[i];
+ }
+
+ s *= 0.5;
+
+ } else {
+ for (size_t i = 0; i < sz; i++) {
+ s += e0[i] * weight[i];
+ }
+ }
+
+ return 0.98 * prevLoud + 0.02 * s;
+}
+
+vector<float> CreateLoudnessCurve(size_t sz)
+{
+ std::vector<float> res;
+ res.resize(sz);
+
+ for (size_t i = 0; i < sz; i++) {
+ float f = (float)(i + 3) * 0.5 * 44100 / (float)sz;
+ float t = std::log10(f) - 3.5;
+ t = -10 * t * t + 3 - f / 3000;
+ t = std::pow(10, (0.1 * t));
+ //std::cerr << i << " => " << f << " " << t <<std::endl;
+ res[i] = t;
+ }
+
+ return res;
+}
+
} // namespace NAtracDEnc