0

I'm trying to write some code that will a. take in sound from my computer's microphone and b. output what frequency (ie. pitch) the sound is. It does not have to be very precise, but has to work. I have spent many hours perusing various fora on this subject and have found that they all ought to be very useful except and would be too if I had more knowledge on the subject. However, I am not a particularly experienced coder and most of the answers I've seen go over my head. I understand that I may have bitten off more than I can chew, considering my novice, but if anyone could give a really down-to-earth easy to understand walkthrough of how I should go about implementing this, I would be verrry appreciative. Please forgive my basic question :).

I was looking to write it in Java but have experience in python and swift as well.

GregarityNow
  • 707
  • 1
  • 11
  • 25
  • 1
    Take a look at JTransforms for a Java solution - also search SO for the `jtransforms` tag for similar questions (there are a lot). – Paul R May 22 '16 at 10:22
  • 1
    Please take a look at previous questions on SO - variants of this one are frequently asked. – marko May 22 '16 at 10:36

2 Answers2

1

There's a lot of solutions for your problem. If you're good at math, you can look at the definition of a FFT and implement the formula.

However, that job has already be done by other programmers and there are a lot of different libraries that implement the FFT function.

In python, you can use numpy. Or, if you prefer java, you can use that snippet: http://introcs.cs.princeton.edu/java/97data/FFT.java.html

To read from the microphone, you can use: https://docs.oracle.com/javase/tutorial/sound/capturing.html

(there's a sample for acquiring audio from microphone here: Java Sound API - capturing microphone)

So, you just need to use the second code, read the data as 16bits PCM big endian and forward it to the FFT function.

Community
  • 1
  • 1
Alexis Clarembeau
  • 2,776
  • 14
  • 27
  • 1
    If the author was able to write the FFT itself, it would have asked the question in another way. It's why I provided a link to a reference FFT implementation. Princeton codes are always checked and works correctly. The second link is a reference to the sound capture api from oracle. He can combine easily the two codes snippets to solve its problem. I think that the purpose of this forum isn't to give a functionnal code by solving myself the problem. Thoses are just good hints.. – Alexis Clarembeau May 22 '16 at 14:27
1

I've been using Processing for a while now and it has a couple of nice audio libraries with FFT support. By default Processing is a java library, so you might want to give it a shot (you can use it in eclipse/netbeans/etc. if the default minimal IDE isn't suitable).

You don't have to use Processing with these libraries though, they are java libraries after all.

Minim has a FFT class with forward() and logAverages()

Beads also has a FFT class and there's a book available that does into more detail on analysis.

Both libraries also offer support for sound input.

George Profenza
  • 50,687
  • 19
  • 144
  • 218