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

**URL:** <https://forum.csound.com/t/csoundunity-where-is-the-read-output-from-csound-actually-passed-to-unitys-audiosource/725>\
**Category:** General\
**Created:** [March 26, 2022, 9:15pm UTC](https://forum.csound.com/t/csoundunity-where-is-the-read-output-from-csound-actually-passed-to-unitys-audiosource/725 "2022-03-26T21:15:49Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![DespairBear](https://forum.csound.com/user_avatar/forum.csound.com/despairbear/32/88_2.png) [@DespairBear](https://forum.csound.com/u/DespairBear)\
**Post date:** [March 31, 2022, 6:19pm UTC](https://forum.csound.com/t/csoundunity-where-is-the-read-output-from-csound-actually-passed-to-unitys-audiosource/725/22 "2022-03-31T18:19:37Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![g\_b](https://forum.csound.com/user_avatar/forum.csound.com/g_b/32/208_2.png) [@g\_b](https://forum.csound.com/u/g_b)\
**Post date:** [April 2, 2022, 11:25am UTC](https://forum.csound.com/t/csoundunity-where-is-the-read-output-from-csound-actually-passed-to-unitys-audiosource/725/23 "2022-04-02T11:25:37Z")

</div>

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](https://github.com/rorywalsh/CsoundUnity/blob/e1de8be18c4bfe6a5445d29dffb0ff6eb2b90071/Documentation~/csoundunity_child.md?plain=1#L54))  
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:

> <https://github.com/rorywalsh/CsoundUnity/blob/e1de8be18c4bfe6a5445d29dffb0ff6eb2b90071/Runtime/CsoundUnity.cs#L910>

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!

---

<div class="post-metadata">

**Author:** ![g\_b](https://forum.csound.com/user_avatar/forum.csound.com/g_b/32/208_2.png) [@g\_b](https://forum.csound.com/u/g_b)\
**Post date:** [April 2, 2022, 11:28am UTC](https://forum.csound.com/t/csoundunity-where-is-the-read-output-from-csound-actually-passed-to-unitys-audiosource/725/24 "2022-04-02T11:28:46Z")

</div>

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

[Previous page](https://forum.csound.com/t/csoundunity-where-is-the-read-output-from-csound-actually-passed-to-unitys-audiosource/725.md?page=1)
