我正在使用SoXR库的可变速率功能来实时动态更改音频流的采样率。不幸的是,我已经注意到,在使用正弦波测试时,将速率从1.0更改为更大的值(例如:1.01)时,会出现不希望的咔嗒声。从大于1.0的值更改为1.0时,我没有注意到任何不需要的伪影。我看着它产生的波形,看起来好像有几个采样率变化正确的样本被错误地调换了。
这是使用签名的16位交织样本存储的440Hz立体声正弦波示例的图片:
除第五个代码示异常(exception),我还找不到任何有关可变利率功能的文档。这是我的初始化代码:
bool DynamicRateAudioFrameQueue::intialize(uint32_t sampleRate, uint32_t numChannels)
{
mSampleRate = sampleRate;
mNumChannels = numChannels;
mRate = 1.0;
mGlideTimeInMs = 0;
// Intialize buffer
size_t intialBufferSize = 100 * sampleRate * numChannels / 1000; // 100 ms
pFifoSampleBuffer = new FiFoBuffer<int16_t>(intialBufferSize);
soxr_error_t error;
// Use signed int16 with interleaved channels
soxr_io_spec_t ioSpec = soxr_io_spec(SOXR_INT16_I, SOXR_INT16_I);
// "When creating a var-rate resampler, q_spec must be set as follows:" - example code
// Using SOXR_VR makes sense, but I'm not sure if the quality can be altered when using var-rate
soxr_quality_spec_t qualitySpec = soxr_quality_spec(SOXR_HQ, SOXR_VR);
// Using the var-rate io-spec is undocumented beyond a single code example which states
// "The ratio of the given input rate and ouput rates must equate to the
// maximum I/O ratio that will be used: "
// My tests show this is not true
double inRate = 1.0;
double outRate = 1.0;
mSoxrHandle = soxr_create(inRate, outRate, mNumChannels, &error, &ioSpec, &qualitySpec, NULL);
if (error == 0) // soxr_error_t == 0; no error
{
mIntialized = true;
return true;
}
else
{
return false;
}
}
任何想法可能导致这种情况发生吗?或对替代库提出建议,该库能够实时进行可变速率音频重采样?
最佳答案
与SoXR库的开发人员交谈后,我能够通过调整soxr_create方法调用中的最大比率参数来解决此问题。开发人员的响应可以在here中找到。
关于variables - 使用SoXR库进行可变速率重新采样时不需要的单击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24639212/