I got a Raspberry Pi 3 model B and I want it to detect and identify musical notes.

I was thinking that maybe with only a USB mic I can accomplish this however, I'm not sure.

The USB Mic I found: https://www.adafruit.com/product/3367

Can someone tell me what is required to accomplish this?


Presumably you looked at https://learn.adafruit.com/usb-audio-cards-with-a-raspberry-pi/recording-audio from Adafruit. Once you get your data with the microphone, what you want is an "audio spectrum analyzer" . You will need to do Fourier Transforms to convert the time series data from the microphone into frequency data. You can look for the standard musical note frequencies in the Fourier Transforms. There is a computationally fast way of doing Fourier Transforms aptly named FFT, i.e. Fast Fourier Transform. See https://www.raspberrypi.org/blog/accelerating-fourier-transforms-using-the-gpu/ for info on how to do that on a Raspberry PI.

There is a LOT to understand about FFTs and spectrum analysis. For example, the frequency resolution of the FFT depends on the number of samples that are processed. You also need to understand windowing. See https://www.edn.com/electronics-news/4383713/Windowing-Functions-Improve-FFT-Results-Part-I .

For this specific example, if there are multiple notes playing at the same time and the same note is played in different octaves, you will have to distinguish between overtones from lower frequency notes and the fundamental frequency of higher notes. For actual music versus isolated instruments, this is non-trivial.

  • Can all of this be accomplished in real-time as well? – Drago Feb 13 '18 at 13:21
  • The point of using the GPU for the FFT is to do it as fast as possible. Whether that is fast enough depends on the amount of work that you need to do to recognize the notes. For audio it is probably doable in real time with a PI3, but you won't know until you try. – crj11 Feb 13 '18 at 13:29
  • I have one more question what exactly would I need to buy other than the PI to accomplish this all. I prefer not to use a headphone. – Drago Feb 13 '18 at 13:36
  • You just need something to generate digital audio samples that you can process, for example the Adafruit microphone that you mentioned. Note that to have the best chance of running real time, you should use a compiled language like C or C++ vs an interpreted language like Python. – crj11 Feb 13 '18 at 13:41
  • Correct me if I'm wrong. In the example they give they save the recorded fragment into a .wav audio file. Isn't there a way to have a constant stream/buffer instead, and whenever it detects sound, it turns that sound into frequency data. – Drago Feb 13 '18 at 14:19

apt-get install gtkguitune will install a package with a simple program for instrument tuning. It will analyse the sound captured by the microphone and tell you which note is being played (and the corresponding frequency):

enter image description here

Another package you may want to try out is fmit which stands for "Free Music Instrument Tuner".

enter image description here

Not the answer you're looking for? Browse other questions tagged or ask your own question.