Cabbage Logo
Back to Cabbage Site

csoundUnity noob questions

Hi friends, i`m porting my granular csd to mobile devices with Unity and csoundUnity. so far all good, kbobs, triggers, comboboxes working well. Not sure what is right i need to add to my CSD for best performance and mobile microphone input? also any tips for performance and GUI optimizations for Androids and IOS is welcome.

Not sure what i need to add to “”…

to CsOptions )))

I’m going to ping our Csound Unity export @giovannibedetti I’ve never ported any instrument to Android from Unity, so I can’t offer much in terms of advise.

Hey there!
I would start from the microphone input sample (it detects frequency and volume of input signal) to see how to grab mic input. You will soon find out that the latency is very high using Unity Microphone API as in the sample.
To have better latency you will have to write native Android and iOS code to grab mic input and send it to CsoundUnity.
Be aware that until CsoundUnity 3.5 you won’t be able to set the Sr and Kr from Csound options as they are hardcoded to AudioSettings.outputSampleRate.
Other Csound settings “should” work :slight_smile:

If real-time input is crucial, you can try bypassing Unity’s audio system and using Csound directly with the -odac option. I’ve done this before and was able to achieve the same latency within Unity as one can with Csound alone. However, it will require some additional work. To start, you’ll need to remove the -n CsOption, although I’m not entirely sure where this is set anymore. Disabling this option allows Csound to use its own audio drivers, but it also means you won’t be able to use many of CsoundUnity’s features, which are closely tied to Unity’s audio system.

Keep in mind that I’ve only done this on Windows/MacOS, not on Android. In my non-Unity work on Android, I’ve noticed that I/O latency is generally poor regardless of the audio system used. There are a few Unity packages that claim to offer really good latency, but the last time I checked, they did the same thing—bypassing Unity’s audio system and using native drivers instead.

Even if you find a very basic example that doesn’t use Csound, you’ll see mic latency sucks.

in my case dont care about mic latency , i used it only to fill buffer scenario. Iinterested in any possible tricks to optimize and smoosify performance.

Good day, i have another question, how to record csoundUnity output on Android… tried ftout , its ok in Unity editor but when run on phone not sure its working.

i mean fout… direct recording to file

I just tried it on Android, I guess you forgot to set the environment folders like this:

In my case I found the file under: Android/data/com.DefaultCompany.CsoundUnity_Development/files/fout_aif.aiff

This is the csd I used:

testRec.csd (464 Bytes)

About performance, you’ll have to wait for release 3.5 where you will be able to set the sample rate and control rate as you wish. This will allow you to reduce the CPU usage by decreasing the control rate (and thus increasing ksmps).
I just need to update the docs, but the release is basically ready here:

https://github.com/rorywalsh/CsoundUnity.git#release_3_5_0

Use the above link in the Unity Package Manager to import this updated version of CsoundUnity

Thanx for folder tips!! performance is fine actulay, on snapdragon phones no problem… but on mediaTek not so

looking forward for 3.5

after i add global Android path csd is not running anymore , can be permissions problem?

I don’t think so but let’s see. If you can please post the relevant parts of your csd and a screenshot of the environment settings so that we can take a look!
Do you see any Csound error in the logs? enable Csound logs like in my latest screenshot above

Yes it works, when i add only android global folder it fails, but when i add same as on your screenshot, it works. btw i can use other folder aswell? like Emulated/0/Music

and what is the Suffix tab?

ok got it, suffix fo custom folder, trying)

1 Like

even when live sound is with slight crackling noises on MedaTek, recorded file is clean.