Showing posts with label Synthdef. Show all posts
Showing posts with label Synthdef. Show all posts

Thursday, March 19, 2009

Some Birthday Code

It's was my birthday recently and I was lucky enough to  get this birthday code from my old friend and Finchley's premier SuperCollidist, Dan. 

I was going to post the code on here, but it's pretty long and I can't get it to format nicely at the moment, so you'll have to make do with the .scd file in the link above. 

Happy Birthday to me.  

Monday, February 9, 2009

Moooog

Last post I showed of my wonderfully entertaining Moog style synth. This time I'm going to go into some of it in  more detail. 

Envelopes have troubled me for a while and mental images of stationary have not helped me understand what they do.  After much study I have learned they are in fact structures that control a particular aspect of a sound over time, usually the amplitude or volume, but also filters and effects.

I use two in this synth, one to control the amplitude of the oscillators and one to control the filter.  

(
SynthDef("Moog",{

arg oscType =0, oscType2 = 1, pan = 0, level = 0.5, cutoff = 500, gain = 3.3, attack = 0.1, decay = 0.1, sust = 0.7, rel = 0.2, attackf = 0.1, decayf = 0.1, sustf = 0.9, relf = 0.2, gate = 1, freq =440;


var oscArray = [Saw.ar(freq ), SinOsc.ar(freq), Pulse.ar(freq)];
var oscArray2 = [Saw.ar(freq), SinOsc.ar(freq), Pulse.ar(freq)];
var ampEnv = EnvGen.ar(Env.adsr(attack, decay, sust, rel), gate, doneAction:2);
var filterEnv = EnvGen.ar(Env.adsr(attackf, decayf, sustf, relf), gate, doneAction:2);
var osc1 = Select.ar(oscType, oscArray);
var osc2 = Select.ar(oscType2, oscArray2);
var fade = XFade2.ar(osc1, osc2, pan , level * ampEnv);
var filter = MoogFF.ar(fade, cutoff * filterEnv, gain);
Out.ar(0,filter)

}).store
)

This here is the SynthDef.  I've created two arrays of oscillators which are selected by the arg osc type being passed to the Select ugen. 

The envelopes are created by these two lines, 

var ampEnv = EnvGen.ar(Env.adsr(attack, decay, sust, rel), gate, doneAction:2);
var filterEnv = EnvGen.ar(Env.adsr(attackf, decayf, sustf, relf), gate, doneAction:2);

I create a new envelope generator object and pass it an adsr (attack, decay, sustain release) evelope specification. The variables attack, decay, sustain and release contain the time in seconds.

var fade = XFade2.ar(osc1, osc2, pan , level * ampEnv);
var filter = MoogFF.ar(fade, cutoff * filterEnv, gain);

Here I times the output of the evnvelopes by the level of the cross fade and the cuttoff frequency of the moog filter giving me a output which is changed over time by the envelope. 

Saturday, February 7, 2009

Moog Thing

This is a blog about SuperCollider.

Whilst supercollider isn't my first language, I'm not a hugely experienced programmer, so this is going to be very much from a newbies perspective.

Lets start at the beginning.

This is the first real SuperCollider program that I managed to get working, very closely aided by my mate Dan who is very good at Supercollider indeed.


(
SynthDef("Moog",{

arg oscType =0, oscType2 = 1, pan = 0, level = 0.5, cutoff = 500, gain = 3.3, attack = 0.1, decay = 0.1, sust = 0.7, rel = 0.2, attackf = 0.1, decayf = 0.1, sustf = 0.9, relf = 0.2, gate = 1, freq =440;


var oscArray = [Saw.ar(freq ), SinOsc.ar(freq), Pulse.ar(freq)];
var oscArray2 = [Saw.ar(freq), SinOsc.ar(freq), Pulse.ar(freq)];
var ampEnv = EnvGen.ar(Env.adsr(attack, decay, sust, rel), gate, doneAction:2);
var filterEnv = EnvGen.ar(Env.adsr(attackf, decayf, sustf, relf), gate, doneAction:2);
var osc1 = Select.ar(oscType, oscArray);
var osc2 = Select.ar(oscType2, oscArray2);
var fade = XFade2.ar(osc1, osc2, pan , level * ampEnv);
var filter = MoogFF.ar(fade, cutoff * filterEnv, gain);
Out.ar(0,filter)

}).store
)

it's a synth. A simple Moog inspired thing, with two oscillators, which can be either saw, sin or square/pulse waves and a mixer to mix them. It's also got a filter and two envelopes, one controlling the filter and one controlling the amplitude.

here's a pattern to play it with.

(
Pbind(
\instrument, "Moog",
\freq, Pseq([440, 550, 660, 770, 660, 330, 880], inf),
\dur, Pseq([0.2, 0.4, 0.1, 0.2, 0.2], inf),
\oscType, Pseq([0,0,0,0,0], inf),
\oscType2, Pseq([0,0,2,2,1], inf),
\cutoff, Pseq([100,599,1000,20,800], inf),
\pan, Pseq([1], inf)

).play
)


I'll go into more details of it's workings later...