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 /
  • Help Room /
avatar image
0
Question by cresquin · Nov 13, 2015 at 11:42 PM · audioaudiosourcegetspectrumdata

GetSpectrumData error

This feels like I'm missing something basic, but I'm a bit stuck.

I'm just trying to do a vanilla AudioSource.GetSpectrumData() call but I'm getting an error in the console that looks deep:

 /Users/builduser/buildslave/unity/build/Runtime/Audio/AudioSource.cpp(1621) : Error executing m_dryGroup->getSpectrum (samples, numSamples, channelOffset, windowType) (An invalid parameter was passed to this function. )
 UnityEngine.AudioSource:GetSpectrumData(Single[], Int32, FFTWindow)
 AudioMediator:Update() (at Assets/Scripts/AudioMediator.cs:24)

my code looks like this:

 public AudioSource MainAudioSource;
 
 void Update () {
         float[] b = new float[32];
         MainAudioSource.GetSpectrumData (b, 0, FFTWindow.BlackmanHarris);
 }

Here is a sample project

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

4 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by julianwitte · Sep 14, 2016 at 10:19 PM

I found this post looking for an answer, but at the end I found an answer myself. Apparently 32 is not enough for the GetSpectrumData function, the minimum length for the float array is 64.

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

Answer by Red_Nut · Dec 01, 2015 at 12:15 AM

Replacing AudioSource with AudioListener seems to stop that error. I'm currently getting a bunch of 0's though so not sure.

Comment
Add comment · Show 2 · 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 Red_Nut · Dec 01, 2015 at 12:46 AM 0
Share

I modified the supplied example code and got the following to produce some squiggly lines. http://docs.unity3d.com/ScriptReference/AudioSource.GetSpectrumData.html

 #pragma strict
 var Audio: AudioSource;
 function Start() {
 
 }
 function Update() {
     var spectrum: float[] = new float[1024];
     AudioListener.GetSpectrumData(spectrum, 0, FFTWindow.BlackmanHarris);
     var i: int = 1;
     while ( i < 1023 ) {
         Debug.DrawLine(new Vector3(i - 1, spectrum[i] + 10, 0), new Vector3(i, spectrum[i + 1] + 10, 0), Color.red);
         Debug.DrawLine(new Vector3(i - 1, $$anonymous$$athf.Log(spectrum[i - 1]) + 10, 2), new Vector3(i, $$anonymous$$athf.Log(spectrum[i]) + 10, 2), Color.cyan);
         Debug.DrawLine(new Vector3($$anonymous$$athf.Log(i - 1), spectrum[i - 1] - 10, 1), new Vector3($$anonymous$$athf.Log(i), spectrum[i] - 10, 1), Color.green);
         Debug.DrawLine(new Vector3($$anonymous$$athf.Log(i - 1), $$anonymous$$athf.Log(spectrum[i - 1]), 3), new Vector3($$anonymous$$athf.Log(i), $$anonymous$$athf.Log(spectrum[i]), 3), Color.yellow);
         i++;
     }
 }


Four things that may be obvious:

  • The DrawLine function draws in the scene window not the game window.

  • I had to zoom out to see the lines

  • I had to increase the number of samples to 1024 in order to get any values. 32 was too small.

  • You'll need to keep your audiosource to make the sound and will need an audiolistener for the AudioListener.GetSpectrumData to work.

avatar image cresquin · Dec 01, 2015 at 12:55 AM 0
Share

This is strange as the above project works out of the box in 5.1.4. Was there an undocumented breaking change in 5.2?

avatar image
0

Answer by cresquin · Dec 01, 2015 at 12:31 AM

I downgraded to 5.1.3 and it works as expected. I think this bug was introduced in 5.2

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 AustinSpafford · Mar 23, 2016 at 10:50 PM 0
Share

Status update: I'm seeing the same errors in 5.3.4f1.

It would be nice if this bug could either be fixed, or the error message updated to contain workaround options, or the feature be marked as deprecated (if it's failing triage).

In the meantime, it's time to use GetOutputData and research how to implement an FFT...

avatar image
0

Answer by Sami_AlEsh · Sep 14, 2019 at 12:38 PM

how to catch this exception in code ?? i cant catch it !!!

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

38 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

Related Questions

All my spectrums from GetSpectrumData are the same 0 Answers

GetSpectrumData from an audio source when Volume is 0? 0 Answers

I want the audio to play when the player nears the object, but fade away when they walk away. 0 Answers

Audio playing at hightspeed and simoultanesly various times! 1 Answer

Stop AudioSource on Trigger!!! 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