Synthesizer Controlled by USB MIDI Keyboard (with Spectrum Analyzer)

Purpose

To compose proper synthesizer notes based on input from a USB MIDI keyboard, while also displaying said frequencies in a simple spectrum analyzer on a LCD.

Description

This synthesizer is implemented by using a USB MIDI keyboard connected via a Type A Female USB Breakout. When a note is pressed or released on the keyboard, a MIDI message is sent to the mbed. The mbed then determines whether the message is a NoteOn (note press) or NoteOff (note release) message. Once the message has been decoded, the mbed will execute the proper code.

If the mbed receives a NoteOn message, it stores the value of the note and its velocity as an unsigned char. Next, these values are converted into int and then into double datatypes. The mbed calculates the proper frequency corresponding to the received note by using the piano frequencies formula. The volume is calculated using the note's velocity value. Lastly, the PWMOut pin's period is set to (1/calculated frequency) and the pin is set to the calculated volume. The connected speaker then outputs the tone.

While the tone is playing, the mbed draws the proper (x,y) values of the frequency and magnitude (volume) on the LCD. The note, frequency, and volume are also displayed underneath the graph.

If the mbed receives a NoteOff message, the PWMOut pin is set to 0.0 to stop playing the tone.

A watchdog timer is also implemented in the execution of this code in case the mbed does not catch a NoteOff message or does not callback the NoteOff function. This keeps a note from playing continuously without user input. The timer starts when the NoteOn function is called and is restarted when the NoteOff function is called. If the NoteOff function is not called three seconds after the NoteOn function is called, the mbed will reset itself.

Demo

Equipment

Connections

/media/uploads/kjones99/img_20171213_102153.jpg

/media/uploads/kjones99/midi_pinout.png

/media/uploads/kjones99/_scaled_speakerdriverschem.png

https://cdn.sparkfun.com/assets/1/3/c/e/d/52f3c319ce395f904a8b4569.png

Code

Import programMIDISynthwithSpecAnalyzer

A synthesizer that is controlled by a USB MIDI Keyboard. Also displays corresponding frequencies via a simple spectrum analyzer on a LCD. Uses a watchdog timer to reset Mbed in case it freezes.

References


Please log in to post comments.