Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by ExpiredIndexCard · Aug 06, 2013 at 06:00 AM · audiosoundmusicrhythm

Calculating rhythm of any music?

I am making a music based game and I want the level being generated by the rhythm of any sound track the player puts in the game. How do I find/calculate the rhythm of any song? Any ideas? Thanks

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image dorpeleg · Aug 06, 2013 at 06:39 AM 0
Share

Take a look at this: AudioClip.

I've never really worked with the audio clip variables, so I don't know if it will help you.

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by CHPedersen · Aug 06, 2013 at 07:31 AM

This has the potential to be somewhat complex. :-/ There is no out-of-the-box feature in Unity that calculates the rhythm of arbitrary music, probably because doing so is a non-trivial signal processing task uncommon in the field of computer graphics. It can be done, of course, but if you were hoping for that one magical method call, you're in for some tough luck, I'm afraid; it's going to be involved, and it's going to require a lot of hairy math and hard work.

The defining characteristic of rhythm is repetition over time. Some feature of the music that creates a distinguishable pattern which is periodic and has a clear frequency. The most obvious place to look would be the bass drum. You mention you want the player to select a song from his library. Have you considered what happens if the player selects a song that doesn't have a bass drum? What if he passes your algorithm a classical piece that has no distinguishable beat? Or worse yet, a file that contains white noise?

Even if the music has a periodic beat, it is not enough to just examine a sample in the frequency domain (which is what DaveA's reply suggests. GetSpectrumData takes the Fast Fourier Transform of a time domain sample to convert it to its frequency domain representation). Articles I've seen which reliably evaluate the beat of music instead use the Continuous Wavelet Transform. See links:

http://www.ams.org/notices/200903/rtx090300356p.pdf

http://marcs.uws.edu.au/links/ICoMusic/Full_Paper_PDF/Smith_Honing.pdf

So yeah. Like I said, hairy math.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by DaveA · Aug 06, 2013 at 06:54 AM

Use GetSpectrumData. You'll probably want to just use that visualizer code in the scripting reference so you can find the array index or indices that will indicate the beat.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ExpiredIndexCard · Aug 06, 2013 at 07:05 AM 1
Share

I don't need a visualizer. I want the player to select a song from his library and the game will generate a level based on the songs beat. How can I get the rhythm of it?

avatar image ExpiredIndexCard · Aug 06, 2013 at 07:29 AM 1
Share

I have been doing some research on GetSpectrumData and I have a few questions. How do I use this information? What kind of information does it give me? I need to know this. I have to generate platforms based on the tempo of the music. The players speed is also affected by the tempo.

avatar image CHPedersen · Aug 06, 2013 at 07:32 AM 0
Share

See my reply below. :P

avatar image
0

Answer by Vetpetmon · Nov 29, 2014 at 12:00 PM

You would have to listen to the song a few times. Peaceful beats (few or none)means that it can not be used for combat zones. chaotic music (many or fast)is for battle zones and dangerous areas. Also, find the most used drum in the music and judge if it goes good for you. Note: I'm not a musician, I don't make music but I do listen to music.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Audio controls disabled??! 0 Answers

How To Turn Off Sound For Certain Objects? 1 Answer

Audio Scripting 1 Answer

audio different in game than preview? 1 Answer

Problem with seamless music looping in Unity 5 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges