00:00
00:00
Newgrounds Background Image Theme

Ryor just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Unity Audio Programming

1,075 Views | 1 Reply
New Topic Respond to this Topic

Unity Audio Programming 2017-03-05 17:45:22


Hey guys, I've never done much technical audio programming in Unity, but I want to try something a bit more difficult.

I want to make a script that can dynamically determine the beat of a song being played, then spawn a game object every time the beat hits. I'm not sure if this is best done with a plugin like wWise or if Unity's onboard audio tools can help me solve this. I'm assuming I'd have to give the script access to the actual song files, then do some fancy audio channel math to so it could assess the beat on the fly and then start generating game objects whenever audio channel X hits above a certain threshold?

Maybe I'm wrong in how I want to code this, but I can't find much online with google searches, any help would be great.


BBS Signature

Response to Unity Audio Programming 2017-11-04 08:48:36 (edited 2017-11-04 08:55:45)


At 3/5/17 05:45 PM, Ganon-Dorf wrote: Hey guys, I've never done much technical audio programming in Unity, but I want to try something a bit more difficult.

I want to make a script that can dynamically determine the beat of a song being played, then spawn a game object every time the beat hits. I'm not sure if this is best done with a plugin like wWise or if Unity's onboard audio tools can help me solve this. I'm assuming I'd have to give the script access to the actual song files, then do some fancy audio channel math to so it could assess the beat on the fly and then start generating game objects whenever audio channel X hits above a certain threshold?

Maybe I'm wrong in how I want to code this, but I can't find much online with google searches, any help would be great.

I've never done it but even dedicated audio software can sometimes do a shitty job with detecting beats so rather than trying to code it myself I'd use external programs to create a list of beat time stamps and then import this data to Unity. This would perform much better than generating the data on the fly and probably be a LOT less work than if you were to do a really good job of beat detection. You could also edit the data this way too, maybe you want different objects to spawn at different sections of the song for example.

If you absolutely must have the data generated inside Unity I'd take a look at some audio visualiser scripts/projects (which there are dozens of) and modify the code to call your spawn object function rather than visualise.

If you wanted to do a really good job it would require a LOT more than just spawning when the audio reaches a certain threshold, you'd want a small countdown timer to prevent objects being spawned a few frames in a row if the volume hasn't dropped, you'd want it to detect changes in song volume during different sections and adjust the threshold accordingly, you'd want it to only detect volume in a particular frequency range etc.