Cabbage Logo
Back to Cabbage Site

Csound and Unity on Android

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:

Ok great!

I wanted to ask if it would be possible to add to the test suite the ability to build and run the application without a System install of Csound present (MacOS and Windows). I’ve found this to be fairly time consuming every time I have to figure it out. Specifically In regards to the line on OSX:

internal const string _dllVersion = “/Assets/StreamingAssets/CsoundLib64.framework/CsoundLib64”;

i found on OSX Mojave that in order to run a build without a system installed version of Csound that i had to remove the beginning slash, in other words:

internal const string _dllVersion = “Assets/StreamingAssets/CsoundLib64.framework/CsoundLib64”;

and make a copy by hand into the .app directory Contents/Frameworks/MonoEmbedRuntime/osx/libAssets/StreamingAssets

This is still breaking the Editor build, I’m working on that as well

Sure. Sounds like a good idea. I just pushed some new code to the master branch now that removes all the native plugins stuff as it is no longer needed. I also fixed an issue with the path that @giovannibedetti reported. Whatever changes improvements or otherwise you make, just throw them into a PR and I will merge to the main branch :wink:

Sorry i didn’t see this earlier to reply. I didn’t make any changes to the Android package from what Henry sent me. It had the csound libs embedded in a unity package, I’m not sure what version

Now I remember why I added this! When you export it will take the audio assets and place them into streamingassets too so Csound can access them…