Digital Music Synthesizer

 ECE 476 Digital Systems Design using Microcontrollers - Spring 2002 Final Project

Jeff Ting jbt11@cornell.edu | Jinu Rhee jr65@cornell.edu

  

Click on above pictures to view larger version

Introduction | High-Level Design | Program/Hardware Design | Results | Future Considerations | Appendix

 

bullet

Introduction:

Our ECE 476 Spring 2002 final project is a musical synthesizer that mimics the sounds produced by a piano and a clarinet.  We wanted to create a device that could produce different musical signals by direct digital synthesis.  Using Fourier analysis of the signals, we were able to imitate the sounds from different musical instruments.  In addition, we wanted to give our keyboard users the ability to play multiple note chords to create more interesting music patterns. Working on this project gave us a lot of insight into the nature of sound and how high-end keyboard synthesizers actually operate.

Click on Picture Above for a Java Piano Synthesizer!

The best part about our project was that once we had finished debugging and assembled our final project, we were able to play simple melodies using our Digital Music Synthesizer. Some of these songs included simple tunes like 'Jingle Bells' as well as more complex tunes like 'Chop Sticks' which requires more than one note to be played at one time (chords).

 

Back to Top

 

bullet

High-Level Design:

Sine Wave Generation

The range of the synthesizer covers from middle C (lowest note, C4) to an octave above middle C (highest note, C5) and includes all 11 notes in between including all the sharps and flats.  This encompasses an entire octave on a musical scale.  The sampling frequency of our synthesizer is 20 kHz which is many times the Nyquist frequency of our highest note (C5 523 Hz) so we avoid the possibility of aliasing.  We stored the sine table values for each note into flash memory.  Each value in the sine table is 6 bits in resolution.  C4, at 262 Hz, has a period of 3.81 ms, so at a sampling rate of 20 kHz, we need 77 samples to represent a single C4 wave.  A4, at 440 Hz, has a period of 2.27 ms, so we need 46 samples to create a single A4 wave.  Since the period of each note is different and we are using a 20 kHz sample rate, each note has a sine table of a different size.  Below is a picture of the piano keys (one full octave) that we implemented and a listing of their corresponding frequencies.

bullet

C4      =     262 Hz (middle C)

bullet

C4#    =     277 Hz

bullet

D4      =     294 Hz

bullet

D4#    =     311 Hz

bullet

E4      =     330 Hz

bullet

F4      =     349 Hz

bullet

F4#    =     370 Hz

bullet

G4     =     392 Hz

bullet

G4#   =     415 Hz

bullet

A4     =     440 Hz

bullet

A4#   =     466 Hz

bullet

B4     =     494 Hz

bullet

C5     =     523 Hz

Interrupt Service Routines (ISRs)

The range of the synthesizer covers from middle C (lowest note, C4) to an octave above middle C (highest note, C5) and includes all 11 notes in between including all the sharps and flats.  This encompasses an entire octave on a musical scale.  The sampling frequency of our synthesizer is 20 kHz which is many times the Nyquist frequency of our highest note (C5 523 Hz) so we avoid the possibility of aliasing.  We stored the sine table values for each note into flash memory.  Each value in the sine table is 6 bits in resolution.  C4, at 262 Hz, has a period of 3.81 ms, so at a sampling rate of 20 kHz, we need 77 samples to represent a single C4 wave.  A4, at 440 Hz, has a period of 2.27 ms, so we need 46 samples to create a single A4 wave.  Since the period of each note is different and we are using a 20 kHz sample rate, each note has a sine table of a different size.

Our synthesizer was designed with the ability to play chords of 2 or 3 notes.  Since a chord is just the superposition of multiple waves, this required the addition of different sine waves in order to play more than one note simultaneously.  Since we used separate sine tables for each note with the same interrupt frequency, we simply added the values from 2 or 3 sine tables together inside the Timer 1 Clear On Compare Match Interrupt to create the chord.  The reason for using a resolution of only 6 bits for each note is because the sum of a 3 note chord cannot exceed 8 bits since we are using PORTC as the output port.

The duration of each note is dictated by the period of time in which the corresponding keypad button is depressed.  So holding down a certain keypad button produces an extended note.  We used Timer1 to create the music signal and Timer0 to detect button pushes from the keypads.

Fourier Coefficients

The sound of a piano is very similar to that of a simple sine wave so we did not use any Fourier coefficients to alter it.  But in order to imitate the distinct sound of a clarinet, we did use the Fourier coefficients (which we found on the internet) to calculate the sinusoidal waveform and the sine table values.  We represented the signal with about 10 upper harmonics.  We used Matlab to calculate the different sine table values.  The values were normalized and truncated to 6 bits to permit the addition of multiple waveforms when generating chords.

 

Back to Top

 

bullet

Program / Hardware Design:

Software

Our source code for this project consists of a mixture of C and Assembly.  We used Assembly code in the Timer 1 Interrupt to generate the different wave forms and manipulate the chords.  We used Matlab code to generate our different sine tables from the Fourier coefficients for the different instruments used by our synthesizer.

bullet

C Source Code

bullet

Matlab Code

Hardware

We used the Atmel 90s8515 microcontroller chip on a STK500 board.  We used 13 pushbuttons to emulate the piano keys so that each of the buttons represent a different note on the musical scale.  The keypads connect to 2 ports on the STK500 board (PORTA and PORTB).  We used the UART to interface with a hyperterminal on the PC in order for the user to select which instrument to use.  The output signal is produced on PORTC and connected to an 8-bit Digital to Analog converter (DAC0808).  The output of the D to A is fed through an op amp (LF353) and then sent to a speaker to produce the music signal. 

bullet

Diagram of Push Button Setup

bullet

Diagram of DAC

bullet

Diagram of Final Setup

Back to Top

 

Results:

Given the time allotted for our final project, we were able to successfully meet the goals that we had set out in our initial project proposal. Specifically, we achieved our primary goal to allow users to play chords of multiple notes (up to three buttons pressed simultaneously). Additionally, we were able to implement different instrument sounds by calculating their unique waveforms from their Fourier coefficients and thus instruments like the piano and clarinet could be emulated by the user through the use of the hyperterminal on the computer.

When the speaker output was measured using the oscilloscope, the measured frequencies closely matched the actual note frequencies as expected. As a result, a very clear, distinctive note was generated for each note in the scale from (C2 - C3). Even the three note chords generated a clear waveform that revealed the additive nature of its composition. The resulting chords were thus very clear and very pleasing to the ear.

Included below are some sample captures of the waveforms generated by our Digital Music Synthesizer.

bullet

Piano Note Waveforms

bullet

Clarinet Note Waveforms

Back to Top

 

bullet

Future Considerations:

bullet

Utilize more processors/ports to expand and include more octaves

bullet

Support more complex chords (4+ notes at once)

bullet

Buy pushbuttons that more closely resemble true piano keys

bullet

Implement more instrumental options to choose from

bullet

Add dynamics such as fading out of notes

bullet

Allow for the intensity of note to reflect pressure of key press

bullet

Use more Fourier coefficients to synthesize additional harmonics

bullet

Include a simple demo song that plays when user selects from menu

bullet

Record and playback features implemented through the Hyperterminal

 

Back to Top

 

bullet

Appendix:

bullet

Programs
bullet

C Source Code

bullet

Matlab Code

 

bullet

Hardware Diagrams
bullet

Diagram of Push Button Setup

bullet

Diagram of DAC

bullet

Diagram of Final Setup

 

bullet

Output Waveforms
bullet

Piano Note Waveforms

bullet

Clarinet Note Waveforms

 

bullet

Parts List
bullet

1 Atmel 90s8515 chip

bullet

1 STK 500 board

bullet

2 four-key push buttons

bullet

2 three-key push buttons

bullet

1 DAC0808

bullet

1 LF353 Op-Amp

bullet

14 10k pull-up resistors

bullet

2 5.1k resistors

bullet

1 0.1 uF capacitor

bullet

1 Amplified speaker

bullet

1 Power supply

Back to Top