Cabbage Logo
Back to Cabbage Site

Csound and Unity on Android

Hi Rory,

I was wondering if you have tried anything recently to get CsoundUnity working on Android. I spent a long time today trying to find the source of the crash but without any errors in the logs it’s hard to figure out. I’m trying to figure out ways of debugging it (already trying with Android Studio). It is odd that it seems that CsoundUnityBridge is successfully instantiated (so the native CsoundCreate is also successful) and it also is successful compiling the CSD file but then Unity seems to crash after the initialization pass. I disabled audio processing (OnAudioFilterRead) but still the crash happens. I’ve also tried with the latest libcsound.so, libc++ and libsndfile from GitHub but it doesn’t make a difference.

Cheers,

Hector

I’m afraid I haven’t gone near it since. How you been able to confirm that the recent Csound Android libraries work Ok? I’m not sure how many people are using them, and I’ve seen reports on the mailing list about issues. I think we’d need to create an vanilla android app using the current Csound libraries just to make sure they work Ok.

I’ve more of less moved away from Unity/Unreal in favour of web based game engines such as BabylonJS and Phaser3. I use them with the csound-wasm build and they work fine and I can run them on any platform that supports a browser.

I was speaking with Steven Yi yesterday and he was talking about producing a more game engine friendly version of the Csound Android package, but I’m not sure what kind of time frame he was talking about.

Thanks Rory,

A game engine friendly version of Csound sounds great! I think it will fill a gap in that area since so far there are no mobile procedural audio synthesis and processing plugins that are publicly available, maintained and easy to integrate into Unity or Unreal. I’m mostly interested in my students using it for mobile interactive projects (including AR/VR) and for my own personal artistic work.

I’m going to try the AAR library package route now. I’ll first test the package with a vanilla Android app and then try to integrate it into a Unity project. After some more debugging with Android Studio I suspect what is happening is that the native allocation of the csound object is clashing with Unity and corrupting the memory. This might explain why the crashes often happen at different places each time without any error messages and they are all invalid access related. Hopefully doing it from an AAR library using the Java API will solve this.

Cheers,

Hector

Let me know how it works out for you. The lack of support on Android for Csound with Unity is one of the reasons I’ve stopped using Unity.

Some bad news. I built an AAR and just by instantiating Csound() from the Java API caused Unity to crash. It didn’t crash right away but about half minute it always crashes with the same illegal access error. There most be some low level clashes going on.

That’s too bad. There must be a conflict somewhere. Steven Yi is pretty good with android stuff. Might be worth reaching out to him?

Yes, I just posted on the Csound list asking him and anyone else for any ideas. We’ll see!

Hi, I am going to take a look at this myself, with the target of Android/Unity/Oculus Go or Quest, and I had a few questions for both of you if you don’t mind

  1. What version of csound are you using?
  2. What csound binaries and headers are you using? Files that are downloaded, ie Csound6.apk? or are you building your own?
  3. If you’re building your own csound binaries, are you doing it on mac, Linux, windows, Linux-on-windows?
  4. Same question for the CsoundUnity binary libraries: mac, Linux, windows, Linux-on-windows, etc?

Thanks very much for your work so far

PS: I am looking at a csound6.12.0-Android directory that is mentioned in the FLOSS manual with documentation dated 10/24/2018.

As far as I know @virtualHC he’s this working. Hopefully he can advise on how best to get going with it. Or perhaps provide some packages :+1:

1 Like

That would be awesome on either count.

Has anyone had issues with intonation on CsoundUnity Android? I’m using Hector’s CsoundUnity for Android, (and first of all thanks again very much for the port).

I’ve found that in order for the tuning to be correct, i need to set sr=96000 in the csd files, or else the tonality is way lower than it should be (over an octave too low at sr=48000). However, sfinstr (soundfont2) plays notes increasingly out of tune as they get farther from middle C (or midi 60) both higher and lower.

I have two questions about this,

  1. does the 96000 make sense to you, or is there some adjustment i should make somewhere in CsoundUnity to change how it handles Update() and samples? [BTW, I have noticed that CsoundUnity will actually have different intonation to using different sr rates than CsoundQT which is not affected.]
  2. I suppose I could experiment with the sfinstr arguments iflag/xfreq to correct the cycles, but that would really make me responsible for all the cps mappings myself, which would not be ideal

Thanks very much in advance!!

I’m pinging @virtualHC here to see if he has any ideas. I’ve never used CsoundUnity on Android so I can’t really say.

Do you mean when running in the Unity editor? @billalves reported an issue some time ago about how changing the ksmps also had an effect on the sample playback, I believe he might have also been using the sf stuff, but he was just using desktop Unity. However, I couldn’t reproduce the issue. Maybe you can throw together a very simple package for me with the sf’s included and I can try here?

I can confirm that I found that the pitch and timing of the csd playback in Unity depended both on sr and kr. I can’t find our earlier email exchange about it, but I was using desktop Unity editors on both Mac and Windows. I was not using soundfonts but established that the problem was consistently there with a simple oscil to test the pitch. By trial and error, I found that the csd played back correctly when sr = 44100 and ksmps = 16.

Hi and thanks very much for getting back. No, this is not related to the editor, currently there is no way to use the editor on android.

On Unity/android in general (Oculus Quest specifically), the app only runs on a build (an .apk file created through Gradle) that is copied onto the device using the adb command). This behavior is specific to the CsoundUnity on android.

Let me do two things and I’ll get back to you

  1. I didn’t try playing with the ksamps parameter…let me try it at 16, and if that doesn’t work then
    2.i will put together Android sample code and post it. (This is a little more involved because there are quite a few Unity settings and programs that are specific to android, and the build file is different depending on device) so i would want to check with you what format/device would be best

Hold off creating the android version as I won’t be able to test it. But what I was asking if whether these problems persist on the the desktop version of CsoundUnity, or is it ONLY on Android?

Only on Android. I also sent an email to Hector to ask him what sr and ksamps settings he was using

Ok. I couldn’t recreate the issues Bill was having, but I suspect it might be because I was using a newer version of Unity. Let us know if you are able to solve the issue.

hello, I’d like to try CsoundUnity for Android, where can I find it? I’m glad this thread is alive!

I think the only package that exists for Android is one that @virtualHC put together for his own projects. Perhaps you can reach out to him and ask? Or maybe @ceberman can share the one he has, if Hector does not mind.