Update F0Preprocess.hpp

This commit is contained in:
Ναρουσέ·μ·γιουμεμί·Χινακάννα 2023-04-08 00:01:26 +08:00 committed by GitHub
parent c29ba569c6
commit 7651f33926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 0 additions and 66 deletions

View File

@ -5,12 +5,6 @@
#include <vector>
//Cpp F0 Preprocess
struct SliceResult
{
std::vector<unsigned long long> SliceOffset;
std::vector<bool> SliceTag;
cutResult(std::vector<unsigned long long>&& O, std::vector<bool>&& T) :SliceOffset(O), SliceTag(T) {}
};
class F0PreProcess
{
@ -101,66 +95,6 @@ long long* F0PreProcess::f0Log()
return tmp;
}
inline SliceResult SliceWav(Wav& input, double threshold, unsigned long minLen, unsigned short frame_len, unsigned short frame_shift)
{
const auto header = input.getHeader();
if (header.Subchunk2Size < minLen * header.bytesPerSec)
return { {0,header.Subchunk2Size},{true} };
auto ptr = input.getData();
std::vector<unsigned long long> output;
std::vector<bool> tag;
auto n = (header.Subchunk2Size / frame_shift) - 2 * (frame_len / frame_shift);
unsigned long nn = 0;
bool cutTag = true;
output.emplace_back(0);
while (n--)
{
//if (nn > minLen * header.bytesPerSec)
if (cutTag)
{
const auto vol = abs(getAvg((short*)ptr, (short*)ptr + frame_len));
if (vol < threshold)
{
cutTag = false;
if (nn > minLen * header.bytesPerSec)
{
nn = 0;
output.emplace_back((ptr - input.getData()) + (frame_len / 2));
}
}
else
{
cutTag = true;
}
}
else
{
const auto vol = abs(getAvg((short*)ptr, (short*)ptr + frame_len));
if (vol < threshold)
{
cutTag = false;
}
else
{
cutTag = true;
if (nn > minLen * header.bytesPerSec)
{
nn = 0;
output.emplace_back((ptr - input.getData()) + (frame_len / 2));
}
}
}
nn += frame_shift;
ptr += frame_shift;
}
output.push_back(header.Subchunk2Size);
for (size_t i = 1; i < output.size(); i++)
{
tag.push_back(abs(getAvg((short*)(input.getData() + output[i - 1]), (short*)(input.getData() + output[i]))) > threshold);
}
return { std::move(output),std::move(tag) };
}
std::vector<long long> F0PreProcess::GetF0AndOtherInput(const double* audio, int64_t audioLen, int64_t hubLen, int64_t tran)
{
compute_f0(audio, audioLen);