[chuck-users] instrument in function - good idea, or?

Robert Poor rdpoor at gmail.com
Thu Oct 8 21:42:49 EDT 2009


Hey Kas:

After an experiment, I must take slight exception to one thing you said:

2009/10/8 Kassen <signal.automatique at gmail.com>

> ...When the shred a UGen was defined in exits the UGen will be disconnected
> from anything it connected to (I'm not sure everything that connects to the
> Ugen on the other end will also be disconected but that doesn't matter much
> here). Because of this the DAC will no longer poll it for new samples so it
> won't take any CPU anymore. This, in adition to calculation order, is the
> big advantage of the "pull through" model we use for the UGens.
>

Here's a simple program that defines a SinOsc and plays it in its own
shred.  After 3.5 seconds, the shred is killed (and we know that it has
exited since its heartbeat / printing stops), yet the sound plays on.
=============
fun void playit() {
    SinOsc s => dac;
    while (true) {
    <<< now / 1::second, "playing..." >>>;
    1::second => now;
    }
}

spork ~ playit() @=> Shred @ _player;
3.5::second => now;
<<< now / 1::second, "terminating shred..." >>>;
_player.exit();
<<< now / 1::second, "waiting before exiting" >>>;
7.5::second => now;
<<< now / 1::second, "exiting!" >>>;
============
produces
bash-3.2$ chuck ~/Projects/Chuck/Tests/shred_exit.ck
0.000000 playing...
1.000000 playing...
2.000000 playing...
3.000000 playing...
3.500000 terminating shred...
3.500000 waiting before exiting
4.000000 playing...
11.000000 exiting!
===========
[Digression: why the heck does playit() print out "4.00 playing..." when it
was terminated at t=3.5? That may be because an exit() doesn't take effect
until the next time a shred blocks.  If so, that would be a nice thing to
document.]

I think what you meant was "When the shred a UGen was defined in exits
*NORMALLY* the UGen will be disconnected from anything it connected to..."
To test that, we simply let the player shred exit (without unchucking the
dac):
===========
fun void playit() {
    SinOsc s => dac;
    <<< now / 1::second, "playit playing" >>>;
    1::second => now;
    <<< now / 1::second, "playit exiting" >>>;
}

spork ~ playit();
7.5::second => now;
<<< now / 1::second, "finished" >>>;
===========
And yep, sure enough, the sound stops after 1 second.

So the moral of the story: if you terminate a shred via exit(), it does NOT
get the benefit of a standard shred clean-up.

Perhaps "cleanup of a terminated shred" should be added to the
someday-nice-to-have wish list.

Cheers,

- Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.cs.princeton.edu/pipermail/chuck-users/attachments/20091008/0e8adac4/attachment.html>


More information about the chuck-users mailing list