Hello all- I have been doing some granular synthesis in ChucK and I am trying to create overlapping grains without having resort to arrays of Ugens or similar methods to create polyphony. Although I have seen this technique used often, the following seems to eat up memory rather quickly (due to continuously sporking the SndBuf no doubt). //BEGIN CODE --> //use your own file here... Std.getenv("SSDIR")+"/"+"Percussion"+"/"+"snare.wav" => string filename; fun void voice(){ SndBuf s => Envelope e => dac; filename => s.read; .5 => s.gain; s.pos(Std.rand2(0, s.samples())); 5::ms => e.duration; e.keyOn(); 45::ms => now; e.keyOff(); 5::ms => now; } //spork away and make lots of overlapping SndBufs while (15::ms => now){ spork ~ voice(); } //<--END CODE I guess I am wondering if there is a way to release Ugen references or do I need to wait for garbage collection to liberally spork Ugens? I have looked over these threads... garbage collection: https://lists.cs.princeton.edu/pipermail/chuck-users/2009-March/003978.html https://lists.cs.princeton.edu/pipermail/chuck-users/2009-July/004473.html granular: https://lists.cs.princeton.edu/pipermail/chuck-users/2008-May/002917.html ...and they seem to indicate that i should declare a finite number of Ugens and juggle them somehow (not as cool as my RAM hungry example). The ability release unreferenced Ugens would facilitate the easy polyphony one gets when using Csound and really make ChucK awesomer (fingers crossed). Thanks ahead of time for any input. Kurt
kurt
I guess I am wondering if there is a way to release Ugen references or do I need to wait for garbage collection to liberally spork Ugens?
I think you can assign "null" to objects to have them garbage collected forcefully but I'm not sure there. However in this particular case there is a easy way out. Since you are dealing with linear envelope segments and sample-based grains LiSa will suit your needs perfectly (see /examples/special for docs and tutorials). LiSa will contain a single buffer for you that can be played back multiple times at various rates with per-voice start, loop and so on settings. It will handle most voice cycling for you. For a more general case there are questions here. I think grains are a especially interesting case for resource cycling as we will likely be doing rather a lot of that in the case of grains. Off list i talked with Mike (probably our residential expert on using grains in ChucK) about proposing a sensible way for using non-linear envelopes with LiSa however neither of us could come up with a coherent approach. Perhaps somebody else has ideas; the exact volume envelope of grains matters a lot for the resulting spectrum. There are, BTW, no free rides here. For voices or grains (and assuming finite computational power) we will need to somehow cycle resources. This is unavoidable. The question is how much of that should be build in and how much we will need to do ourselves. I don't think all of this can be build into ChucK without sacrificing versatility and so I don't think that arrays with some infrastructure need be such a bad option here. It may be laborious but it also forces us to contemplate in depth what we need and gives us power to specify that in a very precise way. Yours, Kas.
I would definitely use events here instead of sporking:
Instead of this:
fun void voice(){
...
}
while (15::ms => now){
spork ~ voice();
}
do this:
Event voiceEvent;
fun void voicePlayer() {
while (true) {
voiceEvent => now;
...
}
}
while (15::ms => now){
voiceEvent.signal();
}
Besides losing any overhead that sporking causes, it also makes it a bit
easier to manage variables - this way you can keep the SndBuf in the the
voidePlayer function, before the while loop starts.
/Stefan
On Wed, Sep 23, 2009 at 10:39 PM, Kassen
kurt
I guess I am wondering if there is a way to release Ugen references or do I need to wait for garbage collection to liberally spork Ugens?
I think you can assign "null" to objects to have them garbage collected forcefully but I'm not sure there.
However in this particular case there is a easy way out. Since you are dealing with linear envelope segments and sample-based grains LiSa will suit your needs perfectly (see /examples/special for docs and tutorials). LiSa will contain a single buffer for you that can be played back multiple times at various rates with per-voice start, loop and so on settings. It will handle most voice cycling for you.
For a more general case there are questions here. I think grains are a especially interesting case for resource cycling as we will likely be doing rather a lot of that in the case of grains. Off list i talked with Mike (probably our residential expert on using grains in ChucK) about proposing a sensible way for using non-linear envelopes with LiSa however neither of us could come up with a coherent approach.
Perhaps somebody else has ideas; the exact volume envelope of grains matters a lot for the resulting spectrum.
There are, BTW, no free rides here. For voices or grains (and assuming finite computational power) we will need to somehow cycle resources. This is unavoidable. The question is how much of that should be build in and how much we will need to do ourselves. I don't think all of this can be build into ChucK without sacrificing versatility and so I don't think that arrays with some infrastructure need be such a bad option here. It may be laborious but it also forces us to contemplate in depth what we need and gives us power to specify that in a very precise way.
Yours, Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Release me, insect, or I will destroy the Cosmos!
Oh sorry, you also need to start up voicePlayer once. Insert:
spork ~ voicePlayer();
before the last while loop.
/Stefan
On Thu, Sep 24, 2009 at 8:41 AM, Stefan Blixt
I would definitely use events here instead of sporking:
Instead of this:
fun void voice(){ ... }
while (15::ms => now){ spork ~ voice(); }
do this:
Event voiceEvent; fun void voicePlayer() { while (true) { voiceEvent => now; ... } }
while (15::ms => now){ voiceEvent.signal(); }
Besides losing any overhead that sporking causes, it also makes it a bit easier to manage variables - this way you can keep the SndBuf in the the voidePlayer function, before the while loop starts.
/Stefan
On Wed, Sep 23, 2009 at 10:39 PM, Kassen
wrote: kurt
I guess I am wondering if there is a way to release Ugen references or do I need to wait for garbage collection to liberally spork Ugens?
I think you can assign "null" to objects to have them garbage collected forcefully but I'm not sure there.
However in this particular case there is a easy way out. Since you are dealing with linear envelope segments and sample-based grains LiSa will suit your needs perfectly (see /examples/special for docs and tutorials). LiSa will contain a single buffer for you that can be played back multiple times at various rates with per-voice start, loop and so on settings. It will handle most voice cycling for you.
For a more general case there are questions here. I think grains are a especially interesting case for resource cycling as we will likely be doing rather a lot of that in the case of grains. Off list i talked with Mike (probably our residential expert on using grains in ChucK) about proposing a sensible way for using non-linear envelopes with LiSa however neither of us could come up with a coherent approach.
Perhaps somebody else has ideas; the exact volume envelope of grains matters a lot for the resulting spectrum.
There are, BTW, no free rides here. For voices or grains (and assuming finite computational power) we will need to somehow cycle resources. This is unavoidable. The question is how much of that should be build in and how much we will need to do ourselves. I don't think all of this can be build into ChucK without sacrificing versatility and so I don't think that arrays with some infrastructure need be such a bad option here. It may be laborious but it also forces us to contemplate in depth what we need and gives us power to specify that in a very precise way.
Yours, Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Release me, insect, or I will destroy the Cosmos!
-- Release me, insect, or I will destroy the Cosmos!
But you would still need to define your maximum polyphony and declare
some sort of instrument mechanism in the sporked function, right? This
seems like how it works with the polyphony.ck example, at least
(declaring/connecting the STK Clarinet within the function). This does
circumvent the arrays issue, though, since each shred has its own
UGen. Either way, LiSa takes care of the whole thing with linear
envelopes and voice management.
Andrew
2009/9/24 Stefan Blixt
Oh sorry, you also need to start up voicePlayer once. Insert:
spork ~ voicePlayer();
before the last while loop.
/Stefan
On Thu, Sep 24, 2009 at 8:41 AM, Stefan Blixt
wrote: I would definitely use events here instead of sporking:
Instead of this:
fun void voice(){ ... }
while (15::ms => now){ spork ~ voice(); }
do this:
Event voiceEvent; fun void voicePlayer() { while (true) { voiceEvent => now; ... } }
while (15::ms => now){ voiceEvent.signal(); }
Besides losing any overhead that sporking causes, it also makes it a bit easier to manage variables - this way you can keep the SndBuf in the the voidePlayer function, before the while loop starts.
/Stefan
On Wed, Sep 23, 2009 at 10:39 PM, Kassen
wrote: kurt
I guess I am wondering if there is a way to release Ugen references or do I need to wait for garbage collection to liberally spork Ugens?
I think you can assign "null" to objects to have them garbage collected forcefully but I'm not sure there.
However in this particular case there is a easy way out. Since you are dealing with linear envelope segments and sample-based grains LiSa will suit your needs perfectly (see /examples/special for docs and tutorials). LiSa will contain a single buffer for you that can be played back multiple times at various rates with per-voice start, loop and so on settings. It will handle most voice cycling for you.
For a more general case there are questions here. I think grains are a especially interesting case for resource cycling as we will likely be doing rather a lot of that in the case of grains. Off list i talked with Mike (probably our residential expert on using grains in ChucK) about proposing a sensible way for using non-linear envelopes with LiSa however neither of us could come up with a coherent approach.
Perhaps somebody else has ideas; the exact volume envelope of grains matters a lot for the resulting spectrum.
There are, BTW, no free rides here. For voices or grains (and assuming finite computational power) we will need to somehow cycle resources. This is unavoidable. The question is how much of that should be build in and how much we will need to do ourselves. I don't think all of this can be build into ChucK without sacrificing versatility and so I don't think that arrays with some infrastructure need be such a bad option here. It may be laborious but it also forces us to contemplate in depth what we need and gives us power to specify that in a very precise way.
Yours, Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
-- Release me, insect, or I will destroy the Cosmos!
-- Release me, insect, or I will destroy the Cosmos!
_______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
Andrew;
But you would still need to define your maximum polyphony and declare some sort of instrument mechanism in the sporked function, right?
Well, if that is a issue you can always try to detect when you run out of voices and if so append to the array used or spork a new shred or whatever. Kas.
Right, clever idea. In fact, you could just have each sporked function
append its OWN object to the array. How about that? Now we just need
to learn how to destroy...
Andrew
On Thu, Sep 24, 2009 at 6:29 PM, Kassen
Andrew;
But you would still need to define your maximum polyphony and declare some sort of instrument mechanism in the sporked function, right?
Well, if that is a issue you can always try to detect when you run out of voices and if so append to the array used or spork a new shred or whatever.
Kas. _______________________________________________ chuck-users mailing list chuck-users@lists.cs.princeton.edu https://lists.cs.princeton.edu/mailman/listinfo/chuck-users
2009/9/25 Andrew C. Smith
Right, clever idea. In fact, you could just have each sporked function append its OWN object to the array. How about that?
Exactly.
Now we just need to learn how to destroy...
Not really. You just need to append when you run out of voices and otherwise recycle them. You would also need to try to make non-active voices not take cpu, of course. Detroying elements in the middle of a array doesn't seem like such a hot idea to me as that would defeat the whole purpose of having them indexed. To me that seems like a sensible middle between saving resources and making sure you can still do everything you would like (until the cpu gives up). That, of course, is just my opinion; there are many approaches and your ideas may well match the exact issues you have. kas.
participants (4)
-
Andrew C. Smith
-
Kassen
-
kurt
-
Stefan Blixt