0

我无法让以下代码正常工作:

soxr_error_t err;
soxr_datatype_t itype = SOXR_INT16_I;
soxr_datatype_t otype = SOXR_INT16_I;
soxr_io_spec_t iospec = soxr_io_spec(itype, otype);
size_t idone = 0;
size_t odone = 0;
size_t const olen = (size_t)((speed * 44100) * (numframes * 2) / (44100 + (44100 * speed)) + .5);

// Do the resampling
short* output = new short[numframes * 2];
soxr_t sox = soxr_create(44100, 44100 * speed, 2, &err, &iospec, NULL, NULL);
if (!err)
    soxr_process(sox, input, numframes * 2, &idone, output, olen * 2, &odone);
soxr_delete(sox);

我有 PCM 短数据进入(input对象),我希望它也被重新采样为speed与原始采样率相乘的值,如您所见(44100 是标准)。也是numframes我发送的数据块的帧数(立体声)

问题是我的应用程序在执行该soxr_process()方法时崩溃。该方法似乎没有错误,soxr_create()所以我真的不知道它可能是什么。

我目前只是试图加快声音的速度,因此我将输出缓冲区设置为与原始缓冲区一样大,这足以在重新采样后保存所有内容。

我怎么解决这个问题?我是否给该soxr_process()方法提供了错误的值?

编辑:
我也尝试过这种方法:

soxr_oneshot(4410, 44100 * speed, 2, input, numframes * 2, &idone, output, outputFrames * 2, &odone, &iospec, NULL, NULL);

但这也会引发访问冲突错误。

提前致谢!

4

1 回答 1

0

我已经能够使用以下代码修复它:

// Check the number of frames needed to fill extra or send to the next block
int outputFrames = numframes * speed;
int extraReadNeeded = numframes - outputFrames;

soxr_error_t err;

soxr_datatype_t itype = SOXR_INT16_I;
soxr_datatype_t otype = SOXR_INT16_I;
soxr_io_spec_t iospec = soxr_io_spec(itype, otype);

size_t idone = 0;
size_t odone = 0;

size_t const olen = (size_t)((speed * 44100) * (numframes * 2) / (44100 + (44100 * speed)) + .5);

// Do the resampling
short* output = new short[outputFrames * 4];
soxr_t sox = soxr_create(44100, 44100 * speed, 2, &err, &iospec, NULL, NULL);
if (!err)
    err = soxr_process(sox, input, numframes * 2, &idone, output, outputFrames, &odone);
soxr_delete(sox);

看起来输出不像我预期的那样大。虽然不知道它是如何写入指针的。现在已经修好了。

如果有人有任何意见,请随时指出错误

于 2015-03-02T14:04:03.237 回答