[Csnd] Check if ftable is in use
Date | 2020-07-18 18:03 |
From | Syl Morrison |
Subject | [Csnd] Check if ftable is in use |
Hi all, I'm using FTFree to deallocate ftables on an external event (dropdown callback in Unity for example), but when switching tables, obviously I get horrific glitches if its still being read from. Does anyone have any ideas when it comes to waiting until the end of a note to deallocate the ftable? (I'd rather not use temporary ones, as I've written a sampler based around the SFZ format, so ideally all the associated samples stay in ram until the caller requests a change in SFZ!
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here
|
Date | 2020-07-18 19:06 |
From | Jana Hübenthal |
Subject | Re: [Csnd] Check if ftable is in use |
Hi Syl, there are two approaches which come into my mind spontaneously: [1] Keep a global reference counter for any of your tables. Anytime an instrument using your table starts, increment it. Anytime an instrument using your table stops, decrement it. If the reference counter gets zeo, there are no more users and you can deallocate it. That's the usual way "garbage collection" works. Maybe a bit tricky to implement, especially to detect the "real" end of an instrument. There was a discussion about that just a few weeks ago. Can't remenber the exact topic, but is was how to get the very last k-cycle of an instrument.
[2] The way I would prefer, would be a timeout approach. Again, you need a global variable for each table to be supervised. So, define it in global instrument space, like gktable42used init 0 In any instrument using the table in question, set this variable
to a value above zero, for example 1000: instr 123
Then you need a supervisor instrument, continuously running: instr 9999 The nice thing with this: counting down that "in use"-counter
leads to a delay before actually freeing the table. If any
instrument decides to reuse the table during that period, it is
still in memory an does not get deallocated, as the counting down
is cancelled immediately. Beware, you need to implement this for any table you use, which could be a pain! This is not real, tested code! Just take my ideas an a pointer
for further studies... Best,
Am 18.07.20 um 19:03 schrieb Syl
Morrison:
|
Date | 2020-07-18 19:09 |
From | Syl Morrison |
Subject | Re: [Csnd] Check if ftable is in use |
The second approach sounds really handy, will try that, what I just tried was copying to a temp ftable on note start but still sounding pretty bad, thanks so much! Using the above approach but in opcode form could actually be quite useful as well (especially seeing as when a new ftable gets allocated I'm holding a handle for it in c++ already! On Sat, Jul 18, 2020 at 7:06 PM Jana Hübenthal <jana@ebene11.de> wrote:
|