3

I'm trying to create a program which gets the various "notes" in a sound file (WAV or MP3) and can get the frequency and amplitude of each. I've been searching around for this, and of course there is the problem of distinguishing individual "notes" in a music file which isn't a MIDI, but it seems that something along these lines can be done with NAudio or DirectSound. Any ideas?

Thanks!

bramco
  • 467
  • 1
  • 5
  • 6
  • 1
    You really have two problems here: reading the file (simple) and extracting notes (difficult). You might have an easier time using Matlab or Mathematica's audio analysis features. – Chris Laplante Sep 09 '12 at 16:53

1 Answers1

3

What you are asking to do is extremely difficult.

Step one would be to convert your audio from a time domain to a frequency domain. That is, you take a number of samples, and do a Fourier transform (implemented in your software as FFT).

Next, you begin deciding what you call a note or not. This is as not as simple as picking out the loudest of the frequencies! Different instruments have different timbre, which is created by various harmonics. If you had a song of nothing but sine waves, this would be much simpler. However, you'll find that you'll start seeing notes where your ear tells you they don't exist.

Now, psychoacoustics come into play. It is entirely possible for humans to "hear" notes that do not even have a fundamental. This is particularly true in a musical context. If I were to take a trombone and start playing a scale downward, at some point, the fundamental disappears or is mostly gone. However, you will still perceive that scale as going downward, when in fact the fundamental sound has all-but disappeared. Things get really tricky at this point.

To answer your question, start with an FFT. Maybe this is sufficient for your needs. If not, begin reading the significant amount of technical literature on the subject.

Brad
  • 159,648
  • 54
  • 349
  • 530
  • What would be the best way to implement an FFT? I've seen a lot of reference to it, and I (somewhat) know what it is, but I wouldn't know where to begin. Basically, what I want to do is create a sort of musical visualization program that reacts to the amplitude and frequency of various events in a song (notes). – bramco Sep 09 '12 at 18:52
  • Obviously this would be really advanced technique, but I wanted to see if a simplified version could be accomplished. – bramco Sep 09 '12 at 19:01
  • http://stackoverflow.com/questions/170394/fast-fourier-transform-in-c-sharp http://stackoverflow.com/questions/1676294/c-sharp-library-to-do-fft-and-ifft http://www.exocortex.org/dsp/ http://www.codeproject.com/Articles/9388/How-to-implement-the-FFT-algorithm http://gerrybeauregard.wordpress.com/2011/04/01/an-fft-in-c/ http://www.lomont.org/Software/Misc/FFT/LomontFFT.html – Brad Sep 09 '12 at 19:07
  • This takes you from start to finish with code to do pitch tracking using the FFT. But it's monophonic (ie it won't detect separate notes played at the same time). Polyphonic pitch tracking is still considered a research problem. http://blog.bjornroche.com/2012/07/frequency-detection-using-fft-aka-pitch.html – Bjorn Roche Sep 10 '12 at 02:06
  • For monophonic pitch tracking, FFT is NOT the best way to go, though. http://aubio.org/ has several better implementations. – Bjorn Roche Sep 10 '12 at 02:07
  • .Net C# has built in functions for FFT and Digital filters. I'm learning. – Sadat Rafi Apr 07 '20 at 14:46