0

I'm having trouble getting the following code to work:

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

I have PCM short data coming in (the input object) and I want it too be resampled to a value speed that is being multiplied with the original samplerate as you can see (44100 is the standard). Also numframes is the number of frames from the block of data I send (which is in stereo)

The problem is that my application crashes when doing the soxr_process() method. There seems to be no error from the soxr_create() method so I don't really know what it could be.

I'm currently only trying to speed up the sound so I made the output buffer as large as the original which would be good enough to hold everything after the resample.

How can I solve this problem? Did I give the wrong values to the soxr_process() method?

EDIT:
I have also tried with this method:

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

but that also throws a Acces Violation error.

Thanks in advance!

Dries
  • 995
  • 2
  • 16
  • 45

1 Answers1

0

I have been able to fix it using this code:

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

It seems like the output wasn't large enough like I expected. Don't really know how it is written to the pointer though. It's fixed for now.

If anyone has any remarks feel free to point out the mistakes

Dries
  • 995
  • 2
  • 16
  • 45