
hi all, i'm still struggling with the basics of chuck, it seems. let's say i have a process i want to have executed regularly, like a simple click of an impulse. is it more appropriate for chuck's liking to advance time inside the impulse function and spork it only once, or to spork the impulse function regularly? volker. // begin example 1 Impulse i => dac; fun void click() { while(true) { 1.0 => i.next; 0.5::second => now; } } spork ~click(); while( true ) 1::second => now; // end example 1 // begin example 2 Impulse i => dac; fun void click() { 1.0 => i.next; } while( true ) { spork ~click(); 0.5::second => now; } // end example 2

On 10/5/06, vb
hi all, i'm still struggling with the basics of chuck, it seems.
Hi there! No problem, let's have a look at it. is it more appropriate for chuck's liking to advance time inside the
impulse function and spork it only once, or to spork the impulse function regularly? volker.
Well, both could be used and either might be apropriate depending on the situation. I didn't try actually running either example but both look fine to me. I'd say that for just this simple thing example 1 would be best because it's most simple and probably cheaper on the cpu. The second form could also be more simple since it's not actually nesicary for two shreds to run at the same time you could simply call "click()" as a function instead of sporking it to it's own shred. Generally sporking shreds is used to have several things happen at the same time. Function calls without sporking (instead of copying the function's code to one or more locations) is mainly usefull for clarity, readability and keeping your files from growing realy big. If neither is needed I would't use either because they add complexity. Here I'd use; ------- Impulse i => dac; while(true) { 1.0 => i.next; 0.5::second => now; } --------- This is the most simple form; if no more is needed then I wouldn't do any more. I think you are doing well; clearly you figured out that you can have several programs that do the same thing, the one thing I could add to it is that when you have several functionally identical programs you can pick the one you like best. In those cases I myself often pick the one I find most simple to deal with unless one of them is much less heavy on the cpu. I think you'll find that the larger you programs become the more both matter; a very big program needs good structuring or you'll be lost in it next week and clearly for larger programs it's important to make sure the cpu doesn't get overworked. Of cource it's also possible to have a small program that looks simple but that still takes a lot of cpu but even then you'll benefit from keeping it all simple because then it's easier to find what bit costs so much cpu. I hope this covers at least some of your question? Do give a shout if I missed something. Yours, Kas.

hi kassen,
Well, both could be used and either might be apropriate depending on the situation.
ok, good to know.
Generally sporking shreds is used to have several things happen at the same time. Function calls without sporking (instead of copying the function's code to one or more locations) is mainly usefull for clarity, readability and keeping your files from growing realy big. If neither is needed I would't use either because they add complexity.
the simplicity in this case was only intended to have a clear example. of course you are right in that no sporking is required here. i was wondering from a more conceptual point of view, which version would be better or more appropriate for chuck. as you say, the first example might be a little simpler than the second. still the second example seems clearer to me, well at least to what i'm used to... but i was a little concerned with the fact, that the shred ids kept increasing so rapidly (calling a new shred every click) and wondered wether chuck would really like that. thanks for your explanations, i'll be back with more questions... volker.

i was wondering from a more conceptual point of view, which version would be better or more appropriate for chuck. as you say, the first example might be a little simpler than the second. still the second example seems clearer to me, well at least to what i'm used to... but i was a little concerned with the fact, that the shred ids kept increasing so rapidly (calling a new shred every click) and wondered wether chuck would really like that.
Ah, I see. I never looked at it that way, call me heartless but I kinda figured that as long as there are no hickups and glitches ChucK would be quite happy. Maybe it's a bit tyranical but when I would like something and ChucK doesn't seem to like it I tend to mail Ge and ask Ge to make ChucK like it better. It's not quite a relationship between equals but maybe ChucK is still a bit too young and immature to commit to that sort of relationship ;-) I myself don't realy like shred numbers to go up that high either, no idea why but I tend to avoid that it should be fine. At least here it's easy to avoid, for more complicated examples you could considder looking into "signaling" events and recyceling shreds that way. thanks for your explanations, i'll be back with more questions...
volker.
Cool. Sorry if I underestimated what you were aiming at. Kas.

Sorry if I underestimated what you were aiming at. hehe, my aim is to understand chuck...:)
so here comes another simplified situation: i have a little function that's, supposed to play a Sine tone. as function arguments i pass the freq and the duration to play. now i want to call this function *regularly*, let's say every second. depending on the note duration, i want to have overlaying notes. one could say i have a "global" time, scheduling an action every second and i have a "local" time, the duration of the note. i would like to find out how to handle this situation generally in chuck. here is an example i have come up with, sporking the function, which works nice. just would like to know if that's the way to go, or wether there are simpler/better ways to do it. thanks for any comments. volker. // my lame example: Gain g => dac; fun void playNote(float freq, dur duration) { SinOsc s => g; s.freq(freq); Std.rand2f(0.1, 0.8) => s.gain; duration=>now; s =< g; } while( true ) { now => time now1; spork ~ playNote(Std.rand2f(300,600), Std.rand2f(2, 8)::second); //playNote(Std.rand2f(100,1000), Std.rand2f(2, 8)); //calling the function without sporking it won't work... 1::second=>now; <<<"time interval",(now-now1)/ms>>>; }
participants (2)
-
Kassen
-
vb