Skip to content

Avoiding stalls (allocations) in the audio thread #28

Open
@Boscop

Description

@Boscop

The Plugin::process() method is called in the audio thread of the host which should never do anything that stalls, like allocation, page faults etc. to avoid buffer dropouts which can destroy speakers at loud volume and are bad in general (you can't expect people to use your plugin if it even has the potential to stall in certain cases).

So we should eliminate the dynamic allocation of midi note memory for processing midi events.
(Maybe there are more potentials of stalls in methods that the host calls in the audio thread.)
(interfaces::process_events() is called by both hosts and plugins.)

Apparently most developers pre-allocate a generous fixed size array for the midi input and only re-allocate when the size doesn't suffice. (Or truncate midi events per frame to that generous limit.)

We could do this by passing a &mut Vec to process_events(), which the caller (plugin and host) pre-allocates to a generous size outside of the audio thread.
Or do you have a better idea?

(The init and reset opcodes are supposed to be for allocations.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions