Hi
As far as I understand and have tested/heard, using globals and channels can undermine any multi-threading when using -j (as opposed to having self-isolated instruments).
Ideally I'd like to use multi-threading, but also globals/channels, so I thought an interesting way to get around this could be to use the API to run multiple instances of Csound and try to handle threading a bit more manually. The more I looked into this, the more it seemed like it might create other problems though.
The general idea to test is to have one Csound instance running on the main thread which uses -odac and then two other threads using -n which would just send to/receive from the instance on the main thread, and the API brokering audio between them with channels.
In each thread it roughly does something like:
do {
csoundWaitThreadLockNoTimeout(userdata->lock);
} while (csoundPerformKsmps(userdata->csound) == 0);
.. and in the main thread:
while (csoundPerformKsmps(main) == 0) {
csoundNotifyThreadLock(userdata1->lock);
csoundNotifyThreadLock(userdata2->lock);
/*
calls to csoundGetAudioChannel and csoundSetAudioChannel
using previously allocated buffers
*/
}
This does basically work, but at sr=48000, on Windows it only runs without audio dropouts with kr=12, and on Linux on the same machine, a kr about ten times that.
I'm new to multi-threading with audio, but it seems that the threadlock might not be able to wake quick enough to keep up with a higher kr (which I would like to try and achieve).
The more I've read about audio multithreading, the more I think this may be a dead end, so I'd be interested if anyone has any views and opinions.
I also considered (but haven't tried) using csoundPerformBuffer, but then while the threads may be synchronised, as the get/set audio works with ksmps, I couldn't think of any way that would help to exchange channels between the threads (perhaps audio could work with spin/spout, but k-rate channels would face the same thing).
thanks
RK
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here