使用soxr重新采样时发生访问冲突

Access Violation when resampling using soxr

本文关键字:访问冲突 采样 soxr 新采样 使用      更新时间:2023-10-16

我很难让以下代码工作:

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

但这也会引发Acces Violation错误。

提前感谢!

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

// 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);

产量似乎没有我预期的那么大。不过,我真的不知道它是如何写入指针的。目前已修复。

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