2015-03-02 183 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); 

這似乎是產量不夠大,像我的預期。雖然不知道它是如何寫入指針的。現在是固定的。

如果有人有任何意見,請隨時指出錯誤