Cabbage Logo
Back to Cabbage Site

CsoundUnity 3.0, "sfload: cannot open SoundFont file"

I just tested it on Windows editor and Android, and looks great. I have an API question for you about how to access to the CsoundUnity instance at runtime.

In the other uses of CsoundUnity, there is a declared object instance in the Hierarchy at runtime that you can use for score events, etc. In this implementation, the CsoundUnity instance is only created after initialization as a clone. How do you think that other c# classes should have access to it? I thought of a few options, but you may have better ideas

  • provide an access method for Initializer._csoundUnityInstance (it’s private right now)
  • add a public instance variable to Initializer that holds the CsoundUnity instance
  • make Initializer._csoundUnityInstance protected and have developers subclass it and provide their own method

All the three options are good!
The initializer can be customized of course, for example you could want to do other things before instantiating the CsoundUnity prefab.
It is meant to be a proof of concept :wink:
But yes I got your point, after initializing things you’d want to do something with Csound :sweat_smile:
I will add a public accessor!

Thanks, and sorry for the two replies, I am still not getting the ability to edit the environment variables, either in the prefab or the clone, and I’m not sure the LocalLow is the best option

Click the little arrow on the left of Environment Settings!

Ah, sorry, you said that before :slight_smile:

1 Like

Hey @giovannibedetti Reponding to an old post I know, but I’m a bit stuck. I’ve successfully copied your code example above to play correctly in editor [Unity 2022.3.11] and in a PC build, but I’m having a hard time getting it to play back on Android. Specifically I hear no sound but can see no errors in Logcat.

I’ve made slight adjustments (substituting my own sf2 sound bank, and changing the location for copying the sf2 Text Asset directly to the root of Persistent Data Path - it seems to look for the bank there rather than in /CsoundFiles), but as mentioned it’s working fine in editor and in a PC build.

I was suspecting a pathing issue for Android specifically, but actually it looks like it’s loading the sf2 file correcly. Logcat shows lines like these enumerating the patches in the bank:

I’ve double-checked that there’s nothing amiss with my export settings from Unity by exporting the Simple Test in the same Unity scene and it plays back fine on Android.

For your reference, this is with CsoundUnity 3.4.1 and my global environment variables look like this:

That’s strange, if you have those logs it means that the SF file is loaded correctly so all is good. Are you sure the instruments are being triggered? How are you triggering them?

I tried triggering with score events as in the example above:
image
As well as through code like this:


Both approaches work in the editor and in a windows build, but produce no sound on Android.
I’m attaching a logcat log with the whole sequence from startup to quitting the app in case you’re able to spot anything amiss in the initialization.
SF2_Test_Logcat.txt (35.7 KB)

Nothing clearly wrong in the logs, this is suspicious though:

2023-11-01 11:20:30.068 587-599/? W/gralloc4: Unable to set buffer name SurfaceView[com.LyraVR.SF2Test/com.unity3d.player.UnityPlayerActivity]#1(BLAST Consumer)1: File name too long

It seems to be related with an encrypted home directory. Not sure if this is the real issue though.
Does the SF file found in the Environment Vars sample produce sound on Android?
What I can see from the logs is that your SF is loaded correctly, and real time events are triggered, but their volume is zero. So maybe try setting 0dbfs to 1 if it’s not there in the csd.
Feel free to post your csd and SF file so that I can try them here.

Ahh, I totally missed the Environment Vars sample in the package! The scene in that example builds and plays just fine on Android. It may well be an issue with sf2 file I’m using. I’ll report back if I found out what the issue was. Either way, now that I have a working example, I’m unstuck ;^) Thanks for your help!

2 Likes

Great!
Maybe your SF file only needs a bigger volume to produce sound, it could have a different amplitude scale? I’m not sure about this, but be sure to keep your headphones volume low when trying with big values :smiley:

1 Like