2015-03-02 179 views
0

我遇到了麻烦下面的代码工作重采样时:访问冲突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); 

我在(中input对象)PCM短数据快到了,我希望它也被重新取样值speed正如您所见,它正在与原始采样率相乘(44100是标准)。另外numframes是我发送的数据块中的帧数(立体声)

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

我目前只是试图加快声音,所以我做了输出缓冲区一样大的原始,这将足以保存resample后的一切。

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

编辑:
我自己也尝试用这种方法:

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

但也抛出一个艾策斯冲突错误。

提前致谢!

回答

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

这似乎是产量不够大,像我的预期。虽然不知道它是如何写入指针的。现在是固定的。

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