使用soxr重新采样时发生访问冲突
Access Violation when resampling using soxr
我很难让以下代码工作:
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);
产量似乎没有我预期的那么大。不过,我真的不知道它是如何写入指针的。目前已修复。
如果任何人有任何意见,请随时指出错误
相关文章:
- 写入位置0x0000000C时发生访问冲突
- 引发异常:读取访问冲突**dynamicArray**为0x1118235.发生
- 链表中写入访问冲突的未知原因
- C++中的openCV Mat访问冲突
- C++尝试深度复制唯一指针时出现内存访问冲突
- C++ 中动态二维数组的访问冲突
- 从嵌套循环中的 std::list 中删除将返回访问冲突
- 写入访问冲突异常
- 在类 12.exe 中0x7B37FF80 (ucrtbased.dll) 引发异常: 0xC0000005:访问冲突读
- 0xC0000005:访问冲突写入位置0xCDCDCDCD动态分配错误
- 读取访问冲突.这0xCDCDCDCD
- 0xC0000005:访问冲突读取位置 0x00000000. 重载 == 运算符的问题
- 插入数组时违反写访问冲突
- 使用 ReadProcessMemory 获取字符串值的访问冲突
- 尝试通过共享指针使用变量时读取访问冲突
- 堆栈上的 C++ 访问冲突写入异常
- 引发异常:写访问冲突. temp 为 nullptr
- 将静态字符数组中的字符分配给动态分配的字符数组 - 访问冲突
- 在C++中删除双向链表的头节点后出现访问冲突异常
- 使用soxr重新采样时发生访问冲突