Cabbage Logo
Back to Cabbage Site

Relation between Unity calls and K-values in Csound

I am curious about how calls to Csound are handled. For example, if I send multiple channel updates in Update() loops on objects in Unity to Csound, how are they processed? Is there a queue, is it possible to flood Csound somehow? What is the relationship between ksmps and channel values sent from Unity, timing wise? Is there a recommended rate at which to send new values to Csound? Thanks for any info.

As you might already be aware, Csound process audio samples in ksmps blocks. On each block it updates all k-rate variables once. If you send channels messages to Csound they will be processed as soon as the next blocks of samples is processed. All k-rate channel variables will be updated on this boundaries, one after another until they are processed. I imagine it would be very hard to flood Csound with messages this way considering it was deigned to work like this.

Timing in Unity is completely independent from Csound. If you just need to trigger sound events from collisions and such then you can simply send a score event from your collision methods. But if you wish to sequencer some music, I avoid trying to do so with Unity’s Update() method. Although it will be called once every frame, the numbers of frames per second can change depending on lots of factors. I were making some kind of interactive generative music machines I would use Csound to sequencer everything. I posted a simple example of this in a previous thread on building a sequencer with Unity. It’s worth a read as it covers quite a bit of what we’re talking about here.