Cabbage Logo
Back to Cabbage Site

Csound and Unity on Android

Thanks, I’ll take a look tomorrow. Hopefully between the two of us we’ll figure it out. :wink:

This works fine for me here IF I used ftgen instead of f-statements in the score. Note I was getting some errors with MYFLT so I simply changed them to doubles. Looks like I have been doing this since I started this, so I guess it’s not an issue.

Great!
Indeed I didn’t understand fully the need of MYFLT, maybe is needed for the Android version?
I saw this in CsoundUnityBridge.cs in the Android unitypackage @ceberman sent us:

#if UNITY_EDITOR || UNITY_STANDALONE
using MYFLT = System.Double;
#elif UNITY_ANDROID
using MYFLT = System.Single;

Android doesn’t support double precision?

Ah, right, I will add that back in then! In fact, I better change all instances of double to MYFLT then.

Btw, do you know any other changes @ceberman made for Android? It would be nice to bring them into the main repo…

I just pushed through those updates, I also added you as a contributor on the main github page :wink:

I should do some diffs, but I also saw there’s a Prebuild.cs script in CsoundUnityScripts
prebuild_script.unitypackage (2.5 KB)

Thanks I’m very proud of that :partying_face:
Always wanted to do something for the Cabbage / Csound community!

I think that prebuild script is an old one, well, it’s actually from 2017, as far as I know, it’s no longer needed. The best thing would be for you to clone the current repo and see if that works on Android. If you don’t mind? Then we’ll have abetter idea of where we are at.

p.s do you mind if I change your spelling of cSound to Csound? :laughing:

Changed the spelling, I’m an old-fashioned Csound user :wink:
I’m now pulling the repo to test it!

:laughing:
Let me know how you get on with the current repo. Btw, did @ceberman include Android libs with his package? If so I wonder what version of Csound they are?

I’ll do some investigation and let you know
:male_detective:

Actually, would you mind zipping me your project folder so I can take a look? A zip would be simpler than a .package at this point. I just want to see where everything is in terms of the Android stuff. I’m just setting up the Android developer tools here too.

Just let me do some cleaning :sweat_smile:
I modified your test scene 2 (added a joystick I found online to move the player) and imported some csds that I wanted to try.
If you’re ok with that I can send it like it is now. (a bit messy)

Take your time. If you can tidy it up and simplify it, perhaps we can offer it as a sample android project?

Ok that’s better, let’s do this!
I’ll modify the 3 test scenes to be usable on android.
I’ll add a fourth scene with basic file reading.

Perfect. :wink:

I’ve pulled the repo, I’m on macos.
There’s something missing for the macos platform here:

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN 
    internal const string _dllVersion = "csound64.dll";
    internal const string _dllVersionCsUnity = "/Assets/StreamingAssets/CsoundUnityNativePlugin.dll";
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
	internal const string _dllVersion = "/Assets/StreamingAssets/CsoundLib64.framework/CsoundLib64";
#endif

[DllImport(_dllVersionCsUnity, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern void setCsoundInputSample([In] IntPtr csound, [In] Int32 pos, [In] MYFLT sample);

[DllImport(_dllVersionCsUnity, CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, BestFitMapping = false, ThrowOnUnmappableChar = true)]
internal static extern MYFLT getCsoundOutputSample([In] IntPtr csound, [In] Int32 pose);

What’s missing? I tried on osx a few weeks ago and had no problems?

#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN 
    internal const string _dllVersion = "csound64.dll";
    internal const string _dllVersionCsUnity = "/Assets/StreamingAssets/CsoundUnityNativePlugin.dll";
#elif UNITY_EDITOR_OSX || UNITY_STANDALONE_OSX
	internal const string _dllVersion = "/Assets/StreamingAssets/CsoundLib64.framework/CsoundLib64";
    //I added this line, I'm not sure this is correct    
    internal const string _dllVersionCsUnity = "/Assets/StreamingAssets/CsoundUnity.bundle";
#endif

That shouldn’t be an issue as that bundle is no longer needed. Similar to Windows, I can remove that reference to CsoundUnityNativePlugin.dll. It was a solution to a problem that no longer exists :wink: