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 AlexanderOsipov · Mar 29, 2018 at 09:50 PM · audiosoundmicrophonepitch

GetSpectrumData works only for 3 sec of microphone input

Hello. I'm trying to get pitch data from microphone input, like shown in this topic- https://answers.unity.com/questions/157940/getoutputdata-and-getspectrumdata-they-represent-t.html

Briefly:

   void Start()
 `{
   `audio.clip = Microphone.Start(selectedDevice, true, 1, maxFreq);
     audio.Play();
   }
 
  void Update()
  {
     audio.GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);
     float maxV = 0;
     int maxN = 0;
     for (i = 0; i < qSamples; i++)
     { // find max 
          if (spectrum[i] > maxV && spectrum[i] > threshold)
          {
              maxV = spectrum[i];
              maxN = i; // maxN is the index of max
          }
     }
     float freqN = maxN; // pass the index to a float variable
     if (maxN > 0 && maxN < qSamples - 1)
     { // interpolate index using neighbours
          var dL = spectrum[maxN - 1] / spectrum[maxN];
          var dR = spectrum[maxN + 1] / spectrum[maxN];
          freqN += 0.5f * (dR * dR - dL * dL);
     }
     float pitchValue = freqN * (maxFreq / 2f) / qSamples; // convert index to frequency
   }

It works somehow for about 3 seconds of nonstop sound input (singing or whatever). But then pitchValue becomes zero. I took a look at spectrum array - all values are about zero in that case, so they don't pass threshold filter.

If I stop "singing" in mic, and then start again, pitchValue is again above zero. But again for about 3 seconds, then tuns to zero again. How can I fix that behavior? I use Unity 5.6.0.f3, if that matters.

Thanks everyone!

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

0 Replies

· Add your reply
  • Sort: 

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

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

Related Questions

Generating an Echo effect in Unity 3 Answers

Voice Recording issue ?? 0 Answers

Audio microphone analysis 1 Answer

How do I get the fundamental frequency pitch for audio input? 0 Answers

Custom simulation of Doppler effect 0 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