diff --git a/CppDataProcess/F0Preprocess.cpp b/CppDataProcess/F0Preprocess.cpp deleted file mode 100644 index d6bd6f3..0000000 --- a/CppDataProcess/F0Preprocess.cpp +++ /dev/null @@ -1,153 +0,0 @@ -#include "F0Preprocess.hpp" - - -void F0PreProcess::compute_f0(const double* audio, int64_t len) -{ - DioOption Doption; - InitializeDioOption(&Doption); - Doption.f0_ceil = 800; - Doption.frame_period = 1000.0 * hop / fs; - f0Len = GetSamplesForDIO(fs, (int)len, Doption.frame_period); - const auto tp = new double[f0Len]; - const auto tmpf0 = new double[f0Len]; - rf0 = new double[f0Len]; - Dio(audio, (int)len, fs, &Doption, tp, tmpf0); - StoneMask(audio, (int)len, fs, tp, tmpf0, (int)f0Len, rf0); - delete[] tmpf0; - delete[] tp; -} - -std::vector arange(double start,double end,double step = 1.0,double div = 1.0) -{ - std::vector output; - while(start(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; -} - -std::vector F0PreProcess::GetF0AndOtherInput(const double* audio, int64_t audioLen, int64_t hubLen, int64_t tran) -{ - compute_f0(audio, audioLen); - for (int64_t i = 0; i < f0Len; ++i) - { - rf0[i] = rf0[i] * pow(2.0, static_cast(tran) / 12.0); - if (rf0[i] < 0.001) - rf0[i] = NAN; - } - InterPf0(hubLen); - const auto O0f = f0Log(); - std::vector Of0(O0f, O0f + f0Len); - delete[] O0f; - return Of0; -} - -std::vector getAligments(size_t specLen, size_t hubertLen) -{ - std::vector mel2ph(specLen + 1, 0); - - size_t startFrame = 0; - const double ph_durs = static_cast(specLen) / static_cast(hubertLen); - for (size_t iph = 0; iph < hubertLen; ++iph) - { - const auto endFrame = static_cast(round(static_cast(iph) * ph_durs + ph_durs)); - for (auto j = startFrame; j < endFrame + 1; ++j) - mel2ph[j] = static_cast(iph) + 1; - startFrame = endFrame + 1; - } - - return mel2ph; -} - -std::vector F0PreProcess::GetF0AndOtherInputF0(const double* audio, int64_t audioLen, int64_t tran) -{ - compute_f0(audio, audioLen); - for (int64_t i = 0; i < f0Len; ++i) - { - rf0[i] = log2(rf0[i] * pow(2.0, static_cast(tran) / 12.0)); - if (rf0[i] < 0.001) - rf0[i] = NAN; - } - const int64_t specLen = audioLen / hop; - InterPf0(specLen); - - std::vector Of0(specLen, 0.0); - - double last_value = 0.0; - for (int64_t i = 0; i < specLen; ++i) - { - if (rf0[i] <= 0.0) - { - int64_t j = i + 1; - for (; j < specLen; ++j) - { - if (rf0[j] > 0.0) - break; - } - if (j < specLen - 1) - { - if (last_value > 0.0) - { - const auto step = (rf0[j] - rf0[i - 1]) / double(j - i); - for (int64_t k = i; k < j; ++k) - Of0[k] = float(rf0[i - 1] + step * double(k - i + 1)); - } - else - for (int64_t k = i; k < j; ++k) - Of0[k] = float(rf0[j]); - i = j; - } - else - { - for (int64_t k = i; k < specLen; ++k) - Of0[k] = float(last_value); - i = specLen; - } - } - else - { - Of0[i] = float(rf0[i - 1]); - last_value = rf0[i]; - } - } - delete[] rf0; - rf0 = nullptr; - return Of0; -}