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
0
Question by GameTime45 · Aug 24, 2014 at 09:48 PM · musicgetspectrumdata

Using GetSpectrumData

I've been using the GetSpectrumData method to try and "listen" for a couple beats that trigger at a specific time. So far I'm able to get the Unity project to react to notes but when I try and separate it and have only certain notes get picked up by GetSpectrumData I run into issues.

 void Update () {
             musicTrack.GetSpectrumData(this.samples,0,FFTWindow.BlackmanHarris);  
 
             for(int i=0; i<samples.Length;i++)  
             {  
                 Debug.Log(samples[i]);
                 if(samples[i] == spectrumData1)  
                 {  
                     Debug.Log("spectrum match");
                     foreach (GameObject thing in things) {
                         thing.SendMessage("DoThat");
                     }   
                     break;
                 }  
                 if(samples[i] == spectrumData2)  
                 {  
                     Debug.Log("spectrum match");
                     foreach (GameObject thing in things) {
                         thing.SendMessage("DoThat");
                     }   
                     break;
                 }  
                 if(samples[i] == spectrumData3)  
                 {  
                     Debug.Log("spectrum match");
                     foreach (GameObject thing in things) {
                         thing.SendMessage("DoThat");
                     }   
                     break;
                 }  
             }  

Even though the music track is just a couple beats I see wildly varying results when I print out the array of spectrum data. I was hoping that since it is just three notes that are three different frequencies that I could examine the spectrum data to see what the three "spectrums" I should have the program wait for but the numbers never show any kind of pattern.

Any help would be greatly appreciated!

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 Nerevar · Aug 24, 2014 at 11:08 PM 0
Share

The FFT used to extract the spectrum can have some variations. The result depends on the kind of window you use for the FFT, the resolution and the SampleRate of your signal.

If you want to compare the spectrums you have to implement your own function in which you decide the aspect expected and the error you can tolerate.

If you just want to be able to recognize a note, you just have to find the highest point of your Discrete-time Fourier transform (DFT).

I found this algorithm to anaylse a specific tone of your signal, discussed in this thread.

I am not really an expert on signal analysis though, you can have a quick lesson here.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by drudiverse · Dec 01, 2014 at 07:39 AM

I believe that an FFT analysis should return an array of amplitudes of signals at different frequencies, 16 bands, 256 bands etc, i am not sure exactly, personally i prefer 1024 bands to have a clear image of the peaks.

the frequencies come out like 8hz (note 0) 16,32,64,etc etc.i think you would be seeing amplitudes at said freqs i dunno for sure, havent used unities fft.

i can't say that i love FFT, i think it's fast but it's not as precise as an array of bandpass filters. 128 thin bandpass filters is super precise and also consumes alot of cpu.

fft can be of any level of precision so i am told, even can hear a pin drop, for sonar level equipment.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

GetSpectrumData over entire file 1 Answer

Getting beats from a song using frequency range 1 Answer

Continue Playing Music on Load Level 0 Answers

Stream music from a folder? 1 Answer

Music volume decreases after one loop 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