playMaker

Author Topic: Sync Actions to Audio via Time Samples[SOLVED]  (Read 4341 times)

Tobeee

  • Playmaker Newbie
  • *
  • Posts: 13
Sync Actions to Audio via Time Samples[SOLVED]
« on: July 16, 2013, 08:51:44 AM »
Hi guys!

I am trying to fire actions in sync with the beat of a musicfile. I am currently working with a 48000 Hz audio track (which means 48000 time samples per second right?) and want to have an action once per second. So I'm checking the timesamples of the audio via "get property", store the value in an int, convert it to a float to do a float compare where I compare it to 48000 with a tolerance of 500. If compared successfully I send an event to the action and add 48000 in order to have the next comparison at time sample 96000, 144000 and so on.

That basically works well. But some how the fsm gets delayed so the audio is faster than the fsm and my float compare value is less than the current time sample.

Does anybody know what is going on there or has a better approach?
« Last Edit: July 31, 2013, 02:50:23 AM by jeanfabre »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sync Actions to Audio via Time Samples
« Reply #1 on: July 28, 2013, 11:53:31 AM »
Hi,

 if you know the time in millseconds of your beat, simply have a timer that you launch at the same time as you start playing. This will be more efficient than checking.

 given what you are saying, I guess the error comes from the fact that you loose the start point. By giving a 500 tolerance, it may be that the tolerance gap starts adding up and the more you check, the more the tolerances adds up. That's one possible thing to explore depending on how you check for the Hz.

bye,

 Jean

Tobeee

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Sync Actions to Audio via Time Samples
« Reply #2 on: July 30, 2013, 06:42:39 AM »
Hi Jean,

thank you for your reply. Well, I'm looking for an approach that is the most accurate in the end. I wanna spawn objects exactly at the same time of a snare drum for example, so it needs to be in sync.

I know the time in milliseconds but I'm not sure if there will be a delay sometime.
Working with timesamples would make sure that it still works after an hour of gameplay. What do you think?

I am using the tolerance because playmaker/unity doesn't seem to be able to check 48000 values each second.

For me it doesn't seem logical that the tolerance gap adds up the more I check.
Example:
I wanna send an action at
48,000 ... 96,000 ... 144,000

My variable to check is 48,000
Music starts playing, Unity starts counting
somewhere between 47,500 and 48,500 the action will be sent, at the same time I add 48,000 to my variable, so it' 96,000 now
Unity continues counting
somewhere between 95,500 and 96,500 the action will be sent, at the same time I add 48,000 to my variable, so it's 144,000

and so on ...

So in theory there is no way for an increasing gap.
Am I wrong?
« Last Edit: July 30, 2013, 06:47:37 AM by Tobeee »

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sync Actions to Audio via Time Samples
« Reply #3 on: July 30, 2013, 07:52:12 AM »
Hi,

 I would think given what you said, that you might be better off using a proper framework for this:

http://forum.unity3d.com/threads/173918-RELEASED-WingroveAudio-full-audio-toolkit

 this one has playmaker support and has event based triggers on audio, so you are likely good to go with this. Contact the author to check on feasibility first tho :)

bye

 Jean

Tobeee

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Sync Actions to Audio via Time Samples
« Reply #4 on: July 30, 2013, 09:32:22 AM »
Jon just replied. Unfortuneately Wingrove Audio doesn't support beat sync at the moment. I also changed to "Best latency" in the DSPBuffer Size. No results. Any other ideas?

jeanfabre

  • Administrator
  • Hero Member
  • *****
  • Posts: 15500
  • Official Playmaker Support
Re: Sync Actions to Audio via Time Samples
« Reply #5 on: July 30, 2013, 11:31:37 AM »
Hi,

 Is your beat constant? or can it change during the music? If audio framework don't support such feature, it might be for a reason... have you asked about your problem?

If constant, I would totally rely on a custom timer instead of analysing the audio samples.

bye,

 Jean

Tobeee

  • Playmaker Newbie
  • *
  • Posts: 13
Re: Sync Actions to Audio via Time Samples
« Reply #6 on: July 30, 2013, 12:11:10 PM »
Ok, just built the same setup with the time property instead of time samples. Works much better now. Still loosing the signal sometimes but with a little tolerance it works quite well. Thank you Jean!

I am currently checking out Visualizer Studio from the asset store. If it's a serious alternative I'll let you know.