CsoundUnity: Where is the read output from csound actually passed to Unity's AudioSource?

Ah okay, I found a good write up on OnAudioFilterRead and get it a bit more now. So essentially you could use the same reading method as is found in ProcessBlock of CsoundUnity, but just read the output from any of csounds a-rate channels in the same way that it does from the audio output buffer designated at Csound initialization

Is there any advantage to reading from out or outs as opposed to reading with chnget performance wise? Or is outs just handier cause it can be linked on init to an audio devices output? I can test this myself, but just seeing if anyone happens to know this off the top of their head. Reason I ask is I see that GetOutputSample fetches the output with a channel number (int), wheras chnget takes a string. Probably not a huge performance difference, but I’d imagine having to parse/match a string to its corresponding channel is slightly less efficient on the backend

Hey! Sorry it took me a while to answer but I was very busy lately.
I wouldn’t say it’s an advantage in using GetChannel instead of GetOutputSample, it’s a different approach.
I consider audio channels set with chnset as aux channels, that I can pass around instruments or use with CsoundUnityChildren.
A little excursus on this:
Be aware that the current implementation that offers the audio channels to be used by the children is limited, they’re parsed from the csd instead of being grabbed at compile time (read this to understand the limitation: CsoundUnity/csoundunity_child.md at e1de8be18c4bfe6a5445d29dffb0ff6eb2b90071 · rorywalsh/CsoundUnity · GitHub)
That means that like this they’re easier to be used within the Unity Editor, since we don’t need to start Csound, but also that not every channel will be detected correctly.

BUT! We have already this powerful method to list all the available channels:

This is the one to be used at runtime for more advanced usage, but you will have to create your own children since the ones we have read from the ones found when parsing the csd (they could differ!)

So the best implementation to support audio channels fully in the editor would involve compiling/starting Csound when the csd is changed, grabbing the available channels (audio, control, string) and serializing them in the CsoundUnity instance, to be displayed in the Editor inspector, and to be used later at runtime. This is doable but requires some amount of work!

1 Like

About the PR, I’m reviewing it now, I will make comments on GitHub!