FMOD Studio API Fails to Play Audio - Android C# (MAUI)

I have a very simple Andriod App in MAUI that can play audio files fine using FMODCore but when I attempt to use FMODStudio all the calls return success but no Audio is heard.

Note this is NOT a game.

I’ve check and recheck the Bank files forced failures in some of the API to ensure there were being called but still no joy.

This is my first time trying to use FMOD so I could be missing something basic

Any ideas?

Code (Yes these are abscractions)
FMODManager.Init(new AndroidNativeLibrary(), FMODMode.CoreAndStudio, “content”);
List _banks = new List();
_banks.Add(await StudioSystem.LoadBank(“Master.bank”));
_banks.Add(await StudioSystem.LoadBank(“Master.strings.bank”));
_banks.Add(await StudioSystem.LoadBank(“Vehicles.bank”));

    var _engineDescription = StudioSystem.GetEvent("event:/Vehicles/Car Engine");
    
    _engineDescription.LoadSampleData();

     _engineInstance = _engineDescription.CreateInstance();

    //// If you have any parameters set within FMOD Studio, you can change them within the code.
    _engineInstance.SetParameterValue("RPM", 1000);
    _engineInstance.SetParameterValue("Load", -1f);
    _engineInstance.Volume = 1;
    if (_engineInstance.PlaybackState == FMOD.Studio.PLAYBACK_STATE.PLAYING)
    {

        _engineInstance.Stop();
    }
    else
    {

        _engineInstance.Start();
    }

LOGS:
[AAudio] AAudioStreamBuilder_openStream() called ----------------------------------------
[AudioStreamBuilder] rate = 0, channels = 0, channelMask = 0, format = 0, sharing = SH, dir = OUTPUT
[AudioStreamBuilder] device = 0, sessionId = -1, perfMode = 12, callback: OFF with frames = 0
[AudioStreamBuilder] usage = 14, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
[AudioStreamBuilder] privacy sensitive = false, opPackageName = (null), attributionTag = (null)
[libc] Access denied finding property “sys.perf.boostopt”
[nyname.mauihack] PlayerBase::PlayerBase()
[monodroid-assembly] open_from_bundles: failed to load assembly System.Runtime.Intrinsics.dll
[libc] Access denied finding property “sys.perf.boostopt”
[AudioStreamInternal_Client] configureDataInformation() original HW burst = 96, minMicros = 2000 => SW burst = 96
[AAudioStream] setState(s#1) from 0 to 2
[AAudioFlowGraph] configure() source format = 0x00000005, channels = 2, sink format = 0x00000005, channels = 2, useMonoBlend = 0, audioBalance = 0.000000, isExclusive 0
[AAudio] AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#1 ----------------
[AAudio] AAudioStream_close(s#1) called ---------------
[AudioStreamInternal_Client] release_l(): mServiceStreamHandle = 0x0000017E
[AAudioStream] setState(s#1) from 2 to 11
Loaded assembly: /data/data/com.companyname.mauihack/files/.override/System.Runtime.Intrinsics.dll [External]
[AAudioStream] setState(s#1) from 11 to 11
[AAudioStream] setState(s#1) from 11 to 12
[AudioStreamInternal_Client] ~AudioStreamInternal() 0xb40000769420f5c0 called
[AAudioStream] ~AudioStream(s#1) mPlayerBase strongCount = 2
[AAudio] AAudioStream_close(s#1) returned 0 ---------
[fmod] FMOD::supportsLowLatency : Low latency = false, Pro Audio = false, Bluetooth On = false, Acceptable Block Size = false (0)
[AAudio] AAudioStreamBuilder_openStream() called ----------------------------------------
[AudioStreamBuilder] rate = 0, channels = 0, channelMask = 0, format = 0, sharing = SH, dir = OUTPUT
[AudioStreamBuilder] device = 0, sessionId = -1, perfMode = 12, callback: ON with frames = 0
[AudioStreamBuilder] usage = 14, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
[AudioStreamBuilder] privacy sensitive = false, opPackageName = (null), attributionTag = (null)
[nyname.mauihack] PlayerBase::PlayerBase()
[nyname.mauihack] Explicit concurrent copying GC freed 16735(1842KB) AllocSpace objects, 0(0B) LOS objects, 59% free, 4245KB/10MB, paused 25us,14us total 9.020ms
[AudioStreamInternal_Client] configureDataInformation() original HW burst = 96, minMicros = 2000 => SW burst = 96
[AAudioStream] setState(s#2) from 0 to 2
[AAudioFlowGraph] configure() source format = 0x00000005, channels = 2, sink format = 0x00000005, channels = 2, useMonoBlend = 0, audioBalance = 0.000000, isExclusive 0
[AAudio] AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#2 ----------------
[AAudio] AAudioStream_close(s#2) called ---------------
[AudioStreamInternal_Client] release_l(): mServiceStreamHandle = 0x00000180
[AAudioStream] setState(s#2) from 2 to 11
[AAudioStream] setState(s#2) from 11 to 11
[AAudioStream] setState(s#2) from 11 to 12
[AudioStreamInternal_Client] ~AudioStreamInternal() 0xb40000769420f5c0 called
[AAudioStream] ~AudioStream(s#2) mPlayerBase strongCount = 2
[AAudio] AAudioStream_close(s#2) returned 0 ---------
[AAudio] AAudioStreamBuilder_openStream() called ----------------------------------------
[AudioStreamBuilder] rate = 0, channels = 0, channelMask = 0, format = 0, sharing = SH, dir = OUTPUT
[AudioStreamBuilder] device = 0, sessionId = -1, perfMode = 12, callback: ON with frames = 0
[AudioStreamBuilder] usage = 14, contentType = 0, inputPreset = 0, allowedCapturePolicy = 0
[AudioStreamBuilder] privacy sensitive = false, opPackageName = (null), attributionTag = (null)
[nyname.mauihack] PlayerBase::PlayerBase()
[AudioStreamInternal_Client] configureDataInformation() original HW burst = 96, minMicros = 2000 => SW burst = 96
[AAudioStream] setState(s#3) from 0 to 2
[AAudioFlowGraph] configure() source format = 0x00000005, channels = 2, sink format = 0x00000005, channels = 2, useMonoBlend = 0, audioBalance = 0.000000, isExclusive 0
[AAudio] AAudioStreamBuilder_openStream() returns 0 = AAUDIO_OK for s#3 ----------------
[AAudio] AAudioStream_requestStart(s#3) called --------------
[AAudioStream] setState(s#3) from 2 to 3
[AAudio] AAudioStream_requestStart(s#3) returned 0 ---------
[AudioStreamInternalPlay_Client] callbackLoop() entering >>>>>>>>>>>>>>>
[AudioStreamInternal_Client] onEventFromServer - got AAUDIO_SERVICE_EVENT_STARTED
[AAudioStream] setState(s#3) from 3 to 4
[Choreographer] Skipped 237 frames! The application may be doing too much work on its main thread.
[OpenGLRenderer] Davey! duration=3975ms; Flags=0, FrameTimelineVsyncId=132854536, IntendedVsync=496268666292998, Vsync=496272616292840, InputEventId=971261266, HandleInputStart=496272629977923, AnimationStart=496272630367454, PerformTraversalsStart=496272630987402, DrawStart=496272631482610, FrameDeadline=496268682959664, FrameInterval=496272629589017, FrameStartTime=16602554, SyncQueued=496272632908600, SyncStart=496272633036256, IssueDrawCommandsStart=496272633196725, SwapBuffers=496272634736985, FrameCompleted=496272641710944, DequeueBufferDuration=41041, QueueBufferDuration=533437, GpuCompleted=496272641710944, SwapBuffersCompleted=496272635915267, DisplayPresentTime=8589934596, CommandSubmissionCompleted=496272634736985,
[monodroid-assembly] open_from_bundles: failed to load assembly System.Xml.XmlSerializer.dll

Hi,

If possible, can I get you to provide a more complete log with FMOD debugging enabled? You can enable debugging by doing the following:

  1. Use and include fmodstudioL.dll instead of fmodstudio.dll, and fmodL.dll instead of fmod.dll, in your project - you’ll also need to change the dll value in fmod_studio.cs to fmodstudioL, and the dll value in fmod.cs to fmodL
  2. Call FMOD.Memory.GetStats() before Studio system creation in order to enforce library order
  3. Call Debug.Initialize() before creating the FMOD Studio system - the appropriate call in this case should be FMOD.Debug.Initialize(FMOD.DEBUG_FLAGS.LOG);
  4. Create your Studio system

This should log FMOD info alongside the rest of the logging data you’ve provided when running your program, and hopefully provide a clearer picture of the issue.

Thanks Louis!

I set things as you requested everything worked up til I load the master bank and immediately received a failed call when loading the master banks. I then reset the code back to the non-debug libs (Just to make sure I hadn’t modified something) and still have the same behavior, everything reports OK but no audio

This is all of the log from when I initialized the Studio to the failure loading the Bank
ViewRootImpl@fc0f60e[MainActivity]] ViewPostIme pointer 0
[ViewRootImpl@fc0f60e[MainActivity]] ViewPostIme pointer 1
[fmod] FMOD_OS_Init : Detected CPU family: 4, features: 0x7F, cores: 8.
[fmod] FMOD_JNI_GetEnv : JNI_OnLoad has not run, should have occurred during System.LoadLibrary.
[libc] Access denied finding property “sys.perf.boostopt”
[libc] Access denied finding property “sys.perf.boostopt”
Resolved pending breakpoint at ‘StudioSystem.cs:47,1’ to void FmodForFoxes.Studio.StudioSystem.CheckResultCode (FMOD.RESULT rc) [0x00009].

Call Stack from Code

Oh and just in case here’s the init code I’m using…

Unfortunately, since you’re using FMODForFoxes, I can’t be of much help here besides in very general terms, as we don’t officially support third-party APIs. You may have better luck asking in the FMODForFoxes Discord. That said, if you undo the steps I suggested, it’s likely that FMODForFoxes handles enabling logging somehow, and you may be able to obtain more information that way.

Thanks for the response.

Please note I have all source code for FMODForFoxes. Its ONLT a simple abstraction over your C# wrapper so it can be used in a more “natual” C# syntax.

I was only using it as an example over your API.

If you look at my Logs you’ll see FMOD started to output new info

[fmod] FMOD_OS_Init : Detected CPU family: 4, features: 0x7F, cores: 8.
[fmod] FMOD_JNI_GetEnv : JNI_OnLoad has not run, should have occurred during

Then I received the below exception from FMOD’s API Not the abstraction (I wrote the specific code)

FMOD.RESULT.ERR_INVALID_HANDLE

Native → is an instance of the FMOD Libraires its FMODs code

CheckResultCode → Is just my code the validate the FMOD API RCs

It occurred when I attempted to load the Master.Bank.

The only thing I can see potentially causing ERR_INVALID_HANDLE in this case would be if FileLoader isn’t loading the bank data into memory correct for some reason. From a quick look at the source for it, it seems fine, so I would verify that your banks are in the expected location and are accessible by your program, and that FileLoader is generating and opening the correct filepath.

Thanks once again for hanging with me on this challenge!

Observations

  • I pointed the code to a non-existent Bank and received an exception “File Not Found”.

  • Tried loading a different bank first, ‘Vehicles.bank’ → Received INVALID_HANDLE again

  • When I run this code without the logging enabled -> No exception but nothing runs (Shouldn’t I be getting the same error when I’m not using the Logging if there’s an issue with the Bank file?)

I’d share the Bank files but this tool doesn’t allow that (just to further clarity, the Bank files I’m using are compiled for Mobile)

No problem.

At this point, I suspect it may be easier to diagnose the issue if I’m able to take a look a look at your project myself - if possible, could I get you to upload the project to the “Uploads” tab of your FMOD Profile?

Thanks again and sorry for my delayed response.

Please note that this is just protype code as I work to see if this is possible using MAUI (Don’t judge :-))

MAUI-FMOD-Experiments-master.zip

I’m running into errors due to missing native FMOD libs - are you able to able to run the exact project you sent me, as is, without any issues? Or have you removed any libs or other files before uploading? If so, please reupload the project with those files included.

Hi Louis,

Sorry about the delay in my response.

I just downloaded the zip file from this link into a clear location and successfully built and started the app.

Couple questions:

  1. Are you using Visual Studio 2022?

  2. Are you running on Windows? - If you’re running of Windows, did you right click on the zip file and “unblock” it from the OS? I’ve seen strange things happen on Windows if you don’t do that before extracting and building code.

  3. If you’re getting errors about FoxesLib being missing, try just compiling that project first.

No problem about the delay.

  1. Yes, I’m running Visual Studio 2022.
  2. I’m running on Window, and unblocking the .zip file appears to make no difference
  3. I’m not getting errors about FoxesLib being missing

I’m able to compile and run the app on Visual Studio’s Android Emulator (Pixel 5, Android 12.1, API 32), but clicking on any of the buttons immediately triggers “System.DllNotFoundException: ‘fmodL’”, despite the fact that I can see that the appropriate libs appear to be located in MAUIHack/Platforms/Android/Lib.

Hi Louis,

I discovered your issue: I wasn’t including the x86 libs for the emulator (I was testing on native devices). Fixed that and now you can run the code successfully in the emulator.

I also discovered another “debug” switch in the abstraction code. That fixed the failure occurring when trying to run the Studio based code against the debug libraires. So you should see the logging you were expecting. But I’m still not receiving errors and the audio never plays using Banks.

Updated code found here:

Thanks once more you’re a machine!
-Todd

1 Like

Thanks for uploading your project again, I’ve been able to get it working with no fuss this time.

The issue is that the Studio System isn’t being updated at all. Certain actions can take place without the Studio system updating, like loading data or playing audio (which is why the Core API is playing a sound without issue), but most API calls are enqueued into a command buffer, and then executed asynchronously on a separate thread when you call Studio::System::Update. In this case, pretty much all the calls to _eventInstance are enqueued but never executed, which is why the event never actually plays.

The appropriate call to add here for FMODForFoxes appears to be FMODManager.Update();. By adding it once, just after _engineInstance.Start();, all the prior API calls (event instance creation, parameter setting, starting) are executed, and I’m able to hear the event’s audio as the Studio system has actually started audio playback. Typically updating is set to be tied to a game/application’s main update loop - as such, I would recommend creating some kind of update loop to call FMODManager.Update() in so that FMOD processes your API calls appropriately. FMODForFoxes also recommends doing so in the “Playing some tunes!” section of their readme.

Thanks Louis,

I officially feel stupid (How I missed that given I’ve read that instruction in detail serval times). Your technical explanation also helps give how I’m planning to use this outside a gaming scenario.

I have it working, now to do the real work.

Thanks again for sticking with my question and driving it to solution! If I could leave you a tip I would!

Thanks
-Todd

1 Like