c programming / arduino / laser cutting / electric circuit
This project is a synthesizer that can generate chords by different scale degree and single notes. By pressing key ‘1’, ’2’, ’3’, ’4’, ’5’, ’6’, and ‘7’ you can change the tonality of the chord. By pressing key ‘!’, ’@’, ’#’, and ’$’ you can change the number of note in the chord into Triad, Tetrad, Pentad and Hexad. Pressing ‘z’ to move down octave and press ‘x’ to move up octave.
The idea of this project is to generate chord that you can play other instrument with. So, the chord would not stop until you press the next one.
Basically the sound was generated by C language. The Arduino installation works as a USB keyboard to control different keypress as input.
Flow Chart of C program
In file synth.c:
The main() function sets up PortAudio; sets up ncurses; Initialize key table and struct parameters.
In ncurses loop, choose different key(int ch) for different function.
int move is the variable to move octave. int bias is variable to change the tonality of chord(for example, press 2 to change the tonality to D major key, bias = 2. All note index move up 2 half steps).
In file synth.h:
I added struct Tone chord and int chord_note to write in chord index.
In file support.c:
add_chord() function is similar with add_key() function, both write the note index from struct Buf to struct tone. add_chord() function also read in variety harmony to change the number that be write in the tone struct(which is the number of notes in harmony).
In file c_major.h:
This file is the index of every scale chord.
Comilation and Linking
The makefile shows how to compile and link my program for the OS X platform. However, this command line will also compile the project:
gcc -Wall -o synth key.c synth.c support.c -I/usr/local/include \
-L/usr/local/lib -lsndfile -lportaudio -lncurses
The generic command line to run the program is:
A specific command line is
I planed to use arduino uno board, write the code in c and run the arduino code in terminal, but the command(avr-gcc) that the arduino use did not include Portaudio library and ncurses library. Then I found a way to use arduino board as a USB keyboard, but arduino uno board did not have the keyboard library. So, I change the board to arduino Leonardo. Then, I faced the second problem, each arduino contains 13 digital inputs and 5 analog inputs, but I have 22 button inputs. The first solution I have is to use IC 74HC595 in my circuit to extend the digital port number, then I realized that the extensions could only be used as output but input signals. So, I decided to put resistances between each button and use them as analog input(I think this also generate another problem that the voltage of each button is not really stable).
I use arduino leonardo board as a key board input. When I press different button, it will input different key as a computer keyboard. The c program still run in terminal and the ncurses loop. I use laser cut to make the box.