Tuesday, February 05, 2008

Simple polyphonic synth with just arduino

Video: http://www.youtube.com/watch?v=wJZVMu78T9g

So, i thought it might be possible to generate more than one tone at a time using Arduino. The idea and the outcome is relatively simple, yet i still quite like the character of the sound.

The modulo (with symbol %) of two numbers means that the outcome equals the remainder when the left number is divided by the right number. So:

5 % 2 = 1
5 % 3 = 2

and so on.

Consider that we have a counter variable, 'c' that increments with every loop of code. By performing the modulo operation on 'c', it is possible to creates loops within the larger loop that will occur 'alongside' (concurrently with) the main loop.

So, let us set up a loop with a length of eight iterations and add a single modulo function in relation to 'c' (using the variable 'a'):

for(int c = 0; c < 8; c++) {

a = c % 3;


So, when c = 0, 1, 2, 3, 4, 5, 6, 7, a = 0, 1, 2, 0, 1, 2, 0, 1 respectively.

The synthesis relies on creating a long loop (based on the integer i). Then, four oscillators are created and controlled by setting digital output pins d2 to d5 based on smaller, concurrent modulo loops.

For the first half of the modulo loop, the pin will be set low. For the second half, it will be held high. The length of the modulo loop (and therefore the frequency of the oscillator in question) is controlled by one of four pots (one for each oscillator).


/* Very basic polyphonic synth with Arduino

by Sebastian Tomczak

5 February 2008


byte state;

byte mod[] = {

0, 0, 0, 0};

void setup() {

DDRD = DDRD | B11111100;

DDRB = DDRB | B00000000;


void loop() {

for(int i = 0; i < 32767; i++) {

for(int j = 0; j < 4; j++) {

state = 0;

mod[j] = analogRead(j) >> 2 & B11111110;

mod[j] = i % mod[j] / (mod[j] / 2);

state = state + mod[j];

state = state << 1;

PORTD = state << 2;





'Bitchen' Ric said...

Technically monophonic as it only produces one pitch at a time. With additive (FM?) waveforms.

Sebastian Tomczak said...

technically polyphonic, as it produces four square wave generators whose frequencies (ie pitch) are independently controlled of one other, that could be muted independently via software and whose volumes could be easily changed independently via external pots.

evilpaul said...

technically awesome

Sebastian Tomczak said...


Anonymous said...

wherw are the sound output pins?

Sebastian Tomczak said...

The sound output pins are digital i/o pins 2, 3, 4 and 5 with 100KΩ resistors going to a single point. This is then the signal connection of the audio output.

The ground connection of the audio output goes to Arduino ground.

rez said...

Sebastian: simply awesome. I'm beginning to develop with Arduino sound devices. Your work it's perfect to start undersanding Arduino and electronics. So, it's possible to get the connections schema or some detailed photos about your work in order to try to repeat by myself?

will be really nice you can answer to my email: rez at delacrew dot com

Thanks again, great great job! : )

Anonymous said...

can you please post a schematic? where is the sound going?

Anonymous said...

sorry im like a total noob but this looks really simple to make and i'd really like to have a go - and so i was wondering - what potentiometers are those? thanks

Sebastian Tomczak said...

because the arduino is just converting voltage to data, the pots can be of any value from 10kΩ to 1 or 2MΩ.

Hope this helps! :D

igor said...

I'm a little confused about the prder of operationsin this line:

mod[j] = i % mod[j] / (mod[j] / 2);

can you rewrite using parenthesis ?

Earthshine Design said...

Interesting. But where do the outputs go to? What are they connected to and how?

Jason said...

Hello, thanks for inspiration..this page has my own Arduino synth with code, the pot setup is simliar to yours, but uses the 328 with 6 inputs .. let me know if you try this code!

Jason said...

oops sorry i think i forgot to post the link!


SquiggyT said...

I am rather new to Arduino and physical computing, but I would like to try to reproduce this project. I'm trying to figure the wiring on this project but am having trouble following the wires in the photograph and video. Two others have asked and I might have missed the response, but is there any way to get a schematic for this?