0

我正在使用 SoundTouch 库对一些音频文件进行音高转换。一切正常,除了新音频文件的最后几百毫秒与原始文件不同。这是原始文件:在此处输入图像描述

这是我在音高转换后得到的: 在此处输入图像描述

正如你所看到的,结局是不对的。就像原始文件中没有任何内容一样,当然有。

这是我正在使用的代码:

int generateFile(WavInFile *file, SoundTouch *st, string fileName, int semitones)
{
  const bool speech = true; 

SAMPLETYPE samples[BUFF_SIZE];

WavOutFile *out = new WavOutFile(fileName.c_str(), (int)file->getSampleRate(), (int)file->getNumBits(), (int)file->getNumChannels());

int nChannels = (int)file->getNumChannels();

assert(nChannels > 0);

int num, nSamples;
int buffSizeSamples = BUFF_SIZE / nChannels;

st->setSampleRate((int)file->getSampleRate());
st->setChannels(nChannels);
st->setPitchSemiTones(semitones);

if (!speech)
{
    st->setSetting(SETTING_USE_QUICKSEEK, 0);
    st->setSetting(SETTING_USE_AA_FILTER, 0);
}
else
{
    st->setSetting(SETTING_USE_QUICKSEEK, 0);
    st->setSetting(SETTING_SEQUENCE_MS, 40);
    st->setSetting(SETTING_SEEKWINDOW_MS, 15);
    st->setSetting(SETTING_OVERLAP_MS, 8);
}



while (file->eof() == 0)
{
    num = file->read(samples, BUFF_SIZE);

    nSamples = num / (int)file->getNumChannels();

    st->putSamples(samples, nSamples);

    do 
    {
        nSamples = st->receiveSamples(samples, buffSizeSamples);
        out->write(samples, nSamples * nChannels);
    } while (nSamples != 0);
}


st->flush();

do 
{
    nSamples = st->receiveSamples(samples, buffSizeSamples);
    out->write(samples, nSamples * nChannels);
} while (nSamples != 0);

delete out;

return 0;

}

是的,我稍后在我的代码中删除了 WavInFile *file。所以我的问题是 - 为什么 SoundTouch 会这样做,我该如何解决?

此外,我不能简单地剪切新音频文件的错误部分,因为我正在以这种方式生成数百个文件,因此剪切每一个文件都会......

4

0 回答 0