[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [sc-users] Triggering a function with Impulse: wrong approach?



This is one of those things that may work best either way... think something like this could be done like this one the server side:

s.boot;

a = Buffer.read(s, "sounds/a11wlk01.wav")

SynthDef(\slice, {arg buffer, slices, time = 0.13;
	var trig, slice, seglen, point, play;
	// the trigger
	trig = Impulse.kr(time.reciprocal);
// grab a random number between 0 and slices - 1 to decide where to start playback
	slice = TIRand.kr(0, slices-1, trig);
	// calculate the number of frames per slice
	seglen = BufFrames.kr(buffer) / slices;
// the time pointer. Sweep resets to 0 with every trigger, and is offset by the new slice startpoint
	point = Sweep.ar(trig, BufSampleRate.kr(buffer)) + (slice * seglen);
	// the buf rd
	play = BufRd.ar(1, buffer, point);
	Out.ar(0, play.dup)
	}).load(s)
	
z = Synth(\slice, [\buffer, a, \slices, 6, \time, 0.1]);

z.free;

If you want syncing, you could even use a synthdef just for sending out trigger signals that all the others could read. Either way, I think there are a couple UGens in the above example that may make what you are trying to do easier if you want to control things on the Server side:

Sweep - like line, but you can retrigger it easily, and even vary it's slope. TIRand - grab a new integer on each trigger. There are a number of Trigger based UGens, as well as UGens that produce a new value on Demand. Check out the Demand helpfile.

Also, if you are interested in doing more on the lang side with more syncing, triggering on the server side can also help. Take a look at the OSCresponder and OSCresponderNode helpfiles. But your worry about lang side clocks shouldn't really be much of a concern. They are pretty accurate, and TempoClock adds in the ability to change tempo.

Hope that helps.

Josh

On Oct 24, 2007, at 2:26 PM, Batuhan Bozkurt wrote:

Hello,

This is my first message in list and I'm new at SuperCollider too. I'm trying to get the knack of the approach SC introduces, and it is giving me hard time. I'm trying to "unlearn" some stuff as I'm a pretty experienced PD user, and I'm slowly learning that "bang" driven(triggered) structures jsut don't cut it in SC. It's a new approach for me and I'm asking for your help.

What I'm trying to do is essentially building a loop slicer and randomiser mostly to get used to SC. The basic structure should be: Load a sound into buffer(which should be a loop), give the number of slices to the program and let the code play the slices randomly (logic will be applied later) as a start. My approach for this is: Get the length of sound in buffer, divide that number with number of slices to get the length of one slice, then drive a BufRd with some sort of Line so if I want to play the 5th slice, "Line" would ramp through (5 * slicelength) to (6 * slicelength). And when the ramp "ends" I want to retrigger the synth to get a new random number and play that slice. Easy as that. I've actually built it and it is working as is but I don't think I'm approaching the issue in a right way. Here is the code: ////////////////////////////////////////////////////////////////////// /
~thisPath = PathName.new( Document.current.path ).pathOnly;
s.sendMsg("/b_allocRead", 0, ~thisPath ++ "loop.wav");

(
SynthDef("masher",{
var bufPlay, sliceLen = BufFrames.kr(0)/128, sliceDur = sliceLen/ BufSampleRate.kr(0), randSlice = Rand(0,128).round(1); bufPlay = BufRd.ar(1,0,Line.ar(randSlice*sliceLen, (randSlice*sliceLen)+sliceLen, sliceLen/BufSampleRate.kr(0), 1, 0, 2));
   Out.ar([0,1], bufPlay);
}).send(s);

)


r = Routine { loop {
   m = Synth.new("masher");
(0.13).yield } //0.13 is hardcoded here but should be equal to sliceLen
}.play;

////////////////////////////////////////////////////////////////////// //

This way seems to work fine but a new synth is created for each slice(but they are freed by doneAction) but I want to have a one synth running, so I want to retrigger the function inside synthdef with that instance staying on server as it looks more convenient for this case but maybe I'm heading the wrong way. The other problem is; I'm not sure if Routine-loop combos are meant for this kind of control. Controlling iterations with "wait x seconds" way seemed a bit awkward to me. And this approach is unsyncable to outside sources, even to other runing synths.

I'm not really asking help about my code as I'm using it to demonstrate my humble approch in my first steps in SC(it's been 3 full days of work now). But I think experienced people can see what I am going through so they may lead me to the right direction.

I think I should dig for TempoClock for sync issues and retriggering stuff right? What about using them in SynthDefs? Is this the wrong approach for doing things?

Any help is appreciated.

BB.
_______________________________________________
sc-users mailing list
sc-users@xxxxxxxxxxxxxxx
http://www.create.ucsb.edu/mailman/listinfo/sc-users

******************************************
/* Joshua D. Parmenter
http://www.realizedsound.net/josh/

“Every composer – at all times and in all cases – gives his own interpretation of how modern society is structured: whether actively or passively, consciously or unconsciously, he makes choices in this regard. He may be conservative or he may subject himself to continual renewal; or he may strive for a revolutionary, historical or social palingenesis." - Luigi Nono
*/