Arduino Synthesizer With FM
Arduino Synthesizer With FM
by rgco
It is quite possible to create decent sound with an Arduino as has been demonstrated in plenty of other projects,
for example:
The-Arduino-Synthesizer
The-Arduino-OctoSynth
Arduino-Chiptunes
Arduino-Step-Sequencer
Here is another demonstration of how a common Arduino Uno (or clone) can be used to generate a wide range of
musical sounds.
Of course it's nowhere close to the commercially digital synthesizers, but it's a big step from a simple 'beep' piano.
Instruments are defined by a set of 10 parameters, and it's easy to create new sounds by changing the
parameters. After playing around a bit I found came up with 12 instruments that sound good and named them as
follows:
Please tell me in the feedback if you find new good sounds, then I can add them to the code.
The project described has the 19-button keyboard built with microbuttons on breadboard, but it lends itself perfectly
to be built into existing objects, like furniture, toys or vintage equipment.
https://www.youtube.com/watch?v=MX-l05_u3gA
Required materials
Wire up all the components according to the indicated schematic. It's quite some work to get all the wiring in place,
so it makes sense to start with connecting only the audio circuit and one button, and upload the software. If that
works you can progressively add all the other buttons. For the electrolytic capacitor, make sure to connect the
positive terminal to the Arduino side and the negative terminal to the potentiometer. The short connections within
the breadboard are best done with short pieces of solid-core hookup wire, the longer connections to the Arduino
better with flexible jumper wires.
Note that the buttons may be connected to any pin, with software it is possible to assign any key to any note. The
only exception is pin D9, on which the audio signal is produced, it must not be used as a key input.
Load up the Arduino sketch from the next step and you can start playing.
The keys play the notes C4-F5, and the rightmost button changes the instrument. The time that a button is pushed
changes the length of a note, but since these are simple digital pushbuttons, the loudness of the tone cannot be
influenced by speed or force with which the keys are pushed.
Connect a stereo headphones to the 3.5 mm jack and with the potentiometer the volume can be regulated.
To hear the sound over a speaker, it needs to be amplified. Any amplifier that is designed to take headphone input
will work. Alternatively a cheap amplifier module base on the LM386 or PAM8403 should be sufficient to bring up
the volume.
Step 2: Code
Upload the attached with the Arduino IDE. I used of ADSR envelopes and FM sound synthesis .
version 1.8.7, but nothing fancy has been used so I
expect it to work well with most past and future IDE's. ldness: loudness
Moreover, no external libraries are used.
Keeping this at 64 or below guarantees that the
After the 'Verify' step, I see: output does not go in overflow and produce horrible
distortions. But for sounds that remain only very
Sketch uses 11630 bytes (36%) of program storage shortly at maximum amplitude, it's OK to go higher,
space. Maximum is 32256 bytes. Global variables since it's unlikely to have all 4 voices at maximum
use 757 bytes (36%) of dynamic memory, leaving amplitude.
1291 bytes for local variables. Maximum is 2048
bytes. pitch0: pitch offset
So it is far from exhausting the 2kB RAM, 32kB flash Setting this to 12 results in 'normal' configuration
of the Arduino Uno. where the leftmost key has the pitch of the C4.
Setting it to 0 results in a shift of a full octave down,
Instrument definitions
while the value 24 results in a full octave up.
Each instrument is defined by 10 parameters. To
discover new sounds, it's crucial to understand their
ADSR_a: attack parameter
meaning, and make sure you understand the basics
Sounds amazing! The low bell wow! Of course the problem with interesting songs is that you have
to deal with both the composition and notation (and storage). Maybe look into existing standards
for this, such as RTTL https://en.wikipedia.org/wiki/Ring_Tone_Transfer_Language or of course
midi files.
Good idea! I had looked into midi but it seemed way too complicated. RTTTL seems doable, and
there seem to be thousands of them readily available! Thanks!
Exactly! Cant remember if it was monophonic only tho..
OK, you got me enthusiastic about RTTTL, I coded it up, did a few more tweaks and wrote it up as
a separate instructable:
https://www.instructables.com/id/Arduino-Chrismas-...
I'd like to pose one more request of you, and that's to add a simple square wave and triangle wave
instruments. This thing was destined for chiptune.
I made a new version with 8 pots and 24 keys, it is much better indeed. Thanks for the suggestion!
https://www.instructables.com/id/Arduino-Soundlab/
That's amazing! Thanks for your work and I'm glad my feedback helped, if even a little.
Hey awesome work on this! I'm currently building it myself, but I was hoping to do a couple
modifications to it. I'm just not sure where to start.
I'd love to add an SPI OLED 128x64 screen that displays the current sound font, and maybe other
information.
Is there any way to increase the amount of keys you can press at once?
Also, would live modification of each font be possible with a few potentiometers?
I'm still fairly new to Arduino so I'm not sure where to start coding wise for these few things.
Glad you like it!
Adding a screen requires pins so reduces the number of available keys. Also updating the screen
might not be fast enough to do simultaneously with making sound, but that's not necessarily a
problem.
Increasing the level of polyphony from 4 to 8 is not trivial: It would take a reduction in sampling rate
to 16kHz or a reduction in sound complexity (giving up on FM synthesis). Both will reduce the
sound quality. May need to go to a faster microcontroller for that... In any case it would be a
complete rewrite of the code since the 4-fold polyphony is hardcoded everywhere to save CPU
cycles.
Live modification should be possible with pots on the analog inputs. Every pot will use a pin so one
key less (but the Arduino Nano has 2 extra analog pins A6 and A7). Regular 'analogRead' will be
too slow, but accessing registers directly (similar as done in
https://www.instructables.com/id/Another-Arduino-Oscilloscope/ ) it's possible to start an analog
readout, keep 'working', and read the result when it's ready (instead regular analogRead waits
doing nothing after the start of the ADC).
Good luck and let me know your progress!
Thanks for your reply! I actually have an expansion board if I run out of pins. I'd love to add those
potentiometers.
Would you happen to know how to code for say, 3 pots for sustain, attack, and decay?
This.is a.nice idea. 4 pots for adsr and 4 for the fm parameters would really allow to experiment
with sound synthesis. The black keys would have to go though. I might give it a try but it will take a
while. Just ordering the pots takes 2 months...
How about instead of losing keys, we use a pin expansion board/shift register? They're quite cheap
around where I am. I hear the 74HC595 IC is sufficient.
I have a bunch of those, they cost cents indeed, but they are output registers, they cannot be
directly used for input. But there may be tricks to use them for input (like scanning the 'power' to
sets of input devices) interesting...
I appreciate your work and your replies. I'm new at this sort of thing, but I figured it wouldn't hurt to
spitball a bit and see what can be done. I wasn't aware they were only output registers and not
extra pins. Is there another cheap micro controller we could use that has more input pins? Teensy