Skip to content

Conversation

@sakertooth
Copy link
Contributor

@sakertooth sakertooth commented Apr 22, 2025

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 calling src_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 and will be used on the next call to src_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.

  • Remove the choice to choose an interpolation mode when exporting. This can conflict with the interpolation mode specified by the instruments and their APIs, so it was removed.

@sakertooth sakertooth marked this pull request as draft April 22, 2025 17:31
@sakertooth sakertooth marked this pull request as ready for review April 23, 2025 00:24
@sakertooth sakertooth changed the title Improve correctness of AudioResampler Fix audio resampling logic Apr 23, 2025
@sakertooth sakertooth marked this pull request as draft April 24, 2025 13:39
@sakertooth sakertooth marked this pull request as ready for review April 27, 2025 10:54
@sakertooth sakertooth marked this pull request as ready for review September 3, 2025 15:14
The quality settings can conflict with an instrument's choice of interpolation. For example, one instrument may only work with a fixed set of interpolation modes that do not necessarily align with the interpolation modes specified by AudioResampler. AudioRessampler works with some modes like SincBest, but some instruments may not have that mode, so theres a conflict. It is simpler and safer
to allow instruments to determine what interpolation
mode they will use.
Lots of double backing, but probably should wait for a refactor for the current code architecture and stuff to see how the playback loops fit into everything.
Copy link
Contributor

@szeli1 szeli1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have reviewed this PR and I didn't find anything wrong with the code.

I tested this PR by importing sample clips and I found the following:
I got this message every time I imported something:

qt.accessibility.atspi: WARNING Qt AtSpiAdaptor: Accessible invalid:  QAccessibleInterface(0x5562060aeb00 invalid) "/org/a11y/atspi/accessible/2147484886

Copy link
Contributor

@szeli1 szeli1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving this PR. (tested with 8000, 11025, 16000, 22050, 32000 and more sample rates)

@sakertooth
Copy link
Contributor Author

sakertooth commented Oct 19, 2025

I have reviewed this PR and I didn't find anything wrong with the code.

I tested this PR by importing sample clips and I found the following: I got this message every time I imported something:

qt.accessibility.atspi: WARNING Qt AtSpiAdaptor: Accessible invalid:  QAccessibleInterface(0x5562060aeb00 invalid) "/org/a11y/atspi/accessible/2147484886

Doesn't seem related, though I don't think I've seen this error before. Might be something specific on your machine, not sure.

Approving this PR. (tested with 8000, 11025, 16000, 22050, 32000 and more sample rates)

Thanks for testing!

Copy link
Member

@messmerd messmerd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me code-wise

@sakertooth
Copy link
Contributor Author

Thanks for the review @messmerd!

@messmerd
Copy link
Member

Ready to merge?

@sakertooth
Copy link
Contributor Author

Ready to merge?

Basically, but @bratpeki is interested in doing some final testing.

@bratpeki
Copy link
Member

Tested PATs, GIGs, SF2, AFP and SlicerT on 192, sounds great. Please (finally) merge! 🎉

@sakertooth sakertooth merged commit 44a68b8 into LMMS:master Oct 22, 2025
11 checks passed
Jan125 pushed a commit to Jan125/lmms that referenced this pull request Oct 22, 2025
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

Successfully merging this pull request may close these issues.

4 participants