Cabbage Logo
Back to Cabbage Site

Panning from Csound, relationship to AudioSource in Unity

Can I just copy the script and streaming assets folders into the old stuff?

You can just import the entire package. It should be fine. Make a copy first though.

Ok, that worked fine. The original Unity package that Iā€™d used contained 3 example scene levels (which ran fine) but the new one doesnā€™t, thanks! much easier to import.

The link I originally used was from your CsoundUnity page. Inspecting the link gives me:

CsoundUnity for OSX

Version 2.0!

Yikes. Iā€™ve updated now!

Ok, one more question. I was trying to get a smoother realtime update on panning and changed ksmps from 32 to 16. It completely changed my pitch to a screaming high pitch. I wonder why.

Iā€™m not sure. 32 is pretty smaller though. Have you set your audio settings in Unity to be at best performance?

Not sure how to do this. Iā€™m using the standard 44100, -B is 2048 and -b is 512 in Csound

hey Tom - the settings for Unity are in Project Settings>Audio. you can set the sample rate and latency performance in the Inspector.

Thanks Scott! So what is optimal?

Select Best Performance. That usually does the trick for me, with ksmps set to 32.

interesting, Rory. iā€™ve usually found that Best Latency is what works, but that was for folks using Unity internally. perhaps itā€™s different for streaming/OnAudioFilterRead functions.

Sorry, youā€™re right. Best Latency was the option I was trying to think of :smirk:

OK, just to finish up, I set the System Sample Rate to match the Csound sample rate and set the DSP Buffer Size to Best Latency. I still get the high pitched screech when ksmps is 16, so Iā€™ll stick with 32. I get little glitches occasionally, will have to investigate.

hey Rory just to mention i downloaded the package from that link and the 2D Panner from the AudioSource isnā€™t working for me at least. i also think that iā€™m not hearing panning in 3D either. i wiped the CsoundUnity Scripts and CsoundLib64framework folders before installing your update but i did not remove meta files beforehand. i am hearing distance attenuation but iā€™m not getting any kind of azimuth effect going. it just sounds like a single channel between both speakers no matter what.

I even tried the demo files and i could not get panning to happen in Unity in a clear way. also, on the PC in the same sequencer project iā€™m only getting the left channel. iā€™ll update once i try the demos on the PC.

Iā€™ll try here now with a new project and see whatā€™s going onā€¦

Sorry guys. looks like you are right. It seems I fix this bug at least once a month, although Iā€™m baffled by the current behaviour. Iā€™ll take a look and see what I can seeā€¦

This probably isnā€™t the problem, but the link on this forum page is still pointing to an older release, since I was trying to show that it was pointing to the wrong releaseā€¦ and shouldnā€™t be used.

I just downloaded the latest packages into a new project and get an error because the Player.csd is not a part of the package.
I downloaded the .zip source as well and found the Player.csd there. When I brought it into the project assets folder and played the 1st or 2nd scene I got a constant buzz sound that doesnā€™t change when the character moves.

Hi @Marco_Polo, Iā€™m just looking into this now. I download the latest release from here:


I then create a new project. I add a CsoundUnity component, edit and add the Basic.csd script to play back some sinewaves with panning:

instr PLAY_AUDIO_CLIP
a1 oscili 1, 400
a2 oscili .5, 1
outs a1*(a2+.5), a1*(1-(a2+.5))
endin  

Start my scene and I get panning. No high pitched craziness, just good old school sine waves. I fail to recreate your issue here with the high pitched sounds, but I do note that panning in Unity doesnā€™t work, although the stereo image is coming from Csound just fine. A quick search of the issue shows that there is a long standing bug in Unity that causes this problem. The guys at Heavy also have the problem:


Also check here:

What I can do is programmatically retrieve the pan position and use it to alter the gain of the left and right channels. Iā€™ll try it out and see how it works, although Iā€™m afraid we may get some artifacts in the audio when the panning is changed. Iā€™ll try it out and let you know. Unity really should look after this itself.

Iā€™m afraid this approach wonā€™t work as I donā€™t have access to that info. I can look into some of the other solutions and see whatā€™s possible. Just so weā€™re clear, we can easily pan from Csound, but not from Unityā€™s AudioSource panning controlā€¦