• 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 sharpshot124 · Jun 22, 2012 at 09:57 AM · soundpitchfrequencyaudio clip

Read the pitch frequency of a audio clip

i need to be able to read the pitch of a song at runtime in unity, and to avoid confusion i dont mean audioClip.pitch or audioClip.frequency, because frequency is the same through out and pitch just changes the pitch of the clip not tell me the actual frequency, any help would be greatly appreciated

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by maturasek · Jun 26, 2012 at 01:11 PM

Pitch detection is not a trivial problem, since every polyphonic audio data has a whole spectrum of frequencies. The actual "pitch" is just the most significant frequency in it for the human mind.

This spectrum can be extracted with the FFT algoritms, which is a widely discussed and reasearched topic. Unity also has FFT solution, which I found fast enough for some real time work. You can simply use AudioSource.GetSpectrumData, but, as FadeToBlack mentioned, the spectral data will only give you the source material for actual pich detection algorithms (findign the fundamental frequency, etc) If you need some more info on the topic, please refer to the article on this page

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 FadeToBlack · Jun 26, 2012 at 11:25 AM

to get actual pitch of sound playing at current time, you need to get sound data currently playing (using something like AudioSource.GetOutputData), then you need to learn what is Fast Fourier Transform, find & download some ready solutions around this. using FFT you can detect pitch of your sound (or even detect a note), but it also need to do some hard work. i think simply you need to find some ready solutions for sound analyzing for realtime. if you will not found ready solutions, then you can do some experiments with FFT. it gives you spectrum of your sound, you need to found maximum amplitude, it tells you approximated frequency.

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 FadeToBlack · Jun 26, 2012 at 01:38 PM 0
Share

AudioSource.GetSpectrumData - wow ) even so.. a long time ago i have try to make guitar tuner, but also stuck on frequency detection, but i was needed in best precision. detect which note playing or approx frequency is quite simple.

avatar image maturasek · Jun 26, 2012 at 01:47 PM 0
Share

Yeah, you are right, in a guitar tuner, pitch detection is quite simple and precision is a bigger importance. When I wrote my answer I had my music information retrieval project (kind of a genre detection problem) in my mind, and in my case it was quite hard to extract pitch data from a complex music piece. Well, I guess I have to relax a bit :)

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

getting pitch 1 Answer

AudioSource pitch measurement unit 1 Answer

GetSpectrumData works only for 3 sec of microphone input 0 Answers

Generating an Exact Muscial Note 1 Answer

How to i make a gear system from this script? help please 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges