Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check if my resampler usage is correct #85

Closed
xd009642 opened this issue Sep 4, 2024 · 4 comments
Closed

Check if my resampler usage is correct #85

xd009642 opened this issue Sep 4, 2024 · 4 comments

Comments

@xd009642
Copy link

xd009642 commented Sep 4, 2024

So normally I'd use some closed source code making use of ffmpeg bindings to do audio resampling. But this is an open source project outside of my work so I thought I'd try rubato out as it seemed the most fleshed out solution. PR for reference xd009642/streamer-template#19

So initially I'm doing some fairly simple resamplings in the tests just as a sanity check before doing anything more complicated.

Also I've had to manually implement some truncation to cut off a trailing silence which i guess is based on the buffer size? It would be nice if this was documented in some way or there was a code sample.

Hopefully my code is useful to see how someone with no knowledge of this library approaches using it and if there's any stupid mistakes I've made they could potentially be fed back into examples or docs to add more clarity.

EDIT: Removed something that was an issue in my test I fixed.

@xd009642
Copy link
Author

xd009642 commented Sep 4, 2024

Managed to get it working as expected, feel free to check and see if I'm doing anything stupid but as it works hopefully I'm not 🙏

@xd009642 xd009642 closed this as completed Sep 4, 2024
@HEnquist
Copy link
Owner

HEnquist commented Sep 5, 2024

I took a quick look and I'd say it looks fine. But the resampler size looks a little odd, like a power of two with a typo: const RESAMPLER_SIZE: usize = 4086;. Was that supposed to be 4096? It doesn't matter for the performance of the chosen resampler but maybe a wrong value can cause trouble elsewhere.

@xd009642
Copy link
Author

xd009642 commented Sep 5, 2024

Ah yeah that was a typo. I was doing various powers of two and probably messed up in one of the changes.

It would be nice if I didn't have to manually figure out where to truncate to but that's do-able

@HEnquist
Copy link
Owner

HEnquist commented Sep 6, 2024

You can use this to know how much to trim at the start:
https://docs.rs/rubato/0.15.0/rubato/trait.Resampler.html#tymethod.output_delay
You'll still have to calculate how much to trim at the end. I don't see any reasonable way the library could help with this, considering that the ratio etc can be adjusted at any time while processing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants
@xd009642 @HEnquist and others