Friday, September 05, 2008

CC3 Week 6 - Physical Modelling I


I have created a Karplus-Strong String Synthesis patch with some parameters on the GUI to control the sound. I have a drop down menu to select the timbre of the sound. This is actually changing the type of noise that is being triggered. I also have a frequency slider that obviously selects the frequency of the string. Finally I have a duration slider to select how long the notes are.

To trigger the notes simply click anywhere in the window. I have a button that covers the background so you can just click and hear the notes.

Click here for an audio example of my patch. [1.7MB]






//PINK NOISE
(
// Delayed Noise Generator - Envelope > Noise Generator > Delay
SynthDef("plucked-pink", {

// Arguments
arg midiPitch = 80, duration = 10;

// Variables
var burstEnv, noise, delay, att = 0, dec = 0.001, out,
delayTime = midiPitch.midicps.reciprocal, trigRate = 1;

// Envelope
burstEnv = EnvGen.kr(
envelope: Env.perc(att, dec)
);

// Noise Generator
noise = PinkNoise.ar(
mul: burstEnv
);

// Delay
delay = CombL.ar(
in: noise,
maxdelaytime: delayTime,
delaytime: delayTime,
decaytime: duration,
add: noise
);

// Output
Out.ar(
bus: 0,
channelsArray: delay.dup
);

}).send(s);


//WHITE NOISE

// Delayed Noise Generator - Envelope > Noise Generator > Delay
SynthDef("plucked-white", {

// Arguments
arg midiPitch = 80, duration = 10;

// Variables
var burstEnv, noise, delay, att = 0, dec = 0.001, out,
delayTime = midiPitch.midicps.reciprocal, trigRate = 1;

// Envelope
burstEnv = EnvGen.kr(
envelope: Env.perc(att, dec)
);

// Noise Generator
noise = WhiteNoise.ar(
mul: burstEnv
);

// Delay
delay = CombL.ar(
in: noise,
maxdelaytime: delayTime,
delaytime: delayTime,
decaytime: duration,
add: noise
);

// Output
Out.ar(
bus: 0,
channelsArray: delay.dup
);

}).send(s);


//BROWN NOISE

// Delayed Noise Generator - Envelope > Noise Generator > Delay
SynthDef("plucked-brown", {

// Arguments
arg midiPitch = 80, duration = 10;

// Variables
var burstEnv, noise, delay, att = 0, dec = 0.001, out,
delayTime = midiPitch.midicps.reciprocal, trigRate = 1;

// Envelope
burstEnv = EnvGen.kr(
envelope: Env.perc(att, dec)
);

// Noise Generator
noise = BrownNoise.ar(
mul: burstEnv
);

// Delay
delay = CombL.ar(
in: noise,
maxdelaytime: delayTime,
delaytime: delayTime,
decaytime: duration,
add: noise
);

// Output
Out.ar(
bus: 0,
channelsArray: delay.dup
);

}).send(s);


//CLIP NOISE

// Delayed Noise Generator - Envelope > Noise Generator > Delay
SynthDef("plucked-clip", {

// Arguments
arg midiPitch = 80, duration = 10;

// Variables
var burstEnv, noise, delay, att = 0, dec = 0.001, out,
delayTime = midiPitch.midicps.reciprocal, trigRate = 1;

// Envelope
burstEnv = EnvGen.kr(
envelope: Env.perc(att, dec)
);

// Noise Generator
noise = ClipNoise.ar(
mul: burstEnv
);

// Delay
delay = CombL.ar(
in: noise,
maxdelaytime: delayTime,
delaytime: delayTime,
decaytime: duration,
add: noise
);

// Output
Out.ar(
bus: 0,
channelsArray: delay.dup
);

}).send(s);



//GREY NOISE

// Delayed Noise Generator - Envelope > Noise Generator > Delay
SynthDef("plucked-grey", {

// Arguments
arg midiPitch = 80, duration = 10;

// Variables
var burstEnv, noise, delay, att = 0, dec = 0.001, out,
delayTime = midiPitch.midicps.reciprocal, trigRate = 1;

// Envelope
burstEnv = EnvGen.kr(
envelope: Env.perc(att, dec)
);

// Noise Generator
noise = GrayNoise.ar(
mul: burstEnv
);

// Delay
delay = CombL.ar(
in: noise,
maxdelaytime: delayTime,
delaytime: delayTime,
decaytime: duration,
add: noise
);

// Output
Out.ar(
bus: 0,
channelsArray: delay.dup
);

}).send(s);


w.close;

// WHOLE WINDOW
w = SCWindow.new.front;
w.bounds = Rect(170,150,450,280);
w.name_("Strings");
w.alpha_(0.8);


// PANEL
e = SCCompositeView(w,Rect(10,50,430,210));
e.background = Color.new255(100,0,50);
//Gradient(Color.blue,Color.black);


// TRIGGER BUTTON
f = SCButton(w, Rect(10,50,430,210))
.states_([
[" ", Color.white, Color.new255(10,0,100)]
])
.font_(Font("Arial", 10))
.action_({


~noisetype.switch(0,{Synth("plucked-pink", [\midiPitch, ~pitch, \duration, ~dur])},
1,{Synth("plucked-white", [\midiPitch, ~pitch, \duration, ~dur])},
2,{Synth("plucked-brown", [\midiPitch, ~pitch, \duration, ~dur])},
3,{Synth("plucked-clip", [\midiPitch, ~pitch, \duration, ~dur])},
4,{Synth("plucked-grey", [\midiPitch, ~pitch, \duration, ~dur])});
});


// DROP DOWN MENU
l = [
"Twang","Harsh","Warm","Tin","Nylon"];
m = SCPopUpMenu(w,Rect(10,10,150,20));
m.items = l;
m.background_(Color.new255(10,0,100));
m.stringColor_(Color.white);

m.action = { arg m;
~noisetype = m.value.postln};

//c.value=""++(slider.hi) ++"Hz";




//PITCH
c = SCTextField(w, Rect(350, 100, 50, 20));
a = SCSlider(w, Rect(40, 100, 300, 20))
.focusColor_(Color.red(alpha:0.2))
.action_({
c.value_(""++((a.value*70)+30).midicps.round(0.1)++"Hz");
~pitch = ((a.value*70)+30)
});


//DURATION
d = SCTextField(w, Rect(350, 200, 50, 20));
b = SCSlider(w, Rect(40, 200, 300, 20))
.focusColor_(Color.red(alpha:0.2))
.action_({
d.value_(""++((b.value*10)+0.1).round(0.1)++"s");
~dur = ((b.value*10)+0.1)
});




)


[1] Christian Haines. "Creative Computing: Semester 2 - Week 6 - Physical Modelling I". Lecture presented at the Electronic Music Unit, University of Adelaide, South Australia, 4th September 2008

No comments: