-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix audio resampling functionality #7858
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
base: master
Are you sure you want to change the base?
Conversation
AudioResampler
6bb4aed
to
0ede71a
Compare
b6d53f9
to
a9fdaf0
Compare
Please don't test right now, I think I broke some stuff and I am making some changes to the API. Maybe I should just stash my changes instead of pushing immediately if I want to back out on some of them, since other developers wont know. Edit: This is why I drafted the PR. I am not done with it, but I am a bit in the wrong here because I kept backing out on this PR, if it wasn't ready then I should've waited until I got it in the state I wanted. |
I actually reverted back to the working version right after you sent this. |
I am facing a dilemma where I am trying to make the resampler API as hard to use wrong as I can, because the problem with how libsamplerate was being used before was that callers would generate input frames and not check if all of what they generated was consumed, so those input frames will be dropped or "leak" in the next callback. I am trying to write an API that is hard to use wrong but also clean and simple, but maybe I cant have both honestly. |
Oh, yikes. Let me know if I can help any way. If this needs to expand into a set of PRs, that's fine, too. |
It's fine, its mostly me being a perfectionist. I have reverted the PR back to where it was before, if I have something that I know is what I want and is working, only then will I push. |
Okay, please let me know when testing can continue, either on Discord or by requesting a review. |
…iven and no more output was generated
…nth_write_float Sf2Player should always fill the input buffer
Advance the data stream within the input callback, as it is being called multiple times in a loop per call to process
Accidentally removed this
Okay, I think this is actually ready for review now (and testing assuming CI builds fine). I stopped overthinking and came up with a decent design. It should work well. |
One thing I want to do in the future after this is merged is making the interpolation feature in export actually work. This PR should make that process a lot simpler. I didn't want to do it here because it might be a bit disorienting since the changes will be all over the place. |
The reason why -Wunused-variable being treated as an error isn't a great idea. 1. Using [[nodiscard]] 2. Return value is checked only within an assert But one could argue filling the remaining partially filled buffer with silence is more correct.
This PR improves the usage of libsamplerate when resampling.
Changes:
Redirect all libsamplerate usage to
AudioResampler
. This ensures we are always using libsamplerate with the same resampling logic, preventing bugs.Call
src_process
as many times as necessary to resample all of the source audio we need to fill up the destination buffer. Before, LMMS was only callingsrc_process
once, and assumed that libsamplerate always read all of the input data it gave it, which isn't necessarily true and can cause input frames to be dropped. Any input frames not read in the current iteration are stored within a small array inAudioResampler
and will be used on the next call tosrc_process
.Remove the use of buffer margins. This was needed to accommodate for libsamplerate's transport delay, but this involved expensive copies and allocations, and the margin added may not be adequate depending on how long the transport delay needs to be, which wasn't accounted for. To fix this, we allow the transport delay to occur on the onset of when
AudioResampler
is first used, which then the delay will be removed on subsequent resampling.TODO: