【发布时间】:2015-03-02 13:19:42
【问题描述】:
我无法让以下代码正常工作:
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);
但这也会引发访问冲突错误。
提前致谢!
【问题讨论】: