Skip to content

Playback: add wsola as a alternative pure-rust tempo stretcher - #794

Open
hasezoey wants to merge 7 commits into
tramhao:masterfrom
hasezoey:rusty-wsola-other
Open

hasezoey wants to merge 7 commits into
tramhao:masterfrom
hasezoey:rusty-wsola-other

Conversation

@hasezoey

@hasezoey hasezoey commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

This PR adds wsola experimentally as a pure rust tempo stretcher alternative to rodio's plain convert and FFI soundtouch.
Additionally, cleans-up the sources a bit.

Unlike #793, in this PR everything works, but has abyssal performance in debug builds, either requiring upstream changes, or using opt-level for this specific dependency.
Additionally, in its current state, it is missing the 1.0 (default) tempo bypass, which would also improve performance.

fixes #167
closes #793

This is a DRAFT for testing and to hopefully fix the abyssal debug build performance (without cargo opt level).

@tramhao

tramhao commented Oct 12, 2026

Copy link
Copy Markdown
Owner

You translate the algorithm yourself? Excellent!

@tramhao
tramhao marked this pull request as ready for review October 12, 2026 06:53
@hasezoey

hasezoey commented Oct 12, 2026 •

Copy link
Copy Markdown
Collaborator Author

You translate the algorithm yourself? Excellent!

I did not. Since about 3 months, there exist 2 crates which had implemented the algorithm, both released about the same time. I just came across them and pushed some PRs to improve them.

PS: i converted it back to a DRAFT as the debug build performance is still not solved.

@hasezoey
hasezoey marked this pull request as draft October 12, 2026 10:18
@hasezoey

hasezoey commented Oct 24, 2026 •

Copy link
Copy Markdown
Collaborator Author

I think wsola(crate) itself is now ready after all the changes. I updated the PR to the latest version.
It is ready for a test listen again, but before merge i want to add a bypass for normal speed (like soundtouch has), so we dont unnecessarily use CPU or modify the samples.

While working on this and the other PR, i noticed how bad the actual rodio naive speed change actually is.
@tramhao do you want to make this the default and remove the rodio naive speed change option, or keep it? (likely done in another PR)
Note that this is not about the soundtouch option, which i would like to keep as it does sound slightly better than wsola.

Note that wsola in its current state has abyssmal performance in debug builds.
Also there is currently no 1.0 tempo bypass implemented.
This new implementation is behind the experimental environment variable "TERMUSIC_RUSTY_WSOLA". Set it to "true" or "1" to enable.

fixes tramhao#167
…unt at once and output that before transitioning

This is necessary, as otherwise we might feed odd-numbered samples to soundtouch.
@hasezoey

Copy link
Copy Markdown
Collaborator Author

Likely final update:
Implemented a bypass, like in soundtouch, which only bypasses until the algo is started.
Due to how wsola works, at least to my understanding, there is a slight audio distortion at algo start (ie once you first change the speed to non-1.0), but it is so slight that i think it is acceptable. (please test)

Additional changes:

  • always optimize wsola in debug mode, as otherwise it consumes way too much CPU while running
  • update soundtouch impl to not accidentally change to algo in the middle of a frame
  • cleaned-up git commits
  • Explicitly log what Timestretcher is active, not just when "soundtouch" is active

For caution, this will stay behind the TERMUSIC_RUSTY_WSOLA environment variable flag, until making it the default in a follow-up PR, as said in #794 (comment).
(Set TERMUSIC_RUSTY_WSOLA=1 to enable WSola, but only if soundtouch is either not compiled in or set to active in the config)

@hasezoey
hasezoey marked this pull request as ready for review October 25, 2026 16:17
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.

[Feature Request] Speed control without changing pitch

2 participants