【问题标题】:Access Violation when resampling using soxr使用 soxr 重新采样时访问冲突
【发布时间】: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);

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

提前致谢!

【问题讨论】:

    标签: c++ audio libsox


    【解决方案1】:

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

    // 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-01-02
      • 2010-11-19
      • 2016-10-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多