-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Multithreaded rubberband #13143
base: main
Are you sure you want to change the base?
Multithreaded rubberband #13143
Conversation
9bd52ef
to
470a227
Compare
I assume you would like to see the deck computing in parallel, right? I'm afraid that won't only require a refactor of the RubberBand, but rather a refactor of the audio engine which processes the channel sequentially. Also, note that simple deck will not use the threaded version and will perform RubberBand in the calling thread Or did you mean something else? |
Note that this is only a PoC, and production ready solution could include to make a global pool of thread, instead of owned thread per channel (meaning a max of 4 thread, rather than the current 4(deck)x4(stem)) |
Everything in parallel is too much, at least for my laptop. A thread stealing pool with e.g. 4 workers seems more appropriated.
This would be of cause beyond the scope of the stems project, but from the pure technical viewpoint, I think this is the way to go. There can be many running decks, if we think about the use of samplers. |
With the amount of in-flight PR for the STEM feature, I will pause that one for now. I guess that proves that we have some quick wins to action in order to make STEM more usable. |
I think this feature should be ready for review and testing. I believe the thread usage should now be optimal. I have tested parameters and the current one seems to be the best, slightly better than my initial commit. |
470a227
to
c3f57ee
Compare
c3f57ee
to
94d3f99
Compare
This comment was marked as resolved.
This comment was marked as resolved.
The last commit contains a lot of useful refactoring. Can you please create a separate PR with these changes. I expect that we can merge them quickly. |
That's very odd! Just to double check, did you use
Yes, no problem, I will remove the STEM changes, only dependency is the stem channel count constant, so I will hardcore it for now and put a |
This solution unfortunately involves a priority inversion. In the best case you gain a better CPU utilisation of otherwise idling cores. This comes with the cost of lost deterministic behavior which is more important IMHO. A better working solution would be a buffer swap algorithm, that just swaps the prepared buffers from the engine thread and does the preparation in the low priority workers. The workers will have a whole cycle to finish the task which may be finished even in critical time situations, if not, only one stem is effected. This may doubles the latency, but likely allows to compensate that by halving the minimum possible latency. |
Did you consider the poor man's solution of mixing only two buffers of temps before doing sound stretching? |
I have removed all impact on the stereo channel, so they will proceed in the same way than previously, and scale directly in the engine thread. Happy to split in multiple commit, but not sure I can see a clear cut in the PR, could you highlights the bits that should live as a dedicated commit? |
My idea was to have the introduction of the RubberbandWrapper in a first commit and the introduction of the threading in an other. It would be also nice to have enginebufferscalerubberbandthread.h split in three files one per class. m_pRubberBand needs to become m_rubberBand because it s no longer just a pointer. |
b179ec7
to
8cad156
Compare
@daschuer I have addressed your request @JoergAtGithub I found out why the mono split wasn't working. I know you mentioned that had some difficulties having 4 decks on R3 with your setup. If you can, could you try this version and edit this const and set to I think last thing we are missing is the use of |
I tested this with |
I recommend to keep this out of this PR, because this function returns just the number of logical processors, and we have to consider also other threads and processes. This is a topic on it's own. |
@daschuer Do you aggree with that? |
Glad to hear! @daschuer what do you think of making this accessible in the options? I know we said we don't want to change the rubberband for stereo by default, but it looks like this could help on some setups |
Yes sure. I am however unsure what this means to stereo compatibility. I have just skimmed through the Rubberband Documentation but I have not found anything yet. On the other and I remember a discussion. |
It is the ability that the stereo signal can be later still mixed down to a mono singnal without that frequencies are killed out. Just found this in the 3.2 CHANGELOG: |
See #11361 |
I fear that the problem with the mono downmix functionality could catch us up, when we introduce stem mixing in the engine. After all, we're doing nothing other than mixing 4 independent rubberband channels together. But the OptionChannelsTogether option only seems to work for a single stereo channel pair. |
I don't this would be a problem for stem: In principle, stem is only like playing different track on different decks, unlike channels of a stereo set.
By the sound of it, there is too many risk going with this as default. Should I still put the option in the setting, with perhaps a warning that references #11361? |
An option would be great, as only some users will be affected by the Mono downmixing issue. But I wonder how to label it, to make the behavior clear to the user. |
Perhaps I could put a |
97c914a
to
3475899
Compare
Good enough? I guess the message will need to be slightly adjusted but just wondering about the UX. Kooha-2024-05-22-16-07-16.mp4I tried to make the setting adjustable live but it would require more synchronization which may not be a very good trade-off. |
I tested this locally on Windows 11 and the new UI setting works great! |
There are CI fails now! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This comment was pending for a long time. Idk when I'll find time/energy to properly review this.
3475899
to
5a1caa1
Compare
Slightly outdated info
This is a naive attempt to parallelise rubberband processing as per suggested here.
(Test using 44100Hz/11.6ms output settings)
So far the result are very promising! previously, audio drop would occur as soon as start playing a second stem deck, when using
powersave
governor, and third stem deck when usingperformance
, with both R2 and R3.Now I can play 4 stem decks in R3 in
powersave
, with near no audio drop, but it increase when I increase pitches on decks. No issue inperformance
, although the indicator is very highIn R2 there is no audio drop at all, and CPU indicator remains in the green, even in
powersave
!Adds a worker pool for RubberBand. This pool should be used a single threaded environment (engine thread) and will have to be reviewed if the engine is moved to a multi thread design. This decision was made since such a refactor will likely invalidate the need for such a task specific pool.