使用SoXR Library进行可变速率重采样时不需要的点击

时间:2014-07-08 18:31:19

标签: variables audio rate resampling

我正在使用SoXR库的可变速率功能来实时动态更改音频流的采样率。不幸的是,我注意到当使用正弦波进行测试时,将速率从1.0更改为更大的值(例如:1.01)时会出现不需要的咔嗒声。从大于1.0的值更改为1.0时,我没有注意到任何不需要的工件。我看着它正在产生的波形,看起来就好像速率变化时的一些样本被错误地转换了。

以下是使用带符号16位交错采样存储的立体声440Hz正弦波示例图片:

http://i.imgur.com/KTpPJSl.png

除了第五个代码示例之外,我也找不到任何涵盖可变速率功能的文档。这是我的初始化代码:

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;
    }

}

知道可能导致这种情况发生的原因吗?或者建议一个能够实时进行可变速率音频重采样的替代库?

1 个答案:

答案 0 :(得分:1)

在与SoXR库的开发人员交谈后,我能够通过调整soxr_create方法调用中的最大比率参数来解决此问题。可以找到开发人员的回复here