Part of an upcoming project will include a rythm mini-game. My approach so far was to simply play a music event in FMOD, and in parallel inside of Unity trigger pre-determined rythms. It is mostly okay, but as you might expect there is a bit of latency between the two systems that are completely independent, and it gets worse with frame drops. I did see we could edit the DSP Buffer Size to diminsh latency, but the documentation seems to say it shouldn’t be used, and since this minigame is just a small part of the project, I wouldn’t want to ruin everything for this. So my question is “Is there a way to make sure a specific event is played with very little latency ?”
The main this is to ensure your event instance is created, and its sample data loaded, ahead of time before starting your rhythm game - see the Sample Data Loading section of the Studio API Guide
Note that if you’re using the default bank loading setting for the FMOD for Unity plugin, your banks and therefore will have their sample data loaded ahead of time, which will minimize this being an issue.
However, instead of the event latency, you may wish to consider driving triggering your Unity rhythms from FMOD, as this will ensure the systems are working in tandem as opposed to in parallel. You can do so with timeline callbacks, which you can set to trigger on specific timeline markers, as well as beats/bars given a specific tempo and time signature. Please take a look at the Timeline Callback scripting example in our Unity documentation for a basic example of doing this.
Thanks a lot for the help! The only issue with timeline callbacks is that they are not continuous, right, they only happen on beats ? That would be an issue because I want the notes to move constantly, with some look ahead (exactly like in guitar hero for example). But I did realise I could just use getTimelinePosition, which seems to work as intended
Are there some drawbacks to reading the timeline position every frame, or is it fine ?
Thanks a lot, that’s super helpful! I do have an additional issue that came up, which I’ll ask here since it’s still related to the thread : so I have the main song playing, and the player has to press specific keys in rythm. I’d like the key pressing to trigger an audio feedback, but that means it has to have minimum latency, otherwise it’s very jarring when compared to the main song playing. So I have this placeholder click sound (very short, very light), it doesn’t stream, the samples are loaded beforehand as you recommended, but there is still a noticeable delay which makes playing it very annoying. I tried using PlayOneShot as well as just cache an Instance that I replay, but it doesn’t seem to change anything… Is this kind of musical precision just not possible with FMOD ?
That kind of precision is possible, but due to the asynchronous nature of the Studio system, depending on your settings and how an event is set up you may observe a higher amount of latency than you expect. As previously noted, normally a combination of preload sample data, and creating your event instance ahead of time and then starting as needed should mitigate most potential latency. Exactly how much latency are you observing?
As a side note, you can see how much latency is being introduced by the Studio system by recording a profiler session via live update, observing when a specific API command is processed in the API calls view, and comparing it to when the audible effect of that command occurs.