Sync animation with beat

Recently i tried to make some assets animations in sync with the bgm, basically a 2 sprite animation that changes with the beat. So i added a parameter with a square LFO that changes value in every beat, from 0 to 1, and from 1 to 0.
I’m using this code to get that value on unity:

public class SoundManager : MonoBehaviour
{
private FMOD.Studio.EventInstance bgm;
public Animator anim;

void Start(){
    anim = GetComponent<Animator>();
    bgm = FMODUnity.RuntimeManager.CreateInstance("event:/Typhoon Stage");
    bgm.start();
}

void Update(){
    bgm.getParameterByName("sprite", out float i);

    if(i == 0)
    {
        anim.SetFloat("idle", 1);
    }
    else
    {
        anim.SetFloat("idle", 0);
    }
    
}

}

Can someone explain me what im doing wrong?

What is the issue you are having?

Also, you may be better off using something like Timeline beat callbacks instead.
https://www.fmod.com/resources/documentation-unity?version=2.0&page=examples-timeline-callbacks.html