Tuesday, May 12, 2009

Creating plugins with SuperCollider AU

SuperColliderAU is an AudioUnit wrapper that allows you to embed a SuperCollider server in a AU host and either control it through SClang or package it up as a stand alone plugin.
It is of course OS X only being based around Apples AU API and there are some limitations to what you can do with it. According to the SourceForge page activity on this project seems to have stalled a bit, but it's pretty usuable in it's current state. It is possible to create effects units, but instruments with midi support don't seem to work very well. I've strugled to get anything to happen with Garage Band as a host at least, but that could just be me.
To install it you'll need to follow the instructions provided on the readme, it's very simple, just adding the main class and the server to the relevant directories, then recompile the lang and you're ready to go.
I decided to use it to create a bitcrushing plugin, making use of the Decimator Ugen, featured here before. The code is really simple, here it is.

( var name, func, specs, componentType, componentSubtype, builder;

name = "Decimator"; // name of your plugin
func = {
| sampleRate, bitRate|

var decOut, in;

in = AudioIn.ar([1]); //Input from AU host

decOut = Decimator.ar(in, sampleRate , bitRate);

Out.ar(0, decOut);//Output to AU host

specs = #[
[0, 20000 , \Linear, 10000,\Hertz ] ,
[0, 16 , \Linear, 8,\Indexed ]

componentType = \aufx;

componentSubtype = \DECI;

builder = AudioUnitBuilder.new(name, componentSubtype,func, specs, componentType);



There's a function, this is the code that the server will execute when it's embeded in the AU host, there's an array of specs that described the units, range and presets for the GUI control and a builder command that takes the relevant arguments and packages up the plugin.
The function is a very simple effect patch that takes the audio in from the AU host, decimates it and sends it to the output. The help file is a bit vague about this, but I assume that the relevant audio bus used for input from the AU host is 1, and that it needs to be sent out through 0, this is what seems to work anyway.
After that there's the control spec array, this is slightly different from the standard SC spec, but it is explained in the help file fairly well. It contains the range of values, the type and the default setting. In this case I've st up two suitable sliders to control the bit rate and sample rate, I selected index as the type for the bit rate as this gives an integer.
The builder command takes the name of the plugin, a component subtype, basically a unique identifier for the plugin, the function to be used, the spec and the component type, in this case an audio effect unit.
All being well, when this could runs it should create a plugin in the SuperCollider_f/scaudk folder, which can then be loaded into your AU host.

Here's the final product ready rolled.
It you want to gove it a try it should be fairly self explanatory, but I can't guarantee compatabilty with all AU hosts.

1 comment:

  1. Super!
    Thanks for the class!