Update inferPreprocess.hpp

This commit is contained in:
Ναρουσέ·μ·γιουμεμί·Χινακάννα 2023-04-07 23:44:20 +08:00 committed by GitHub
parent 29f7aa3fbd
commit b980ac503f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 35 additions and 0 deletions

View File

@ -26,3 +26,38 @@ private:
double* rf0 = nullptr;
int64_t f0Len = 0;
};
void F0PreProcess::InterPf0(int64_t len)
{
const auto xi = arange(0.0, (double)f0Len * (double)len, (double)f0Len, (double)len);
const auto tmp = new double[xi.size() + 1];
interp1(arange(0, (double)f0Len).data(), rf0, static_cast<int>(f0Len), xi.data(), (int)xi.size(), tmp);
for (size_t i = 0; i < xi.size(); i++)
if (isnan(tmp[i]))
tmp[i] = 0.0;
delete[] rf0;
rf0 = nullptr;
rf0 = tmp;
f0Len = (int64_t)xi.size();
}
long long* F0PreProcess::f0Log()
{
const auto tmp = new long long[f0Len];
const auto f0_mel = new double[f0Len];
for (long long i = 0; i < f0Len; i++)
{
f0_mel[i] = 1127 * log(1.0 + rf0[i] / 700.0);
if (f0_mel[i] > 0.0)
f0_mel[i] = (f0_mel[i] - f0_mel_min) * (f0_bin - 2.0) / (f0_mel_max - f0_mel_min) + 1.0;
if (f0_mel[i] < 1.0)
f0_mel[i] = 1;
if (f0_mel[i] > f0_bin - 1)
f0_mel[i] = f0_bin - 1;
tmp[i] = (long long)round(f0_mel[i]);
}
delete[] f0_mel;
delete[] rf0;
rf0 = nullptr;
return tmp;
}