Programming tutorial series for creating LV2 plugins using C/C++ and turtle.

Programming LV2 Plugins From Scratch

Programming tutorial series for creating LV2 plugins using C/C++ and turtle.

Content

00 - Announce

See video: https://www.youtube.com/watch?v=51eHCA4oCEI

01 - Introduction: What is LV2?

See video: https://www.youtube.com/watch?v=AdB2pLCFQY4

LV2 is a free and open source audio plugin standard. LV2 is available on Linux, Mac, Windows, and on other systems. There are more than 1000 LV2 plugins available by now. And the number is growing.

LV2 is exensible and stores its meta-data (like plugin name, plugin type, and ports used) in separate files. This allows to get plugin informations without loading and executing the plugin.

To create LV2 plugins, you need:

  • a C/C++ compiler (gcc, Clang or MSVC),
  • an editor (Atom, Eclipse, VS Code, KDevelop, or ...),
  • and some developer libraries:
    • C/C++ libraries
    • LV2
    • sndfile
    • X11 (or ...)
    • Cairo
    • pkg-config

On Debian linux-based systems you can get them by calling from the terminal:

sudo apt-get install build-essential
sudo apt-get install pkg-config lv2-dev libsndfile1-dev libx11-dev libcairo2-dev

And on Arch linux-based systems you can get them by calling from the terminal:

sudo pacman -S base-devel
sudo pacman -S pkg-config lv2 libsndfile libX11-dev cairo

Recommended optional tools:

  • Jalv (minimal LV2 host)
  • lv2lint (validation)
  • gdb (debugger)
  • valgrind (memory debugging / leak detection)

02 - A Simple Amplifier (Part 1) - Do The Turtle

See video: https://www.youtube.com/watch?v=aKN89LnmbvQ

Introduction to the basic principles of the Turtle description language. Subject, predicate, and object. And URIs. Define the metadata for a simple amplifier plugin.

03 - How LV2 Plugins Work

See video: https://www.youtube.com/watch?v=Zg-YUbfO6ww

This videos provides a look under the hood of an LV2 plugin and shows how it works inside a DAW. The plugin has to provide:

  • a manifest (and a linked plugin turtle file) for the plugin metadata, and
  • a plugin binary file with
    • a C interface function
    • the seven core functions
      • instantiate
      • connect_port
      • activate
      • run
      • deactivate
      • cleanup
      • extension_data
    • a plugin class definition (at least) with pointers to the buffers provided by the DAW (ports).

The DAW has to provide:

  • buffers for audio in, audio out, ...
  • buffers for the controllers
  • functions to call the plugin functions.

04 - A Simple Amplifier Plugin (Part 2) - Code, Compile & Run

See video: https://youtu.be/XSxZ4_SdqIQ

Coding in C. Basic introduction into C programming and what we need to make LV2 plugins:

  • a class definition using typedef struct,
  • the seven core functions called:
    • instantiate,
    • connect_port,
    • activate,
    • run,
    • deactivate,
    • cleanup, and
    • extension_data
  • a descriptor struct which contains:
    • the plugin URI as a C string and
    • the pointers to the seven core functions (or NULL if not needed), and
  • a C interface function which returns a pointer to the descriptor struct.

Compile the code from the code directory with:

gcc -fvisibility=hidden -fPIC -Wl,-Bstatic -Wl,-Bdynamic -Wl,--as-needed -shared -pthread `pkg-config --cflags lv2` -lm `pkg-config --libs lv2` myAmp.c -o myAmp.so

Copy the resulting .so file and the two .ttl files into a newly created subfolder (I call this folder myAmp.lv2/) in one of your systems LV2 folders. Like the hidden LV2 folder of your home directory: ~/.lv2/.

Then you can test the plugin in an LV2 host, like the minimalistic jalv:

jalv.gtk3 https://github.com/sjaehn/lv2tutorial/myAmp

(gtk3 may be replaced by one of the other jalv variants). Or feel free to directly test myAmp within a DAW.

Now we completed our first LV2 plugin!

05 - A Sound Generator In C++

See video: https://youtu.be/uvskHCJrJcY

Programming a test tone generator as a first step to make a software synthesizer.

Topics:

  • Introduction in classic C++.
  • LV2 extensions: Units, Port Properties
  • Writing a sine wave to the audio output

06 - Atom, URIDs & URIs

See video: https://youtu.be/EHpwO5yl66s

Introduction into the data structures used in LV2: Atoms, URIDs and URIs.

  • LV2_Atom: Data containers with information about type and size. LV2_Atoms may have a body to store data of different types (like int, float, double, string, ..., and even other atoms).
    • Vectors are LV2_Atoms which contain an array of child data and information about the child type and the child size.
    • Properties are "named" LV2_Atoms which contain a key URID and data (e.g., as LV2_Atoms again).
    • Objects are LV2_Atoms which may take up multiple and/or different other property LV2_Atoms.
    • Events are prefixed with a time stamp.
    • And Sequences are LV2_atoms which can take up multiple events.
  • URI: Unique identifier for each definition.
  • URID: Serial number for an URI.

07 - The Simplest MIDI Synth (Part 1)

See video: https://youtu.be/PuOeP-ln7UA

Programming a simple MIDI sine synth LV2 plugin based on our myTestTone.

Topics:

  • Implementation of the LV2 extensions:
    • Atom
    • Urid
    • Midi
  • Understanding LV2 MIDI atoms
  • Programming a basic MIDI interpreter

08 - The Simplest MIDI Synth (Part 2)

See video: https://youtu.be/-mnleLiofdI

Programming a simple MIDI sine synth LV2 plugin based on our myTestTone.

Topics:

  • MIDI data
  • Convert MIDI notes to audio frequency
  • ADSR envelope

09 - Waveform Synth In C++ 11

See video: https://youtu.be/5zbQLFNZRoI

Add a waveform selection feature (sine, triangle, square, saw, noise) to our synth. And this in modern C++. But first, we have to update our previously written code to C++11 too.

Topics:

10 - Performance & Polyphony

See video: https://youtu.be/uelx7poEMNY

In the previous videos, we created a simple monosynth. This time, we will enable polyphony by the use of key containers. This video also shows the features and the limitations of the C++ standard template library (STL). And this video also shows different ways of increasing the plugin performance.

Topics:

  • Header files
  • Polyphony using key as a std::array
  • Alternative STL containers
    • std::vector
    • std::map
    • C++11 for loop
    • Using interators
    • Performance considerations
    • Realtime compatibility
  • BUtility::BMap
  • Compiler flags (-O3, -ffast-math)

Resources

Further reading

Similar Resources

Some GCC plugins useful for OI training/judging.

gcc-plugin-for-oi Some GCC plugins useful for OI training/judging. Currently, only one plugin no_opt_attr_plugin is included. Build Simply make all. O

Mar 14, 2022

Flutter plugins used in Mixin

This repo contains the source code for Flutter plugins which used in Mixin. Check the packages directory for all plugins.

Dec 1, 2022

Portedplugins - A collection of plugins for the SuperCollider sound environment, all of which are ported / remixed from elsewhere

PortedPlugins A collection of plugins for the SuperCollider sound environment, all of which are ported / remixed from elsewhere - including hardware s

Nov 14, 2022

this repo creating three fractals using minilibix (created by 42-Network) and it contains three fractals

Welcome to the beautiful worlds of fractals Hi my name is yahya AKA Ma3ert this projects create three fractals using the minilibix library which's cre

Nov 14, 2022

Writing a basic compiler frontend following LLVM's tutorial, with complete added supports Hindi and UTF-8 in general

Writing a basic compiler frontend following  LLVM's tutorial, with complete added supports Hindi and UTF-8 in general

सारस | SARAS Started with following LLVM's tutorial In development, a hobby project only JIT is broken right now, 'jit' branch par code hai uska Compi

May 1, 2022

Implementation and tutorial for a dynamic vector data-structure in C.

Vec: A Dynamic Vector in C The subject.md file contains exercises for this implementation if you want to do it yourself. In that case, don't peek at t

Oct 17, 2022

Load bitstream to AG1K series FPGA using CH552

Load bitstream to AG1K series FPGA using CH552

ch552-ag1k-msd Load bitstream to AG1K series FPGA using CH552 AG1K does not have a built-in data flash; This design only simulate a USB mass storage d

Nov 16, 2022

Tutorial to connect the Waveshare display ST7789V to the ESP32

Tutorial to connect the Waveshare display ST7789V to the ESP32

ESP32-ST7789V This repository contains the required configuration to connect a display Waveshare ST7789V to an ESP32 board. The correct connection to

Sep 12, 2022

Specular Lighting in OpenGL (Followed tutorial by Michael Grieco)

Specular lighting in OpenGL Specular Lighting in OpenGL (Followed tutorials by Michael Grieco). 2022-02-13.01-55-21.mp4 Setup Clone $ git clone https:

Feb 18, 2022
Comments
  • manifest.ttl does not need to be minimal

    manifest.ttl does not need to be minimal

    Hi, just starting a few corrections for things you have mentioned either on the 1st video or in written text.

    First thing is that you say manifest.ttl has the entry point and minimal data, where the plugin real definitions are on a separate file. While this practice is common, it is not required and everything will work fine if you only have a single manifest.ttl file and nothing else. You can put as many resources as you want in separate files, you can even add new stuff to existing pre-installed plugins from a separate bundle that reference some other URI.

    manifest.ttl is just the entry point as defined by LV2, but whatever is inside and where stuff is defined is up to each one to do as they see best.

    PS: LV2 bundles also do not need .lv2 suffix, see setbfree as example.

  • Maybe having a forum to discuss this tutorial ?

    Maybe having a forum to discuss this tutorial ?

    Like for example I would like to have autocompletion for lv2, rdf, doap ... I installed "Stardog RDF Grammars" the grammar is highlighted, but there is no autocompletion. I tried to use lv2lint without success (I did not investigate much)

  • LV2 is available for any system, not just macOS + Windows + Linux

    LV2 is available for any system, not just macOS + Windows + Linux

    You mention that LV2 is available for these 3 systems, in a way that sounds like it only works on these 3 systems. But LV2, being a specification, works for any compatible system. There are no requirements whatsoever on the LV2 side, you dont even need to be using C or C++, people have successfully written D and Rust LV2 plugins already.

  • Plugin DSP and UI binaries do not need to be split

    Plugin DSP and UI binaries do not need to be split

    Another correction.

    Having the plugin dsp stuff in a binary and the UI in another binary is not a requirement. Developers are free to place everything inside a single binary, even multiple plugins and multiple UIs.

    You can also split the binaries inside an LV2 bundle so each plugin in the bundle gets a different one.

    In resume, there is no restrictions for this whatsoever, and implying there is, is misleading.

SDK for creating GTA IV .asi plugins
SDK for creating GTA IV .asi plugins

iv-sdk "SDK" for creating GTA IV .asi plugins Supports 1.0.7.0 and 1.0.8.0 (EFIGS only) The majority of the project has been created for 1.0.8.0 and t

Oct 23, 2022
A set of tutorial projects for creating a simple digital radio receiver based on the STM32G431KB microcontroller

simple-radio Обучающие проекты по созданию простого цифрового радиоприемника на базе микроконтроллера STM32G431KB. Разработка программ выполнялась в W

Sep 21, 2022
Pure Data patch export to lv2 plugin using heavy compiler + dpf example
 Pure Data patch export to lv2 plugin using heavy compiler + dpf example

Pure Data patch export to lv2 plugin using heavy compiler + dpf example Work in progress - Takes an audio input and writes to a 0.5 seconds buffers. 4

Jun 13, 2022
A lightweight additive chiptune synthesizer (LV2 and Unity Plugin)

OvenMit Synthesizer kenakofer's first ever synthesizer! Coming initially out of BMusic's excellent tutoral series for lv2 synthesizers, the developer

Oct 22, 2022
No loss LV2 sound effect plugin

B.Spacr Description: LV2 sound effect plugin B.Spacr is a unique LV2 effect plugin that enables a clear and brilliant audibility of your music product

Aug 24, 2022
Multi-dimensional dynamically distorted staggered multi-bandpass LV2 plugin
Multi-dimensional dynamically distorted staggered multi-bandpass LV2 plugin

B.Angr A multi-dimensional dynamicly distorted staggered multi-bandpass LV2 plugin, for extreme soundmangling. Based on Airwindows XRegion. Key featur

Nov 7, 2022
In this Program, I am using C language and creating All Patterns Program using Switch case
In this Program, I am using C language and creating All Patterns Program using Switch case

In this Program, I am using C language and creating All Patterns Program using Switch case. It has 15 pattern programs like a pyramid, half pyramid, etc...

Nov 13, 2021
Dockerfile/docker-compose Elasticsearch with plugins elasticsearch-analysis-vietnamese and coccoc-tokenizer

docker-es-cococ-tokenizer Dockerfile/docker-compose Elasticsearch with plugins elasticsearch-analysis-vietnamese and coccoc-tokenizer Deployment docke

Nov 8, 2022
PLP Project Programming Language | Programming for projects and computer science and research on computer and programming.
PLP Project Programming Language | Programming for projects and computer science and research on computer and programming.

PLPv2b PLP Project Programming Language Programming Language for projects and computer science and research on computer and programming. What is PLP L

Aug 20, 2022
Flutter plugins for embedded Linux (eLinux)

Flutter plugins for Embedded Linux (eLinux) This repo is a companion repo to the flutter-elinux. It contains the source code for Flutter plugins for e

Nov 18, 2022