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 Kokujou · May 16, 2015 at 12:26 PM · c#audiomathaudioclip

convert AudioClip.GetData values into AudioSource.GetOutputData values

hello,

you know the functions to get values from the AudioSource like GetOutputData and GetSpectrumData provide information just for the part of the sound that is playing. But i need the spectrum data for at least every second or better every sample of the given audio.

i heard there's something with Fast Fourier Transformation (FFT) but i don't know how to do it.

the only other very messed why i know at this moment is to generate for every second of the given audio a seperate audio clip and play ALL OF THEM at once. than you can analyze them with GetOutputData or GetSpectrumData. Well i don't have to say that this'd be not nice.

i hope you can help... i'm helpless

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
2

Answer by Bunny83 · May 16, 2015 at 01:16 PM

Well, like you have found out already Unity only provides the SpectrumData(FFT) for the currently playing audio. If you want the spectrum data for a certain fixed interval you have to do a FFT manually. There are plenty of FFT libraries or implementations for .NET.

You might want to read about Discrete Fourier Transform to get an overview what it actually is. Calculating a Fourier transform is quite complicated as it makes use of complex numbers. The usual Fourier transform requires an extreme amount of calculations. The "fast Fourier transform" speeds that process up by storing intermediate results for later use.

To get the spectrum at a certain point you have to analyse the samples around that point. That gives you the frequencies within that block of samples. If you want to analyse the whole file you have to repeat the FFT by "sliding" your section (window) you analyse over the data of your file.

Creating a spectrum analysis for every sample wouldn't make mucb sense since you always get the spectrum of a quite large range of samples. If you just shift one sample you most likely won't see any changes. Also a single calculation for a point already takes quite some time. A 3 min track has about 8 million samples (@ 44kHz).

GetOutputData just returns the current buffer of the already mixed output of all playing audioclips. If you only play one audioclip (and it's played in 2d mode) GetOutputData will simply return a fraction of your original AudioClip data. I guess GetSpectrumData simply calculates the FFT from this section.

Comment
Add comment · Show 4 · 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 Kokujou · May 16, 2015 at 07:46 PM 0
Share

so you say getoutput data is similar to AudioClip.GetData? that'd be much more helpful! its just i printed the values of GetData and GetOutputData. i $$anonymous$$NOW in the song i used must be a lot high numbers because i visualized GetOutputData using this tutorial: http://gamedevelopment.tutsplus.com/tutorials/how-to-use-sound-to-make-3d-geometry-in-unity--cms-20456 my problem is... i did both i calculated the average of all values and i counted the values in 0.1 ranges.

i'm still not sure if i know what exactly i want to use but i'm sure GetOutputData was visualized correctly!

well... of course i can't compare the values because i don't know in what frequence the GetOutputData function returns values...

avatar image Kokujou · May 16, 2015 at 07:52 PM 0
Share

another little thing is the following... unity seems to mess around with my audio. i used a tool to get an image such like the visualization tutorial i gave you... but in this tool somehow ... shrinking the curves... i'll try to explain by using images. both graphs are from the same audio track.

$$anonymous$$P3DirectCut

Unity3D

well sorry for the size but you see there are differences but its definitly the same file!

unbenannt.jpg (28.0 kB)
unbenannt1.jpg (14.6 kB)
avatar image Bunny83 · May 17, 2015 at 10:00 AM 1
Share

GetOutputData just returns samples of the pure audio signal. This signal doesn't have one frequency but is a mixture of many. That's what audio is. The Fouier transform actually manages the impossible to actually decompose a section of samples into single frequencies which mixed together would result in the original signal.

The weve form you see in Unity isn't averaged at all. It's simply downscaled. So it's affectively doesn't show all samples in that view. It has to skip some. This file contains 1107168 samples. Since the image representation in Unity has only 381 pixels (at least in your image here) it will skip about 2900 samples. Or to put it the other way round: It only displayes every 2900 sample.

Your's look like you take some kind of average of multiple samples. You also take the absolute value and not the real +- signal.

Any oscillating signal oscillates around a certain level (usually 0). The signal is equivalent to the movement of your speakers membrane. It doesn't only moves outwards (positive signal) but also inwards (negative signal). If no power is supplied the membrane is at it's resting position in the center. See this video or look for others that explain how a speaker works ^^.

As i mentioned on your other question you should read more about signal analysis in general. I suggest you get some audio tools (like Audacity) and zoom in on your file. At the end you will see the how the actual signal looks like. It's not a single frequency but a continous signal which is made up of several frequencies.

avatar image Kokujou · May 17, 2015 at 10:37 AM 0
Share

well at least GetOutputData returns at least the same pattern like $$anonymous$$P3DirectCut as you see. And its not that i miss some samples in unity image. $$anonymous$$y point is that the "height" of the values isn't big enough. as you see the first 3 bars are at least 1.5 times higher than the rest of the signal. but in unity its all nearly the same. so are the values when i read them out. the values of the right part of the signal are even HIGHER!

okay if i want you to help me i guess i have to describe my whole problem. i want to make a game like audio surf. i got some algorithms in $$anonymous$$d how i can use the values i have to transform them into a road but... i don't know what values to use!

so i putted some $$anonymous$$P3s into audio surf. the road goes up what means that the values reduce. (of course for the audio file i showed you in the image). as far as i analyzed in audio surf: the road straight for some seconds. exactly as long as the first 3 beats are playing. then it goes up. the image in $$anonymous$$P3DirectCut seems to exactly match this values.

so here the question: what function in unity do i use to get the $$anonymous$$P3DirectCut values or at least the equivalent in unity. i'm pretty sure unity messes around with the sound somehow.

AND i need those values not only for the actual playing second i need to know ALL values of the sound before i play the sound. the only function that does this way is AudioClip.GetData so i have to use this to produce the signal visualized by $$anonymous$$P3Cut... you know my problem? >.<

i hope you can help me... i pray! this project is really important for me...

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

21 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

Related Questions

Unity Float to db 2 Answers

PlayClipAtPoint Qualify with Type Name 2 Answers

Audio/c#/unity Can i control the duration by time ? 1 Answer

Is There A way For unity to Determine If Audio Was Recorded Backwards 1 Answer

I have a shooting script. I have a problem: when firing bursts, my sound of a shot breaks. How to make the sound produced to the end. 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