Skip to content

Don't use mutexes on the DSP thread #55

@exa04

Description

@exa04

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions