diff options
author | Daniil Cherednik <dan.cherednik@gmail.com> | 2024-10-11 00:07:48 +0200 |
---|---|---|
committer | Daniil Cherednik <dan.cherednik@gmail.com> | 2024-10-11 00:07:48 +0200 |
commit | 57ba306db046601b96b5a1943e63574a37c5e96c (patch) | |
tree | 85103e059c0153923bcb844ea69f7117e6d9b8a5 /src/atrac/atrac_psy_common.cpp | |
parent | fe377370c1ae4691a65270123345f225e3159ed8 (diff) | |
download | atracdenc-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.cpp | 36 |
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 |