Question: Could you please share minimal REAPER_Resample_Interface example? I'm trying to wrap it to be used by another C library (like this: pastebin.com/jvP6tamk) and getting strange memory errors. Is it possible that REAPER_Resample_Interface does it's own memory allocations to supplied buffers?
Asked by Martin (78.0.239.x) on June 6 2014, 4:02pm
Reply on June 6 2014, 5:42pm:Something like this (pardon the (*). syntax, too lazy to do all of the required HTML entities manually):
const int nch = 2;
const int out_block_size = 1024;
REAPER_Resample_Interface *resample = Resampler_Create();
ReaSample *out_buf = (ReaSample *)calloc(sizeof(ReaSample), out_block_size * nch);
(*resample).SetRates(44100.0, 96000.0);
while (you feel like it)
{
ReaSample *in_buf;
int needed_input = (*resample).ResamplePrepare(out_block_size,nch, &in_buf);
if (needed_input > 0)
{
// fill in in_buf with nch * needed_input * sizeof(ReaSample) bytes.
// if less input is available (EOF), decrease needed_input (this will imply a flush, so only supply less if it is EOF)
}
int out_buf_used = (*resample).ReasampleOut(out_buf,needed_input, out_block_size, nch);
// add out_buf_used * nch * sizeof(ReaSample) to output
}
If you want to have your resampler work by having a known input quantity and getting whatever output is available, you can use Extended(RESAMPLE_EXT_SETFEEDMODE,(void*)(INT_PTR)1,0,0), which will allow you specify the input samples available to ResamplePrepare (which will return that same value unless there is an error).