Issues with looping time-stretched music in Unity

Hi all! First off, I’m new to FMOD so apologies if there is an easy fix for this!

I’ve started to use FMOD for a recent game project and have created a discrete parameter in respect to player lives (3, 2, 1 and 0 respectively. Just as a side note, 0 is pitched down 15 semitones and has a seek modulation to simulate a tape stop effect). I am automating the pitch of the audio file using the clip pitch and not the pitch shifter effect. This creates a nice combination of stretching/slowing down the audio as well as pitching. This is perfect and exactly what I want. I also created three separate loop points that are the exact length of the original and time stretched versions (this was worked out by adding extra audio tracks and pitching the audio directly to see what the new length would be for each one). I then setup these loops with conditions that they only trigger if the player lives are 3, 2 or 1. These loops work perfectly in FMOD but for some reason, Unity is refusing to playback the extended audio and has silence during those extended loop points. Unity will correctly use the loop points for each respective life value but refuses to ‘see’ the longer time stretched clip, resulting in a cutoff in sound.

Does anyone have any workarounds for this kind of thing? I’m not a dev so am unsure whether this can be fixed via scripting in Unity.

Thanks in advance :slight_smile:

Hi,

Thank you for sharing the information and screenshot!

I tried to follow up your setup in FMOD, but so far I haven’t been able to reproduce the extended audio silence issue in Unity, and the stretched part seems keeps playing on my side.

Could you please share a bit more details on how you are triggering the event and setting the parameter in your game? For example:

  • Are you starting the event via a StudioEventEmittercomponent, or through code?
  • How are you changing the lives parameter value?

Hiya! Thanks for the reply!

I am using a StudioEventEmitter to trigger the music on object start, see screenshot below of the current setup of the component:

Edit: One of the Devs just told me:

we start from event emitter but change it from code

so we have this field in our script
[SerializeField] private StudioEventEmitter _musicEmitter;

*then we do for example
_musicEmitter.EventInstance.setParameterByName(“livesLeft”, 2);
*
Hopefully this helps a bit!

Thank you for the extra info!

I was able to reproduce the issue on my side when changing the parameter during runtime, so I will forward this to the dev team for further investigation.

In the meantime, another possible workaround you could try is using an Autopitch Modulator.

Here’s a quick setup to test:

  1. Create a new event and add only the livesLeft parameter sheet
  2. Drag your asset onto the audio track, click the single instrument and enable Loop Instrument
  3. Right click on the pitch knob, select Add Modulation > Autopitch
  4. Set the root pitch to 3 and tweak the min pitch to match your design

Hope this helps! Let me know if this works for your project.

Thank you! I will certainly give your suggestion a try!