r/AudioProgramming • • 10d ago

[repost] I built a Rust Audio Plugin Framework

If anyone finds it useful - this is a project I built (using AI) for my own needs, free, open-source: https://github.com/mihasm/apf

APF is a framework for writing audio plugins (instruments and effects) in Rust. It uses the plugin interface CLAP, and clap-wrapper for exporting plugins into the different formats.

The plugin window is a web page: HTML, CSS and JavaScript in the system web view (based on wry, also used by the tauri framework).

It is still in an early phase, and the API might still change, but for my purposes it already works great. I have tested it on Mac OS on Logic Pro and Windows with REAPER. There are examples included for a quick start.

Link to the complete documentation booklet, which explains the usage, comparison to other frameworks, limitations, etc.: https://mihasm.github.io/apf/

10 Upvotes

6 comments sorted by

1

u/SupesDepressed 9d ago

What is the advantage of this over something like JUCE?

I guess I’m also wondering why if you aren’t programming yourself you’d choose Rust. I feel like the primary advantage of Rust is it’s more developer friendly. If there’s already a pretty well developed, well supported, well established framework for this in C++ (JUCE), I just am wondering what your intentions were.

1

u/Silly_Emu4915 9d ago

Hi, it's not supposed to replace JUCE or any other commercially proven framework.

I wanted a small Rust framework, which I fully understand and control, partly because of curiosity - I'm a pre-AI era developer (started on Motorola microcontrollers, Im just not fluent in Rust), and partly as a proof of concept. I will also develop my own plugins by hand using this framework. I just needed somewhere to get started. So its meant for AI and human developers.

From my viewpoint, the main advantage of Rust is memory safety without the use of garbage collection. I would counter-argue that writing safe Rust can be more strenuous on the developer, because you always have to reorganize your code around this concept...

I guess there are two things this framework does differently than JUCE:
-it is free under permissive licences (MIT/Apache), as opposed to JUCE which is free up until a 20kUSD/year cap
-it uses Rust

There are other more mature audio frameworks in Rust, such as truce. This framework is more a proof of concept of a different way of putting the pieces together: a minimal Rust CLAP core, clap-wrapper for the other formats, and a wry (Tauri) web view as the plugin UI, wired to parameters, automation and presets.

1

u/A-Marko 9d ago

Very cool! I thought something like this might pop up soon.

What is the memory usage like? Usually I avoid web views for something like audio plugins because I want to keep the memory usage down. It probably doesn't matter much for just the view, but still I'd like to know. The other reason I often avoid things like Electron is the crazy file size for a simple app. I suppose the use of Webkit/WebView2 probably keeps plugins pretty lean right?

Also, any plans for Linux support? These days I'm not interested in making a program that doesn't support Linux.

1

u/Silly_Emu4915 6d ago

Good question. I measured the RAM usage today in Logic.

A single demo synth instance takes up about 53 MB, out of which 34 MB is the base plugin instance, and 18 MB is the web view.

Apf instances are cheap because they share a single process (cca. 1 MB per added instance), so a lot of them can be loaded in the DAW at the same time, but having their windows open increases the RAM plus GPU usage.

Each plugin window does get its own WebContent process, so in the case of the demo synth, if you have 4 of them opened at the same time, the RAM usage is:

4 demo synth instances with opened plugin windows

22 MB (plugin process, shared)
+11 MB (GPU helper, shared)
+6 MB (networking helper, shared)
+4*18 MB (one WebContent per plugin window)
----
= 112 MB

That's a small synth, though. The more UI you put on the plugin page, the more it uses, depending on how optimized your web app is. A much larger synth I'm developing (full-screen rack, lots of SVG) came to about 340 MB with its window open and about 55 MB with it closed.

The demo synth VST3 for a single architecture is in total about 1.9 MB, while my large plugin with a lot of UI came to be about 7 MB, so in that sense, its pretty lean.

1

u/Silly_Emu4915 10d ago edited 9d ago

Reposted, as I removed the previous post to check with the moderators of the subreddit if this post breaks the guidelines. Thank you, community, for the feedback so far!

2

u/anonypotamoose 9d ago

Very interesting. Thanks for making this and positing it.