Monday, May 26, 2008

CC3 Week 7 - Synthesiser Definitions II


//PART ONE - CODE BORROWED FROM JOHN DELANY


(
SynthDef("IndustrialAmbience", {
arg freq = 100, rate = 0, contFreq = 100, i;
var env, osc, hit, sin, dur = 10, sinDec, envStruct, envGen;
hit = Decay2.ar(Impulse.ar(rate,0,0.3), 0.03, 0.3);
sinDec = Decay2.ar(Impulse.ar(rate,0,0.3), 0.01, 0.3);
sin = SinOsc.ar(freq: contFreq*(i+2), mul: sinDec);
osc = Klank.ar(`[Array.series(10, 50, contFreq, 50),
Array.series(10, 0.8, -0.1)], ClipNoise.ar([0.005,0.005])
);


// Envelope Structure
envStruct = Env(
levels: [0.1, 1, 0],
times: [1.0, 3.0],
curve: 'welch'
).plot;
// Envelope Instance
envGen = EnvGen.kr(
envelope: envStruct,
gate: 1.0,
doneAction: 2.0
);


Out.ar(0, osc * envGen); // Outputs to busses 0 and 1
}).send(s);
)

a = Synth("IndustrialAmbience", [\contFreq, 10000, \rate, 9]);






//PART TWO - MY SYNTH DEF



b = Buffer.read(s, "sounds/Producers @ The Electric Light Hotel.wav");

// Here is the sample for part two.



(
SynthDef("BufferPlay", {

arg speed = 1, amp = 1, pan = 0, mFreq, mAmp;

var sig, pan2, envStruct, envGen, mod, car, out;

sig = PlayBuf.ar(1, b.bufnum, BufRateScale.kr(b.bufnum) * speed, loop: 1.0);
pan2 = Pan2.ar(sig, pan);

mod = SinOsc.ar(freq: mFreq, mul: mAmp);



// Envelope Structure
envStruct = Env(
levels: [0, 1, 0.5, 0.3, 0],
times: [2.0, 1.0, 3.0, 10.0],
curve: 'lin'
).plot;
// Envelope Instance
envGen = EnvGen.kr(
envelope: envStruct,
gate: 1.0,
doneAction: 2.0
);





Out.ar(bus: 0, channelsArray: amp * pan2 * mod* envGen);

}).send(s);
)

a = Synth("BufferPlay", [\speed, 1, \pan, -1, \mFreq, 1, \mAmp, 1]);
a = Synth("BufferPlay", [\speed, 2, \pan, 1, \mFreq, 1, \mAmp, 1]);
a = Synth("BufferPlay", [\speed, 4, \pan, 0, \mFreq, 3, \mAmp, 1]);



// PART 3 - MIDI control

(
MIDIClient.init;

MIDIClient.sources;

MIDIIn.connectByUID(inport: 0, uid: MIDIClient.sources.at(0).uid);
)



(
MIDIIn.noteOn = {

arg src, chan, num, vel;

[chan,num,vel].postln;

a = Synth("BufferPlay", [\speed, 1, \pan, -1, \mFreq, 1, \mAmp, 1]);
a.set(\speed, num.linlin(0, 127, -11, 10).postln);
};
MIDIIn.noteOff = {};
)
(
MIDIIn.control = {

arg src, chan, num, val;

[src, chan,num,val].postln;

a.set(\mFreq, (val * 1.5));
};
)


// PART FOUR - Sound example of PART TWO



[1] Christian Haines. "Creative Computing: Semester 1 - Week 7 - Synthesiser Definitions II". Lecture presented at the Electronic Music Unit, University of Adelaide, South Australia, 17th April 2008

No comments: