Skip to content
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

Don't use mutexes on the DSP thread #55

Closed
exa04 opened this issue May 31, 2024 · 4 comments · Fixed by #58
Closed

Don't use mutexes on the DSP thread #55

exa04 opened this issue May 31, 2024 · 4 comments · Fixed by #58
Labels
enhancement New feature or request

Comments

@exa04
Copy link
Owner

exa04 commented May 31, 2024

Mutexes are discouraged on the Plugin thread - they can lead to lock-ups, glitches, and general performance issues.

Currently, many of Cyma's visualizers synchronize with audio data through some Arc<Mutex<impl VisualizerBuffer>>. The Mutex needs to be locked every time a new chunk of audio gets enqueued or everything gets read out. This can introduce glitches when many plug-ins are used.

A better solution would be a data structure that the plugin processor can continuously write to - whenever it feels like it - without any sort of locking or waiting. I think locking or waiting would probably be fine on the editor thread, though it should definitely perform well at good frame rates. The editor also, in the case of circular buffers, always needs to read out the buffer starting at the correct index.

Possible solutions include:

  • Intermediate queues for new samples
  • Atomics
  • Multiple-buffering (like we did in the Spectrum visualizer)

This is going to be a pretty big change. It should be well though-out. Here's a rough outline of what needs to be done:

  • Extensively test the possible alternatives before banking on them
  • Introduce as few breaking changes to Cyma's API as possible
  • Settle on some new data structures and re-write the previous ones
  • Update docs and book to reflect the changes
  • Update the examples
@exa04 exa04 added enhancement New feature or request help wanted Extra attention is needed labels May 31, 2024
@exa04 exa04 changed the title Use a ring buffer more suitable for real-time audio scenarios Don't use mutexes on the DSP thread Jun 7, 2024
@exa04

This comment was marked as outdated.

@exa04
Copy link
Owner Author

exa04 commented Nov 4, 2024

I'll be working on this system over on the test-channel-buffers branch.

@exa04 exa04 pinned this issue Nov 4, 2024
@magnetophon
Copy link
Contributor

Thanks a ton for taking this on!

Extensively test the possible alternatives before banking on them

I can help testing, if you want.
Just tell me what to do.

Introduce as few breaking changes to Cyma's API as possible

Personally, I'd be more than happy to adapt my plugin to any API changes, if that makes it easier for you.
Having a lock free architecture would be more than worth it!

@exa04 exa04 removed the help wanted Extra attention is needed label Nov 18, 2024
@exa04
Copy link
Owner Author

exa04 commented Nov 18, 2024

I can help testing, if you want.
Just tell me what to do.

I appreciate the offer! I'll open a PR when I've made enough progress so that you can test the new system :)

Personally, I'd be more than happy to adapt my plugin to any API changes, if that makes it easier for you.

For sure! I'm definitely not against introducing major breaking changes to Cyma, per se. After all, it is still in 0.1.0. But I do however want to only do it when breaking changes would be sensible (e.g. for performance reasons or ease of use.)

@exa04 exa04 linked a pull request Dec 17, 2024 that will close this issue
8 tasks
@exa04 exa04 closed this as completed in #58 Jan 16, 2025
@exa04 exa04 unpinned this issue Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants