rust-samplerate
rust-samplerate copied to clipboard
Add process_into* variants to allow utilizing an existing buffer
For some applications, it can be useful to provide an existing buffer as it may already exist (and potentially saves up on allocating memory during a tight loop). The regular process
function always creates a Vec
which would internally always allocate memory, and usually deallocate shortly after it's used.
- This PR adds 2 functions:
-
process_into
, which does the same asprocess
but writes the result in a user supplied buffer and returns a tuple of the amount of data consumed and produced -
process_into_last
, which does the same for theprocess_last
-
- Adds an example to outline its use
- Adds a test similar to
samplerate_conversion
but utilizing the into functions instead
I have to note that I explicitly didn't implement the same thing for convert
(as the fork of xhalo32 adds) because convert
must not be called in a loop, and thus an in-place allocation of the output buffer is not performance critical (Either the user allocates in one go, potentially messing up the calculation. Or the function allocates in one go).
In fact, I believe allowing such a use might even give the wrong impression.