aolsenjazz / libsamplerate-js

Resample audio in node or browser using a web assembly port of libsamplerate.
Other
31 stars 9 forks source link

Add `outLength` to full API, tells caller how many samples were written #144

Closed tortis closed 2 months ago

tortis commented 2 months ago

Includes both number of frames and number of samples for convenience and to avoid confusion.

Real-world example usage:

const outLength = {frames: 0, samples: 0};
resampler.full(res.samples, sampleBuffer, outLength);
res.samples = sampleBuffer.slice(0, outLength.samples);

Ref #143

aolsenjazz commented 2 months ago

I'm glad that you brought up the idea of frames. It seems truer to implementation of SRC internally to use frames rather than samples. Would you revise to just use frames? Again, thanks for suggesting that.

Edit: Unless you think there's a compelling use case for including samples in the object. I just don't see it atm.

tortis commented 2 months ago

Sounds good, I amended the commit, so it just has frames now.

aolsenjazz commented 2 months ago

Thanks - 1 more step. I had to update node version in CI for tests to pass - would you merge with main and update to 2.1.2? I'll publish on NPM and worry about test coverage when I have some time.

Thanks for the extra time.

tortis commented 2 months ago

I rebased the upstream, and ran npm version 2.1.2. I can't push the tag to the upstream, if you wanna keep version tags, so I'll leave that to you.

Thanks for helping get this change out!