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:

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

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…