Problem with Audio to Animation Sync

I am attempting to synchronize audio with animation. Our favorite pirate suggested that @RaananW might be able to assist me.

The playground is heavily commented, so hopefully that explains some of my logic. I found a function that creates very accurate intervals in the browser. That is being used to move the little box. It seems to keep excellent beat with the music. The animation, not so much.

This is programming for a game that will match the players action. The hope is that the player action will be on beat, so it is important that the animation mirrors that.

Perhaps if I could get the animation.start/.stop out of the callback to fire within the interval it would work? Not sure how to make that happen to test it.

If the music starts to drive you nuts, I think it is safe to use the little box visually and mute the audio.

All assistance and suggestions appreciated.

1 Like

You could probably turn off the sound auto play. That does not look needed.

I did not really follow this, but seems like you are making this harder than it needs to be. If you do a play() every time you did a start() of the animation (& setting any matching play rates to both prior), then for a given iteration, it should work.

This would mean that you would need to control the repeat of the animation & not use the built in looping, but seems like adding that would give you both more control of the play rate & be much simpler. There is a way to know that a BABYLON.Animation has finished. I have my own animation system, so I do not know what that is.

FYI, sound is on the fritz here, so I did not actually hear anything. Disregard, if upon hearing it would make this comment impractical.


Based on your recommendation, I looked more closely into the Animation class. I moved the animation group declaration out of the ImportMesh callback so I had access to it. Then I moved the animation group stop/start into the accruateInterval function. I think this will work.

Thank you for your insights.


I am very happy it is resolved :slight_smile: