Tuesday, August 15, 2006

Week3 - SuperCollider - Granular Synthesis - Update

Here's my code for week 3. It is a little weird, and still needs changes. The weird thing is that it works, but not with the sound file that I believe I am buffering. I execute the synthDef section and then the TempoClock section. Both come up without errors, but have no sound. Prior to making the synthDef error free, it would not be able to locate the sound file. Therefore, it must recognise the soundfile, but won't granulate it.

The odd part is that after executing the code, I can get the sound file from the TGrains help file to work with my code. Thus, I have not recorded it because it is unnecessary. I had intended once my code worked properly, to find/create a good sound file to be used for granular synthesis.
//IN THE SAND BOX

(
//Global Variables
~thisPath = (PathName.new(Document.current.path)).pathOnly;

//Granular Synth
SynthDef(
\GranS,

{
//Arguments
arg b = 10;

//Variables
var bufid,
bufNum,
buflen,
signal,
tRate,
trig,
dur;

//Buffer SF
bufid = Buffer.read(s, ~thisPath++"105-timpani.wav");
bufNum = bufid.bufnum;
buflen = BufDur.kr(bufNum);

//Setup
tRate = MouseY.kr(8, 120, 1);
trig = Impulse.kr(tRate);
dur = 6 / tRate;

//Signal Granulate
signal = Normalizer.ar(
TGrains.ar(2, trig, b, 1, MouseX.kr(0,BufDur.kr(b)), dur, 0, 0.1, 2), 0.5);

//Output Signal
Out.ar(0, signal);
}
).send(s);
)

(~gran = Synth("GranS");

//Setup Clock
~granTempo = TempoClock.new( tempo: 1.5,
beats: 0,
seconds: Main.elapsedTime.ceil);

//Multi-Dimensional Array
~granPerf = [
Array.series(100, 50, 1), //GrainDensity, (SIZE, START, STEP)
[100, 1.1, 1.2], //GrainRate
[0.25], //GrainPosition
[0.25, 0.5, 1.2] //GrainDuration
];

//Sequence Gran
~granTempo.schedAbs(0,
{ arg beat;

//Performance Parameters
~gran.set(
\granDens, ~granPerf.at(0).at(beat%~granPerf.at(0).size).postln,
\granRate, ~granPerf.at(1).choose.postln,
\granPos, ~granPerf.at(2).at(beat%~granPerf.at(0).size).postln,
\granDur, ~granPerf.at(3).choose.postln
)
}
);
)

Here's the update of my code, which actually works the way I want it to. I changed some of my buffer code. Unfortunately, I had overlooked the most important thing, which was using a mono sound file. I used a stereo in my original attempts. I thank Martin for his valuable advice and comment.


//IN THE SAND BOX

(
//Global Variables
~thisPath = (PathName.new(Document.current.path)).pathOnly;

//Granular Synth
SynthDef(
\GranS,

{
//Arguments
arg granDens = MouseY.kr(8, 120, 1),
granRate = 1.0,
granDur = 0.2,
vol = 1;

//Variables
var bufid,
bufNum,
buflen,
signal,
tRate,
trig,
dur;

//Buffer SF
bufid = Buffer.read(s, ~thisPath++"Wonder.aiff");
bufNum = bufid.bufnum;
buflen = BufDur.kr(bufNum);

//Setup
tRate = MouseY.kr(8, 120, 1);
trig = Impulse.kr(granDens);
dur = 6 / tRate;

//Signal Granulate
signal = Normalizer.ar(
TGrains.ar(2, trig, bufNum, granRate, MouseX.kr(0, buflen), granDur, 0, 0.5, 2),
0.5);

//Output Signal
Out.ar(0, signal * vol);
}
).send(s);
)

(~gran = Synth("GranS");

//Setup Clock
~granTempo = TempoClock.new( tempo: 1.5,
beats: 0,
seconds: Main.elapsedTime.ceil);

//Multi-Dimensional Array
~granPerf = [
Array.series(100, 50, 1), //GrainDensity, (SIZE, START, STEP)
[100, 1.1, 1.2], //GrainRate
[0.25], //GrainPosition
[0.25, 0.5, 1.2] //GrainDuration
];

//Sequence Gran
~granTempo.schedAbs(0,
{ arg beat;

//Performance Parameters
~gran.set(
\granDens, ~granPerf.at(0).at(beat%~granPerf.at(0).size).postln,
\granRate, ~granPerf.at(1).choose.postln,
\granPos, ~granPerf.at(2).at(beat%~granPerf.at(0).size).postln,
\granDur, ~granPerf.at(3).choose.postln
)
}
);
)
Beware this sound file is quite loud

2 Comments:

At 8:47 pm, Blogger unknown said...

Adrian, I had a look through your code and found the following error:

The buffer that's loaded in has it's bufnum assigned to the variable bufNum but your TGrains UGEN looks like this - TGrains.ar(2, trig, b, 1, MouseX.kr(0,BufDur.kr(b)), dur, 0, 0.1, 2) - where 'b' is a variable that hasn't been initialised. Try changing it to look like this - TGrains.ar(2, trig, bufNum, 1, MouseX.kr(0, buflen), dur, 0, 0.1, 2)

Also, check that your sound file is mono, otherwise TGrains will fail silently.

Martin

 
At 7:51 pm, Blogger @*} said...

o'me o'my, are you sure your ~granperf is working? i set up my code your way intially, to no avail. when i resorted to the cmh way (specify at.position and at.array #) i got it working..still dont get modulus but, and the new oxford dictionary definition of modulus for maths-less folk such as myself is absolutely impossible! a thousand flowers for the dear soul who can explain it to me in a way that sticks.

btw, lucky you for having mv pro-coder to help you out with your patches.

 

Post a Comment

<< Home