Friday, 20 January 2012

A Journey into VST

The VST (Virtual Studio Technology) plugin is one of the universally used tools in electronic music, so learning how to use it was pretty exciting.  Although it's proprietary and owned by Steinberg, it's the actual API code they don't like you spreading, so I'll be sharing a link to my first (unimpressive) VST plugin.

On installing the VST SDK (SDK = Software Developers Kit) I instantly faced a dilemma.  As you probably know, I've been following the "Audio Programming Book", although along the way I've made little adaptations, either to get it working at all or just because of coding style.  I think for a coding newbie this would be daunting, but for me I've learned so much more because of it.  Anyway, the book has a chapter on creating a VST plugin, but, it's using VST 2.  VST 3 has been out for a few years now.  I feel that as a programmer, I should be keeping up to date and adapting to changes.  Unfortunately, it turns out that VST 3 has completely changed everything, the hierarchies of classes, what the functions are called, so how to do even the most basic things.  This was a big obstacle for me.

However, any good SDK is well documented, and this was mostly partly true of the VST SDK.  My biggest criticism it was hard to get the big picture - there were no simple overviews or plans of action for a beginner.  I was surprised to find there aren't any tutorials for VST 3 (there were quite a few for VST 2).  When I become more familiar with it, I'll have a shot at writing a tutorial myself.  Fortunately, there was the next best thing though - a selection of simple demo plugins.  From this I could derive a template to allow me to make my plugin.

Once I made the decision of which route to go down, I then had to decide what my plugin would do.  I wanted to make basically the simplest possible plugin, one that did almost nothing, but still something I could evaluate.  So I made a first order averaging filter plugin - it only required one delay frame and the processing was really, really straightforward.  This meant I could focus on learning the API rather than how the filter worked.

When working on it, the biggest source of frustration was the documentations' lack of clarity on a few things.  I had no clue what the "factory" classes were and what they were doing, I'd just made them because they appeared in the demo.  Turns out they're called to create instances of all the classes you've made.  What the "tail samples" were took me ages to work out - when I tested my plugin this was the only thing the test host failed it on (there's a program that comes with the SDK that tests your plugins to check they follow the VST standards).  I eventually worked out that the tail samples were the trailing samples, so basically how long it takes for the sound to die to nothing after input stops.  For my filter, this was simply a single sample, so 1.

Steinberg supply a test host application to test your plugins
My final frustration came from the unique ids that the demo had given to its processor and controller - I had no idea were these came from.  Steinberg provide an old service to register plugins, but this gave you only 4 ASCII characters, and I needed 32 hex characters.  What made it annoying was the fact there was no documentation on the subject... at all.  Thanks to internet forums I discovered this id was known as a GUID (globally unique identifier) and could be generated by a tool that came with Visual Studio (guidgen.exe).  However, there are also many online GUID generators, for example, this one.

Of course, after writing it and ensuring it follows the VST standards, I then had to test the audio output.  I tested it with a sweeping sine wave, from 20Hz to the Nyquist frequency, and looked at the audio produced in Audacity.  The only problem I found was on going from bypassed to active, the plugin produced a loud click.  I found this was because the I wasn't updating the delay frame when the filter was bypassed, so this left-over sample could produce a sudden difference in loudness, ie a click.
 First I checked the input - sine wave sweeps from 20Hz-20kHz
 For this I made use of Audacity (for viewing the waveforms), VSTHost, and the mda test tone plugin, both of which are free.  The input is simply a sine wave sweeping from low to painfully high (20Hz to 20kHz).  If you're confused by the pictures, in each picture I've captured two sweeps.

Here is the output, my filter works!
 If you remember back a while to the theory behind this, hopefully you'll agree we've got the same shape as the frequency response graph.  (At the top frequencies a little bit's been chopped off - that's because the sine wave sweep wouldn't let me go all the way up to 22,050Hz).

My filter has basic functionality - it acts as a gentle low pass filter and supports bypassing, where the filter is turned off and audio goes straight through unaltered.  But most importantly it's allowed me to understand the VST SDK a bit more, so you can expect future projects to be more exciting.

Here is a link to the plugin, where you're free to download it and try it out for youself.

As a side note, if you're a developer / musician wondering where to put VST plugins, you have two options available to you - most host programs have a folder named "plugins" or something, and you can copy them in there.  Alternatively, on Windows you may have the folder C:\Program Files\Common Files\vst where you can put plugins and have them be picked up by most hosts.

No comments:

Post a Comment