Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 arminms · Sep 09, 2015 at 06:55 PM · getspectrumdata

GetSpectrumData frequently returns null

Hi every one

In unity5, I call GetSpectrumData in Update function. I see it returns null ( an array of zeros) sometimes.

To find the problem, I played a 1000Hz sound to fixed the input and make a log file of GetSpectrumData's returns values.

In this way, it should return an array with same values each time.

But surprisingly in my PC, after every 125 calls, there is "exactly" one null (an array of zeros) returned! And in my Tablet (Samsung android), in every 125 calls, there are "exactly" 14 nulls (array of zeros) returned!

is there anyone know why?

Comment
Add comment · Show 2
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 arminms · Sep 10, 2015 at 02:18 PM 0
Share

@inventor2010 , @CgRobot, @aldonaletto, @Gruffy, @dskillsaw , @LoTek$$anonymous$$, @zach.r.d, @martin101, @Oana, @drudiverse, @roccapl, @benhumphreys, @DannyLZS, @sneftel

Hi guys, would you like to see this question? It is very wired, the GetSpectrumData returns 0 periodically (about every 3.12 seconds / exactly every 125 frames), it continues to return 0 depends on devise (in my PC it returns zero 1 or 2 times every 3.12 seconds, in my tablet it returns 14~15 zeros every 3.12 seconds!)

Thank you..

avatar image Bunny83 · Sep 12, 2015 at 11:24 AM 0
Share

It's still not clear at all where you actually get the data from. In the comment below you seem to use the $$anonymous$$icrophone API which you did not mention at all in your question. The script you've referenced in that comment doesn't use Spectrum data.

So i would suggest that you edit your actual question and include more details about what you actually want to do, what's your setup and your actual code.

When $$anonymous$$icrophone input is started you have to specify the length of the recording. Also keep in $$anonymous$$d that an FFT analysis needs "enough" data to actually calculate the spectrum. I can't currently test myself since i'm currently not on my PC.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Gruffy · Sep 10, 2015 at 08:40 PM

Honestly - it sounds directly related to the hardware your running it on. Could you post the code possibly... The best option is to try and optimise it perhaps. But, without seeing it, I can't tell. Cheers bud Gruffy

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 arminms · Sep 12, 2015 at 03:13 AM 0
Share

Thank you very much Gruffy for your answer

here are more details:

Well I use this code to make my project: http://wiki.unity3d.com/index.php/$$anonymous$$ic_Input . I have change it a bit. I add these variables and function:

 private int amountfreq = 120;
 private float[] freq = new float[1024];
 private float allfreqvalue;
 
 int Get$$anonymous$$axFreq() 
 {
     for (int s=0; s<amountfreq; s++)
         freq[s]=0; 
         
     allfreqvalue = 0;
     int x = 0;
     mic.GetSpectrumData (freq, 0, FFTWindow.BlackmanHarris);
     for (int s=0; s<amountfreq; s++)
         allfreqvalue = allfreqvalue + freq [s];
     return x;
 }

As you see this function returns the do$$anonymous$$ant frequency (which is an integer number between 0 and 1024). It also calculates a summation of all spectrum values (as allfreqvalue). It means from the spectrum we have the "index of maximum value" and "its integral". I call it in Update function and write these 2 values in a log file:

 int maxfreq;
 maxfreq = Get$$anonymous$$axFreq ();
 allfreqvalue = allfreqvalue * 300.0f;// to make it bigger only            
 System.IO.File.AppendAllText (Application.persistentDataPath + "/somewhere.txt", maxfreq.ToString () + "," + maxfreqvalue.ToString () + ";"); 

  

Log file shows; every 125 frame the GetSpectrumData returns some 0s. (the maxfreq becomes 0 and the allfreqvalue becomes very low for a while), in my PC and my Tablet the frequent on this happening is exactly same; "once in 125 frame"!

The only different is, in my PC this situation (returning 0) take 2 or 3 frame and then it "recovers" to its normal functionality , but in my tablet it takes about 14 frame of returning 0 followed by about 20 frame of low value of maxfreq - longer recovery but with same period!

I played a fixed frequency sound and put it through microphone line to my devices, to fix the input... but the result has not changed!

Also I call the Get$$anonymous$$axFreq() using InvokeRepeating seperate from Update function, to avoid animation delay (of course my project has only 3 game objects and it is quite empty!), but again, there is no difference, every 3.12s it returns 0 for a while, no matter what is the repeatRate and no matter what is the device!

See below graphs:

alt text the top graph is maxfreq values in my pc when I played a fixed frequency sound with repeatRate of 0.08, the bottom graph is allfreqvale in my pc from same log file as above

alt text and here, the top one is maxfreq from my tablet, as you see it takes more sample to back to normal, and the other one is allfreqvalu form same logfile as above, (I have played a fixed frequency whistle), as you see it takes more time to "recover"!

Because the "frequency" of returning 0 is same in both PC and Tablet (both 3.12s), it should not has any things to do with hardware. Of course the "recovery time" is obviously related to hardware! So it is complicated ….

avatar image
0

Answer by arminms · Sep 12, 2015 at 05:55 PM

Thank you very much Gruffy for your answer

here are more details:

Well I use this code to make my project: http://wiki.unity3d.com/index.php/Mic_Input . I have change it a bit. I add these variables and function:

 private int amountfreq = 120;
 private float[] freq = new float[1024];
 private float allfreqvalue;
 
 int GetMaxFreq() 
 {
     for (int s=0; s<amountfreq; s++)
         freq[s]=0; 
         
     allfreqvalue = 0;
     int x = 0;
     mic.GetSpectrumData (freq, 0, FFTWindow.BlackmanHarris);
     for (int s=0; s<amountfreq; s++)
         allfreqvalue = allfreqvalue + freq [s];
     return x;
 }

As you see this function returns the dominant frequency (which is an integer number between 0 and 1024). It also calculates a summation of all spectrum values (as allfreqvalue). It means from the spectrum we have the "index of maximum value" and "its integral". I call it in Update function and write these 2 values in a log file:

 int maxfreq;
 maxfreq = GetMaxFreq ();
 allfreqvalue = allfreqvalue * 300.0f;// to make it bigger only            
 System.IO.File.AppendAllText (Application.persistentDataPath + "/somewhere.txt", maxfreq.ToString () + "," + maxfreqvalue.ToString () + ";"); 

  

Log file shows; every 125 frame the GetSpectrumData returns some 0s. (the maxfreq becomes 0 and the allfreqvalue becomes very low for a while), in my PC and my Tablet the frequent on this happening is exactly same; "once in 125 frame"!

The only different is, in my PC this situation (returning 0) take 2 or 3 frame and then it "recovers" to its normal functionality , but in my tablet it takes about 14 frame of returning 0 followed by about 20 frame of low value of maxfreq - longer recovery but with same period!

I played a fixed frequency sound and put it through microphone line to my devices, to fix the input... but the result has not changed!

Also I call the GetMaxFreq() using InvokeRepeating seperate from Update function, to avoid animation delay (of course my project has only 3 game objects and it is quite empty!), but again, there is no difference, every 3.12s it returns 0 for a while, no matter what is the repeatRate and no matter what is the device!

See below graphs:

alt text the top graph is maxfreq values in my pc when I played a fixed frequency sound with repeatRate of 0.08, the bottom graph is allfreqvale in my pc from same log file as above

alt text and here, the top one is maxfreq from my tablet, as you see it takes more sample to back to normal, and the other one is allfreqvalu form same logfile as above, (I have played a fixed frequency whistle), as you see it takes more time to "recover"!

Because the "frequency" of returning 0 is same in both PC and Tablet (both 3.12s), it should not has any things to do with hardware. Of course the "recovery time" is obviously related to hardware! So it is complicated ….

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

What is the window length of FFTWindow? 2 Answers

getspectrumdata returns low values 0 Answers

Question Related to GetSpectrumData and GetOutputData 0 Answers

How can I synch music game objects when I am using spectrum data 0 Answers

Spectrum of a mathematical function? 2 Answers


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