# Panning from Csound, relationship to AudioSource in Unity

**URL:** <https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659>\
**Category:** Csound for Games\
**Created:** [10 August 2017 17:31 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659 "2017-08-10T17:31:36Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [10 August 2017 17:31 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/1 "2017-08-10T17:31:36Z")

</div>

I am having some trouble with getting the Csound opcode pan2 to work properly in Unity3D. I get good results running the patch in Csound by itself, but running it in Unity messes up the panning. I can control other things without problems from Unity (Pitch, volumes, etc.) but not pan. Is there a recommended way to set up the Audio Source parameters to allow transparency through Unity?

(As an aside, I found that using some of Unity’s audio effects through it’s mixers is MUCH more efficient than using Csound’s, probably due to summing of all sources vs. each voice running it’s own effect, provided Unity provides an alternative. This suggests porting all favorite Csound effects into Unity as plug-ins to the mixer).

Thanks for any help!

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [10 August 2017 20:01 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/2 "2017-08-10T20:01:32Z")

</div>

Are you sure you’re using the latest scripts? Grab them from github and overwrite the current ones. We fixed some channel issues a while back. I did create a CsoundUnity mixer plugin. It was just a proof of concept though, it needs more work. And maybe the unity sdk is better now. I’d need to take a look.

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [15 August 2017 22:00 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/3 "2017-08-15T22:00:32Z")

</div>

Just to be sure, I downloaded the UnityPackage from the OSX link on this website - the latest scripts are included in this package, right? Panning still doesn’t work for me, unfortunately.

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [15 August 2017 22:02 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/4 "2017-08-15T22:02:52Z")

</div>

CsoundUnity, or linked from here:  
[http://rorywalsh.github.io/CsoundUnity/docs.html](http://rorywalsh.github.io/CsoundUnity/docs.html)

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [16 August 2017 01:18 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/5 "2017-08-16T01:18:02Z")

</div>

I started a new unity project, put in one game object, added a csoundunity script and just added the file below. The sound just increases in loudness in my left ear but doesn’t pan. Based on the csound below, shouldn’t it pan, even without a unity script sending commands?

```
<Cabbage>
form caption("Test My Pan"), size(300, 200)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -m0d ; for unity
</CsOptions>
<CsInstruments>
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

giSine ftgen 0, 0, 2^10, 10, 1

instr 1

kline	line	0, p3, 1 ; straight line

ain	oscili	.6, 440, giSine ; audio signal..
aL,aR	pan2	ain, kline ; sent across image
	outs	aL, aR

endin
</CsInstruments>
<CsScore>
f0 z
f1 0 32768 10 1

i1 0 20	; pan across the stereo field for 20 seconds
</CsScore>
</CsoundSynthesizer>
```

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [16 August 2017 07:13 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/6 "2017-08-16T07:13:00Z")

</div>

Can you grab the scripts from here and replace the ones if your project with them:  
[https://github.com/rorywalsh/CsoundUnity/tree/master/CsoundUnityScripts](https://github.com/rorywalsh/CsoundUnity/tree/master/CsoundUnityScripts)

p.s. if you don’t format your code using the format code button, or Ctrl+alt+c, it doesn’t appear properly in the forum..

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [16 August 2017 18:14 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/7 "2017-08-16T18:14:51Z")

</div>

Thanks. I just overwrote the CsoundUnityScripts with these scripts and have the following error:

Assets/Scripts/CsoundUnityScripts/CsoundCsharp.cs(97,24): error CS0103: The name `\_dllVersionCsUnity’ does not exist in the current context

Do I need to refresh some other files as well?

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [16 August 2017 18:35 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/8 "2017-08-16T18:35:46Z")

</div>

Can you try replacing all the files with the one on git? I don’t think the OSX packages is up to date. Actually, forget that. Just install the usual package, then replace the CsoundUnity.cs file b with the one in git. That’s the one that fixed the issue. I’ll be able to prepare a new package for osx next week but am not in a position to do so right now…

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [16 August 2017 18:43 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/9 "2017-08-16T18:43:29Z")

</div>

I thought I replaced that one when I copied all the script files into the CsoundUnityScripts folder.  
I can’t run or test because of the error I mentioned.  
Do I need an additional DLL file?

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [20 August 2017 14:51 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/10 "2017-08-20T14:51:53Z")

</div>

Do you have the latest version of Csound installed on your machine? I will be back in the land of OSX on Wednesday, I can take a look and see what’s up.

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [21 August 2017 23:07 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/11 "2017-08-21T23:07:48Z")

</div>

I’m not sure whether the Csound used by Unity is the same as the Csound used by CsoundQT, but here’s what I have in CsoundQT:  
Using Csound version:6080 Precision:double (64-bit)

is this the latest? is it what Unity uses?  
what I see in the CsoundLib64.framework version folder is 6.0, both for libcsnd6.6.0 and libCsoundAC.6.0

If there is a discrepancy between what CsoundQT uses and Unity I assume that things are re-compiled/interpreted in the Unity Csound environment so that compatibility is a non-issue unless there were new Unity opcodes in CsounQT that were not present in the Unity libs.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [22 August 2017 09:47 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/12 "2017-08-22T09:47:20Z")

</div>

Hi Thomas, if Just tried the very latest OSX package and I’m not having any issues?

> [@Marco\_Polo](#):
>
> what I see in the CsoundLib64.framework version folder is 6.0, both for libcsnd6.6.0 and libCsoundAC.6.0

All of the current Csound6 packages are presented with 6.0, if you run Csound from the terminal you should get the version number. I’m running 6.09.

> [@Marco\_Polo](#):
>
> If there is a discrepancy between what CsoundQT uses and Unity…

Normally no as both will use the Csound runtime library. But each time the Csound API is bumped it can cause some issues with pacakges that expect to see the older library. This version of CsoundUnity comes with a precompiled native dll/.dylib that links to Csound 6.09. I had to do this to allow processing of AudioSource clips. My preference is always to avoid having any precompiled plugins and just use scripts instead, but it wasn’t possible here. It will be however once the next version of Csound is released.

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [22 August 2017 13:19 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/13 "2017-08-22T13:19:44Z")

</div>

I’m not sure what to do then, I definitely can’t pan audio properly, even using the Unity panner on a Csound source. The pan2 program I posted previously doesn’t work. I assume you are using a Mac. The CsoundUnity package I’m using I downloaded from your link on the Cabbage site. Could you send me an example Unity project that uses panning? Any help is most appreciated.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [22 August 2017 14:52 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/14 "2017-08-22T14:52:14Z")

</div>

Is this the one you’re installing?  
[https://github.com/rorywalsh/CsoundUnity/releases/download/v2.3/CsoundUnityOSX.unitypackage](https://github.com/rorywalsh/CsoundUnity/releases/download/v2.3/CsoundUnityOSX.unitypackage)

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [22 August 2017 15:07 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/15 "2017-08-22T15:07:47Z")

</div>

Thanks, I’ll check when I get back to my computer.

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [22 August 2017 16:13 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/16 "2017-08-22T16:13:27Z")

</div>

Yes!!! Downloaded the latest and pan now works! Somehow I wasn’t getting the latest before.

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [22 August 2017 16:21 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/17 "2017-08-22T16:21:14Z")

</div>

Great. But I wonder how you were managing to download the wrong package. I hope I don’t have bugs links lying around?

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [22 August 2017 16:23 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/18 "2017-08-22T16:23:07Z")

</div>

I think that I originally found this package in the Unity Store. I thought I was able to update it from your Cabbage page but I guess not…

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [22 August 2017 16:24 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/19 "2017-08-22T16:24:52Z")

</div>

I don’t think there ever was one there. Anyway, it’s all good now. You should also be able to process audio clips quite easily, and all sounds are sent through the Unity3d sound system.

---

<div class="post-metadata">

**Author:** ![Marco\_Polo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/m/b5ac83/32.png) [@Marco\_Polo](https://forum.cabbageaudio.com/u/Marco_Polo)\
**Post date:** [22 August 2017 16:25 UTC](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659/20 "2017-08-22T16:25:06Z")

</div>

Now I have to figure out how to update my earlier Unity projects without breaking something.

[Next page](https://forum.cabbageaudio.com/t/panning-from-csound-relationship-to-audiosource-in-unity/659.md?page=2)
