Plotting waveforms

I am currently working on a new softsynth project and wanted to get some more immediate feedback of code changes to waveforms shapes, since most of the synthesis used in rogue are related to phase/waveform shaping.

Instead of plotting the waveforms via scripting tools like python or ruby, I decided to use Javascript for it. I set up a minimal table structure in the HTML document and plotted the waveforms via jquery, Flot and various phase to wave functions.

The HTML file is available here and it looks like this

waveforms

The waveforms are categorized by synthesis types: VA for virtual analog, PD for Casio CZ style phase distortion, EL for various electronic waveforms and AS for additive synthesis.

The width controls the pulse width or distortion of the waveform and the tone field controls the brightness for additive synthesis. This combination gives me the possibility to try out new waveforms easily.

The functions used in the plot are referenced in the HTML document and take three arguments, the phase, the width and the tone. All parameters are from 0 to 1. The waveform plots are for 1.5 cycles.

Typed Lisp adventure

After having been inspired by overtone and extempore to try out a Lisp dialect for DSP coding I wondered if it would be possible to use a Lisp language directly in synth plugins without a host environment.

My second (or third) language in daytime programming is Clojure, which I am very content with, so I wanted to use something similar in my “freetime” for DSP programming. I initally tried some Scheme dialects such a Chicken, Gambit and Bigloo, but became a little annoyed by the verbose syntax and the lack of proper abstractions for collection like types.

On GitHub I stumbled upon a few statically typed Lisp dialects and was especially convinced by looking at extempore that writing a statically typed LISP was possible and for some programming domains even useful. So I decided to write something similar like extempore, but with Clojure syntax instead of Scheme and without a host environment but gcc based compilation instead. I named the exercise symbol.

I considered using LLVM as the compilation backend briefly, but found especially closure handling too difficult to handle, since I hadn’t any prior experience in compiler programming. I went with using C++11 as the target language since it has some nice features such as templates, closures, direct C bindings and fast compilers.

Next I began to sketch the architecture for my language compiler. After a few iterations and studying various Clojure/script compilation projects I went with

  • reading via a customized Clojure Lisp reader
  • macro expansion, using Clojure macros
  • form normalization via various function based rules
  • type inference using core.logic
  • serialization to C++
  • compilation via g++

The most challenging part was probably the type inference. Having used logic programming actively 10 years ago it was a little difficult to get into logic programming concepts again, but after a few core.logic performance issues, most things went quite smoothly.

I was able to infer variable types based on assignments and function argument and return types via body expressions using a simplified version of the type inference. In addition to Hindley-Milner type inference I also extended the set of literals of the syntax via a custom reader to support integer and float literals in addition to ones Clojure supports.

I was quite successful with porting simple extempore examples to symbol, but struggled with more complex programs. I also couldn’t decide whether to include garbage collection or not. Using smart C++ pointers might have been a good alternative, but might have been difficult for type inference, so I continued with raw pointers and without garbage collection.

I tried to use C++ bindings directly via gccxml which dumps the intermediate format of the gcc compilation via XML, but had some issues with it. gccxml doesn’t support templates and the XML format was difficult to transform into a form that was compatible with the types of the type inference.

Another difficult issue was to map both stack and heap allocation to the minimal syntax of symbol. After a while I gave up and began to use C++ directly for DSP programming. All in all this was a really interesting experience to sketch a new language, or better a compilation chain, since what I did could also be described as mapping a subset of Clojure syntax to C++. I might continue with symbol once I am more familiar with C++, but for now it’s suspended.

Various syntax examples are available here.

Diving into D

After having used C++ and Faust for a while to write Synth plugins I decided to try out some alternatives. My main requirements for the language were automatic memory management, easy to use bidirectional C interfacing for using and exposing C libraries and support for functional programming. I considered amongst others OCaml, Haskell, D and Vala as language options. After a small evaluation of the options I decided to focus on D. OCaml didn’t look like a proper evolution over Standard ML, Haskell too demanding to learn and Vala with too many Gnome dependencies.

D is a statically typed C-based language with the ambitious goal to provide a better C++. It feels more consistent than C++, but sits oddly between a system and application level language. As a small exercise I ported the STK library to D to get a better feel of the language features. I named the port synd.

What I liked were the module system, properties, type inference and integrated support for unit tests. What I found confusing were mutability of ranges, initialization of members and the quite heterogeneous community. Missing support for shared library creation in Linux is a showstopper for now.

I am still trying to figure out whether to use closures for lower level elements or Class based objects. The FP approach allows for more consistent types and composition of elements whereas the OOP approach offers better separation between configuration and other method calls.

Cascaded delegate construction would also work in D. And it works quite well for elements where only static and sample based configuration parameters are used. For configuration updates let’s say every 32 samples something else would need to be used.

Both extempore and Overtone look like good sources of inspiration for doing functional audio coding.

Soft synth plugins for Linux

Before starting with a new Soft synth project for Linux I decided to track what kind of synthesizers are already out there available. I focused on LV2 plugins, since LV2 is the plugin standard I want to use. LADSPA is outdated and DSSI doesn’t seem to be as widely used as LV2.

With the aim to provide a clear separation between the synthesis engine, the LV2 integration and the GUI I focused also on architectural aspects.

So here is a list of LV2 soft synths for Linux in no particular order.

Calf plugins

Calf plugins provides a set of plugins available as LV2, including a flanger, an organ synth, a phaser, a reverb, some filters, a chorus and a rotary speaker simulator.

Calf Monosynth

The Calf Monosynth is a monophonic subtractive soft synth.

Calf Organ

The Calf Organ is a mixture of a traditional drawbar organ and a subtractive synth.

Calf Fluidsynth

The Calf Fluidsynth is a frontend for the Fluidsynth Sampler engine.

foo-yc20

The YC-20 is a divide-down combo organ designed in the late 60′s. The foo-yc20 emulation faithfully copies the features, sounds and flaws of the original organ.

Foo YC20

Newtonator

The Newtonator is a LV2 soft synth that produces some unpredictable sounds.

Newtonator

LinuxSampler

The LinuxSampler is a streaming capable open source pure software audio sampler with professional grade features.

Minaton

The Minaton is a fat sounding mono subtractive software synthesizer.

Minaton

ll-plugins

ll-plugins provides several synth and utility plugins and a GUI-capable host.

Composite Sampler

Composite Sampler is a LV2 plugin that acts as a MIDI-controllable sampler.

lv2-mdaEPiano

lv2-mdaEPiano is a native LV2 port of the famous mdaEPiano VSTi.

mda-lv2

mda-lv2 is an LV2 port of the popular VST mda plugins.

Russolo Suite

The Russolo Suite consists of the CrazySynth Synthesizer and the “the do-it-all effect” Omnifono.

So-synth-LV2

So-synth-LV2 provides unofficial LV2 ports of 50m30n3′s synthesizers.

Zyn

Zyn provides an LV2 port of Zynaddsubfx.

Qin

Qin is a LV2 synth plugin for plucking sounds

Minicomputer-LV2

Minicomputer-LV2 is a softsynth for creating experimental electronic sounds

lv2_guitar

lv2_guitar is another String synth

This list has been assembled from the contents of the following two webpages:

Summary

Here is also an overview of the used programming languages and GUI toolkits in each plugin:

Name Languages GUI Remarks
Calf Plugins C++ GTK+ UI is defined in XML, knobs are created from SVG files and rendered via Cairo
foo-yc20 C/C++/Faust GTK+ Faust is a functional language for DSP design
Newtonator C++ GTK+ -
LinuxSampler C++ Qt4 Qt4 is only one GUI option, there is also a Java based UI
Minaton C++ FLTK -
ll-plugins C++ GTK+ ported from DSSI plugins
Composite Sampler C++ - part of bigger Composite audio system effort
lv2-mdaEPiano C++ - -
Russolo Suite C - -
So-synth-LV2 C - -
Zyn C/C++ - extracted Synth engines from ZynAddSubFx
Qin C - -
Minicomputer-LV2 C - -
lv2_guitar C - -

From this overview can be seen that most of the GUI-less plugins have been written in C++, whereas the plugins with GUIs have been mostly written in C++. GTK+ is prefered over Qt and FLTK as a GUI toolkit.

Popular Non-LV2 synths

As the LV2 plugin is still quite new, there are lots of great established soft synth projects that are not available in LV2 format.

Here are some of the more popular options:

Name Languages GUI Remarks
amSynth C++ GTK++ Subtractive synth with 2 Oscillators
Bristol Audio Synthesis C ? Emulation of various vintage keyboard synths
Qsynth C++ Qt4 Popular Qt based frontend for FluidSynth
ZynAddSubFx C++ FLTK Very popular synth with three different synth engines
Hydrogen C++ Qt4 Popular drum machine
hexter C GTK+ very good Yamaha DX7 synth emulation
WhySynth C GTK+ Versatile multi paradigm soft synth