aolsenjazz / libsamplerate-js

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

How Much Data was Written to `dataOut`? #143

Closed tortis closed 1 month ago

tortis commented 1 month ago

Summary

I'm using the full API with a reused buffer which is much larger than the expected number of samples.

After I run:

resampler.full(inputSamples, resampleBuffer);

How do I know how much data is in the resampleBuffer. I looked at the source briefly and it doesn't appear to slice the Float32Array or return the number of samples in any other way.

Is there a way to deal with this, or does the library need to be updated to support this use case?

aolsenjazz commented 1 month ago

Hey, thanks for submitting this issue. After reviewing the implementation, I think you're correct in identifying that I didn't provide what you would need to properly read dataOut. I imagine the best way to do this would be to add a third argument, something like outLength: { length: number } = { length: 0 } that we could reference following a call to full to determine how much to slice. I wouldn't want to break the existing API by change the return val.

I don't have time in the nearish future to implement this, but if you're able and have the time, I think it'd be great to add this.

tortis commented 1 month ago

I like it, I just opened PR with this change. I did a build/pack and installed it into my project and was able to use it successfully.

I opted to include sample and frame count just for convenience and clarity, but we can change it back to just length if you'd prefer.

aolsenjazz commented 1 month ago

Fixed in #144. 2.1.2 is live on NPM.

Thanks for your contributions!