-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
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? |
This is difficult to do during review, but I can label the respective comments as nits and you can postpone them until we've decided on a more concrete course. Does that sound like a reasonable compromise? |
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.
only nits so far. its too late in the day to wrap my head around this
8ba9bae
to
406fc3a
Compare
Some last minute untested change... I believe it should be fixed 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.
fyi LGTM if you address the nits
3937274
to
cf2c5d0
Compare
(keylockMultithreadedComboBox->isChecked() && | ||
keylockMultithreadedComboBox->isEnabled())) { | ||
QMessageBox::information(this, | ||
tr("Information"), | ||
tr("Mixxx must be restarted before the multi-threaded " | ||
"RubberBand settings change will take effect.")); | ||
} |
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.
As a follow up PR, it would be nice if this wasn't required. It's fine if it means that the audio engine must block when applying the new settings, but forcing to restart is much more annoying (especially considering mixxx's startup times).
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.
Yes, agreed. This was my attempt at first, but it turns out to require far more changes that I wanted to do in this PR. Happy to try and give it a go in a future one.
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.
Are you sure it needs that more work? We support changing the stretcher without restarting too, this doesn't seem that much more complicated.
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 is what I thought too, the problem is the way we manage the dynamic stretcher (with a CO) somewhat make things more complicated, and I was left with the only option to add another CO and quite a few synchronisation bits. Potentially, some of the changes I did in the end will make it not as hard as my first attempt, but I'd like to still do that later as this feature is MVP for STEM, while dynamic setting update is nice to have
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.
LGTM. merge @daschuer?
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.
Im finally done with the review.
Thank you for this good solution.
b8a874e
to
4bd8151
Compare
4bd8151
to
b49544b
Compare
Did some brief test and it works good. |
Yes, as discussed here, from my first attempt, adding dynamic reload was at least doubling the size of this PR if not more. Now, with the QThreadPool refactor, it might not be as bad, but I still would like this to be merged first as @JoergAtGithub and @Swiftb0y have already reviewed the existing code. I still have some time free so I'm happy to look into this right away if we me quick enough on this one. |
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.
LGTM, thank you.
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.