MIDI Decoding
Fortunately, the protocol for MIDI (Musical Instrument Digital Interface) signals is UART with a specific Baud rate of 31250 bps. So, after altering the Baud rate in the header files, we just needed to use the UART receive message helper functions. Now, the data from the controller is 3 bytes long, and we care about bytes 1 and 2. byte 1 holds the control signal. The most relevant ones are “note on” and “note off”. The other ones can be ignored for basic implementation. Other variations of this project could potentially use other control signals such as “Aftertouch” or “Pitch Bend”. The second byte contains the note number ranging from 0-127. This is fed into a helper function in a later stage and converted into a phase increment for DDS. So, a successful MIDI transfer of relevant data will give us all we need to know going forward: either “note on” or “note off” and the note number. Any other signal should be ignored, and the UART message buffer should be cleared once the data is saved. Note: the third byte of the message controls the velocity (volume) of the note, but for our implementation, we assumed maximum velocity for every note. We stored the velocity in a variable to potentially use later, but it was not needed.

Pitch Selection
Getting the note number from the MIDI message is enough to calculate the step through the sine table. The math comes out to: ((0xffffffff/ (SAMPLE_FREQ))*(pow((double)1.059463094, (double)(i-57)) * 440). In simpler terms, the phase is inversely related to the frequency of the pitch, and that frequency is found by 2^(1/12) raised to the note number offset by note A 440.

Interactive Menu
The first thing to notice on powering up the synthesizer is the menu displayed on the Adafruit TFT screen. This menu shows the user all of the accessible features in the synthesizer and allows the user to tune any of the parameters that are described further below. There are three main categories for tunable parameters in this device. The first is the master volume, which is displayed on a single line at the top of the screen. The volume can be changed at any time using the leftmost knob on the synthesizer. The second category contains parameters that control a low-frequency oscillator (LFO) in the synthesizer, which can then be used to modulate either volume or pitch. These parameters are adjusted by using the rightmost knob on the synthesizer. The third category contains all other effects that can be tuned real-time by the user. Within each of the effect pages, there are a number of parameters that can be adjusted using the middle knob on the device. The four buttons on the device let the user move through the menu and cycle through the various options. The up and down buttons move a red pointer between the lines on the menu, and the left and right buttons cycle between the various options in that line.

Button and Knob Noise Reduction
In order to make the user interaction as smooth as possible, the signals from each button and knob were passed through buffering functions to minimize any noise from those components. Because button presses send flickering signals before settling at a final value, each knob was debounced using a four-state finite state machine. A single button press would then correspond to only one action. Each of the knobs was buffered through a variable that compared current readings to the previous readings. This buffering is essential because while the user cycles through the menu options, it is important to maintain the previous values for each of the parameters the user does not intend to change. Updating parameters only when the position of the knob changes significantly prevents each parameter from latching to the same value.

Waveform Selection
The effect that is displayed on startup is the control over the main signal waveform. The effect and effect parameter lines on the menu display the values WVFRM and TYPE to signify that this effect has been selected. By turning the effects knob, the user can select between four different waveforms that are displayed on the bottom line of the menu: sine (SIN), triangle (TRI), square (SQU), and noise (RAND) waveforms. These waveforms can be selected in real-time, and the signal will adjust to the user’s selection.

Amplitude Envelope
This effect page can be selected by cycling through the effect names and stopping on the ENV option. This page contains two parameters: attack (ATK) and release (REL). These respectively control the speed at which the signal approaches its maximum amplitude and then returns back to zero amplitude. The values for each of these parameters can vary between 0 and 255, where 0 is in an instant change in amplitude and 255 is an infinitely long attack or release.

Duty Cycle Control
This effect page can be selected by cycling through the effect names and stopping on the DTYCYCL option. Duty cycle control can be turned on by selecting the ENABLE parameter and turning the effect knob to change the value from OFF to ON. The DEPTH parameter can then be adjusted to change the duty cycle of the signal. The duty cycle can be set to any percentage between 0 and 100, where 50 is an unmodulated signal. This effect adjusts the rate at which the synthesizer traverses through each half of the selected wave table. Values below 50 signify that the first half of the waveform is sped up, while the second half is slowed down. The reverse happens for values above 50.

LFO Modulation
This effect page can be selected by cycling through the effect names and stopping on the LFOMOD option. This effect utilizes the LFO mentioned previously to continuously modulate a specific parameter in the signal. Within the TYPE parameter, the LFO can either be routed to the amplitude (AMP) or frequency (PITCH) of the signal, or it can simply be ignored (NONE). The DEPTH parameter controls the degree to which the LFO affects the selected destination and can be varied between 0 and 255, with 0 as no modulation and 255 as maximum modulation. In amplitude modulation, the signal would oscillate between zero amplitude and the maximum amplitude set by DEPTH and the master volume. Frequency modulation would oscillate the pitch of the signal around the base frequency set by the MIDI input signals. In the separate LFO menu, the user can control the waveform (WVFRM) or the rate (RATE) of the LFO signal at any time using the LFO knob, regardless of whether this effect page has been selected on the menu. The user could choose between sine (SIN), triangle (TRI), and square (SQU) waveforms and could choose frequencies ranging from roughly .5 Hz to 65 Hz.