Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by pablo_leban · Jul 04, 2015 at 11:37 PM · audiosync

What's wrong with this? (audio.timeSamples)

Basically the problem I have is that Unity doesn't sync well this.

  • The audio clip starts inmediately (i.e. there's no blank sound at the beginning)

  • It's an .ogg file

  • Frequency 44100

So I want to make that on each beat the background music plays, the background color gets brighter by changing the alpha color of the material.

So I have this code:

     void FixedUpdate(){
         //Im always decreasing the alpha so if there's no beat, color starts to disappear
         bgMaterial.material.SetColor("_Color", new Color(bgMaterial.material.color.r,bgMaterial.material.color.g,bgMaterial.material.color.b,bgMaterial.material.color.a-0.01f));

         // With this equation, I can calculate the beats
         // 128 = BPM
         // 60 = seconds in a minute
         // 4 = to make it 1/4 beat
         // loopClip.frequency is 44100
         //(The problem is not in the if condition)
         if (mainAS.timeSamples >= (((128d/60d)/4d) * loopClip.frequency)*nextBeat){
             bgMaterial.material.SetColor("_Color", new Color(bgMaterial.material.color.r,bgMaterial.material.color.g,bgMaterial.material.color.b,0.75f));
             nextBeat++;
         }
     }

The logic is pretty simple. I get a number with that equation. When that number is the same or higher than the mainAS.timeSamples, it means that there's a beat right there. So then, set to 0.75 de alpha color. Remember that alpha is decreasing everytime, so this will make the effect that I want to reach. The thing is that this works but it's not synchronized well, and I don't know why. It's like it starts ok, but then it starts to unsync, then is synched again, and so that. I hope someone helps me!

Cheers!

Comment
Add comment
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

1 Reply

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

Answer by ttesla · Jul 05, 2015 at 03:00 AM

Have you seen this, first paragraph of answer seems what you are looking for: http://answers.unity3d.com/questions/157940/getoutputdata-and-getspectrumdata-they-represent-t.html

Or you may group spectrum data into bands. Then from bands you can check if they go higher than your threshold limit. This way you will have a better beat detection. You can separate beats like bass, snare, vocal beats..ect.

This helped me a lot for making bands from spectrum data: https://github.com/keijiro/unity-audio-spectrum/blob/master/AudioSpectrum.cs

Comment
Add comment · Show 1 · 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 pablo_leban · Jul 05, 2015 at 08:09 PM 0
Share

I definetly have to try that! Thank you for your answer!

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

22 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 avatar image avatar image avatar image

Related Questions

AVPro QuickTime Plugin A-V Not in Sync Problem 2 Answers

Syncing audio clips to speech or audio waveform. 0 Answers

Samplesync Audioplayer 2 Answers

Tracker modules: can they send out messages? 1 Answer

Why does audio get out of sync with multiple loops playing? 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