Question Regarding Creating Custom Plugins

Programming applications for making music on Linux.

Moderators: MattKingUSA, khz

Post Reply
Shortstop
Established Member
Posts: 25
Joined: Sun Jun 13, 2021 10:48 pm
Been thanked: 3 times

Question Regarding Creating Custom Plugins

Post by Shortstop »

Hey there,

I do tech support for my actual day job, and am pretty comfortable with viewing and editing code.

I was wondering, what are the best projects to just git clone and modify a bit to learn from?

Are all these plugins based in C?

Or is there anything that's worthwhile in Python?

I ask because I honestly prefer Python and Bash a bit as opposed to straight C, but let me know what exists! Would love to fork some stuff and learn a bit as I always wanted to make some plugins.
Basslint
Established Member
Posts: 1511
Joined: Sun Jan 27, 2019 2:25 pm
Location: Italy
Has thanked: 382 times
Been thanked: 298 times

Re: Question Regarding Creating Custom Plugins

Post by Basslint »

Python is not suitable to write plugins because it's not meant for real-time usage for a number of reasons.

There are two popular standards for plugins on GNU/Linux, LV2 and VST3. VST3 plugins can be written in C++ exclusively, LV2 can be written in C, C++ or other suitable languages (like Rust, Zig and Nim).

Since Zig is easier than C IMHO, here is a simple plugin written in Zig :D
The community of believers was of one heart and mind, and no one claimed that any of his possessions was his own, but they had everything in common. [Acts 4:32]

Please donate time (even bug reports) or money to libre software 🎁

Jam on openSUSE + GeekosDAW!
User avatar
Michael Willis
Established Member
Posts: 1431
Joined: Mon Oct 03, 2016 3:27 pm
Location: Rocky Mountains, North America
Has thanked: 67 times
Been thanked: 155 times
Contact:

Re: Question Regarding Creating Custom Plugins

Post by Michael Willis »

I have used Distrho Plugin Framework to develop plugins in C++. Take a look at my Dragonfly Reverb project for some example code.

I have also experimented with DPlug, which uses D language. I had no prior experience with D, but now I think it's a nice language.
Shortstop
Established Member
Posts: 25
Joined: Sun Jun 13, 2021 10:48 pm
Been thanked: 3 times

Re: Question Regarding Creating Custom Plugins

Post by Shortstop »

Michael Willis wrote: Fri Jun 18, 2021 3:44 pm I have used Distrho Plugin Framework to develop plugins in C++. Take a look at my Dragonfly Reverb project for some example code.

I have also experimented with DPlug, which uses D language. I had no prior experience with D, but now I think it's a nice language.
Oh wow! You made the Dragonfly Reverb plugin?

I've used that a TON over the last 2 albums I worked on, that's so awesome. Thanks a ton for this :)

I'll take a look at the code for your project as well to see if I could learn anything and maybe think about making my own plugin :)
User avatar
mike@overtonedsp
Established Member
Posts: 145
Joined: Mon Apr 24, 2017 5:26 pm
Location: Oxford, England
Been thanked: 55 times
Contact:

Re: Question Regarding Creating Custom Plugins

Post by mike@overtonedsp »

SamwiseStrikesBack wrote: Fri Jun 18, 2021 3:30 am ...honestly prefer Python and Bash a bit as opposed to straight C,
I use C and C++, as god and nature intended. You really shouldn't try to write plug-ins using Bash :)
User avatar
Michael Willis
Established Member
Posts: 1431
Joined: Mon Oct 03, 2016 3:27 pm
Location: Rocky Mountains, North America
Has thanked: 67 times
Been thanked: 155 times
Contact:

Re: Question Regarding Creating Custom Plugins

Post by Michael Willis »

SamwiseStrikesBack wrote: Sat Jul 03, 2021 7:36 pm Oh wow! You made the Dragonfly Reverb plugin?

I've used that a TON over the last 2 albums I worked on, that's so awesome. Thanks a ton for this :)
Heh, I always smile when somebody says that they like using Dragonfly Reverb, it makes me feel like I've finally earned that "open source contributer" badge that I dreamed of for years. I actually can't take credit for the sound though. Dragonfly Reverb is built on the work of many other people: Teru Kamogashira, Fons Adriaensen, John Dattorro, James Moorer, and the list goes on and on. I mostly just took the code from Teru's freeverb3 project and used it to build plugins with DPF.
patchlore
Established Member
Posts: 8
Joined: Tue Sep 07, 2021 1:23 pm
Been thanked: 8 times

Re: Question Regarding Creating Custom Plugins

Post by patchlore »

So, what does it mean to make a "plugin", anyways?

> Are all these plugins based in C?

Kind of? Practically speaking, all roads eventually have some C code at some point in the chain. This actually isn't for performance reasons, but because it's the path of least resistance.

Audio Plugins, as a concept, revolve around a thing in computing called "dynamic loading": https://en.wikipedia.org/wiki/Dynamic_loading

In a nutshell: having the ability to load pre-compiled code from a file while a program is running, and then calling functions found inside of that bit of code. Rendering audio to a buffer, changing a parameter. That blob of pre-compiled code is gonna have the function for that!

Audio Plugins are little more than dynamically loaded files that have agreed upon a set of functions to use (a specification/protocol).

Dynamic loading (specifically libdl) is a feature that exists in C. dlsym, the function in charge of actually finding the name of the function, looks for symbols which correspond to the names of C functions. This is why plugin formats eventually boil down to C. It's just the path of least resistance. Even C++ plugins usually have a bit of C wrapper code at the end of it because C++ compilers mangle namespaces a bit during compilation.

> I was wondering, what are the best projects to just git clone and modify a bit to learn from?

I learned the most about the concept of audio plugins studying the original LADSPA SDK. As far as plugin formats go, it's the smallest and simplest. It's very easy to get to the bottom of how it works. Most modern formats like VST, LV2, AU, are enormously complex in comparison. The SDK even comes with sample code for a plugin loader, which I highly recommend glancing at. You can actually *see* the libdl calls like dlopen, dlsym, etc. Seeing that made most of the mystery go away for me:

http://www.ladspa.org/ladspa_sdk/download.html
https://github.com/adsr/ladspa-sdk/blob ... src/load.c

> Or is there anything that's worthwhile in Python?

Technically, I think you probably could write an audio plugin with Python. You'd just need the end point to be wrapped around a C function, and there'd need to be away to instantiate an instance of Python inside of the plugin. I would never discourage someone from doing it in the name of science and exploration, but my guess is that it would probably be very impractical.

As mentioned already, yeah, Python is usually not a good choice for real-time audio, specifically. With languages like Python, it's some kind of overhead it brings. Most of the time, this comes down to how memory is managed. Making memory allocation calls on the audio render thread is indeterminate behavior that can vary in time in ways that are hard to predict. This is *not* something you want when you have a buffer of audio that needs to be rendered in a certain amount of time or less, otherwise it will "drag" and cause an audible glitch. Languages like Python use Garbage Collection for memory management, which usually isn't suitable for real-time computing. It's not just a Python thing either. Most modern programming languages are implemented in a way that makes it unsuitable for the niche of real-time computing. Which is why audio programmers tend to gravitate to only a small handful of languages.

This classic "Time Waits for Nothing" blog post by Ross Bencina goes into more detail about this:

http://www.rossbencina.com/code/real-ti ... or-nothing
Post Reply