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 Minimi · Jul 26, 2014 at 02:44 PM · getspectrumdata

Returning spectrumdata to an array of 64 floats in good framerate

I am making a parametric equalizer, and the script underneath works fine with returning 8 floats, based on the incoming audio. What I can't seem to fix, is returning a higher number of floats than 8 without unity framerate going superlow, or it just doesnt work. I need abit help to get it to work returning to 64values with good speed. Maybe there's a better solution than mine?!

using UnityEngine; using System.Collections;

     public class AudioToFloats : MonoBehaviour {
 
     private float[] samples = new float[512]; 
     public static float[] curValues = new float[8]; 
     string ss = "";




         void Start () {
         
         }
         
         // Update is called once per frame
         void FixedUpdate () {
         int count = 0;
         float diff = 0;
         AudioListener.GetSpectrumData(samples, 0, FFTWindow.BlackmanHarris); 
         ss = "";

         for (int i = 0; i < 8; ++i) 
         {    
             float average = 0;    
             int sampleCount = (int)Mathf.Pow(2, i) * 2;
             for (int j = 0; j < sampleCount; ++j)
             {
                 average += samples[count] * (count + 1);
                 ++count;
             }
             average /= count;
             diff = Mathf.Clamp(average * 10 - curValues[i], 0, 4);
             curValues[i] = average * 10;
             ss += curValues[i].ToString("0.000")+",";
         }
             }

 void OnGUI()
 {
     
     GUI.Label(new Rect(150, 0, 600, 500), ss);
     int ImageHeight = 300;
     for (int i = 0; i < 8; i++ )
     {
         float Height = ImageHeight * (1 - curValues[i]);
         
     }    
 }
         }



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
0

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

you can try different FFT settings than blackman harris, see documents.

i believe that you can do 100 bandpass filters in real time with a streaming kind of set up, i.e. analysing 4410 samples every 100ms or so. you should be able to get 100 realtime freq band readouts, and 400 on a quad core.

i ll see your FCT, only way to hasten it up is normally, multicore, jump between frames, and different fft window settings. at it's a unity function, dunno if you can jump frames and multicore :(

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 drudiverse · Dec 01, 2014 at 07:59 AM 0
Share

Aldonetto sais:

Unity generates the audio spectrum incredibly fast, so this whole script consumes less than 1 mS at Update in my machine (a 1.8GHz Intel Core Duo PC). If you want to try this script with a reference sound, download this

he has a code version here: http://answers.unity3d.com/questions/157940/getoutputdata-and-getspectrumdata-they-represent-t.html

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

How to determine the pitch from GetSpectrumData() to make a polyphonic tuner? 1 Answer

GetSpectrumData doesn't update 2 Answers

How to get GetSpectrumData of an audioClip before playing it? 2 Answers

GetSpectrumData From A Muted AudioSource? 1 Answer

For the spectrum data for the return value of GetSpectrumData 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