Global Sources
EE Times-Asia
Stay in touch with EE Times Asia
EE Times-Asia > Embedded

Creating a Mandolin-to-MIDI bridge

Posted: 25 Aug 2015 ?? ?Print Version ?Bookmark and Share

Keywords:MIDI? Fast Fourier Transforms? FFTs?

This means that our solution will work fantastically well with low frequencies, but it will begin to taper off badly at higher frequencies. After some careful selection (cheating with Excel solver), I arrived at a sampling rate of 32Ksps (thousand samples per second) and determined that running a 512-sample autocorrelation will provide the required accuracy. Sampling 512 points at 32Ksps takes only around 16ms, which is definitely faster than anyone can play, so this also solves the sampling time issue we had with our FFTs.

I think I know what you're thinkingthat a 512-point correlation will take way too much time to process. Ah, but we don't really need to perform the full autocorrelation. What we're interested in is specific frequencies that match my note frequency bins. This means that we need to calculate only 49 points (four octaves worth) in the autocorrelation and we can ignore the rest. This comes to 512 multiplies and 512 additions performed 49 times, which is very achievable, even when using a small embedded processor.

A couple of simulations later, I could see that this was working pretty well.

Figure 5: Input note A3 (220Hz).

Figure 6: AutoCorrelated Output for note A3 (220Hz).

Alas, there were still problems; even though I could detect the note, the system would occasionally (maybe once in 20 samples or so) pick up the 2x harmonic. A little disappointed, I did a bit more reading and found this very interesting paper that describes something called "Weighted Autocorrelation," which solves the issue of note detection in an elegant manner. The actual math went a little over my head, but the implementation just needed a subtraction instead of multiplication when calculating the autocorrelation. Another minor change involved looking for a valley instead of a peak, but this was easy enough to implement.

All together now: "One chip to rule them all..."
To get this project working, I picked up my trusty CY8CKIT-050 PSoC5LP development kit. Quite apart from anything else, the PSoC 5 chip has a USB component available straight out of the box that could be used to directly enumerate as a MIDI bridge. In case you haven't used a PSoC 5LP before, you can get one for as little as $10 by clicking here.

Fortunately, I had an old development kit, which had a Cirrus codec with a mic amplifier, so I simply wired the codec up to my kit and I was good to go.

Figure 7: PSoC 5LP implementation.

Regarding the implementation, I employed a simple I2S component, a couple of DMAs, and a USB component. The calculation of the correlation was driven by an interrupt, which ran once every 512 samples (or 16ms). I added a few additional features such as running the note detection only if a sudden change in energy is detected (i.e., a new pluck).

And there you have ita working Mandolin-to-MIDI bridge. The journey was long, but there was light at the end of the tunnel (fortunately this light was not an oncoming train). I would love to hear what you guys think about this, so please feel free to comment below.

About the author
Sree Harsha Angara is with Cypress Semiconductor.

?First Page?Previous Page 1???2???3

Article Comments - Creating a Mandolin-to-MIDI bridge
*? You can enter [0] more charecters.
*Verify code:


Visit Asia Webinars to learn about the latest in technology and get practical design tips.

Back to Top